IBM Previous Years Solved Sample Placement Papers
1. Reverse a String in Java
import java.io.*; import java.util.Scanner; class PrepBytes { public static void main (String[] args) { String str = "PrepBytes", nstr = ""; char ch; System.out.print("Original word: "); System.out.println("PrepBytes"); for (int i = 0; i < str.length(); i++) { ch = str.charAt(i); nstr = ch + nstr; } System.out.println("Reversed word: " + nstr); } }
2. C Program to Find the Largest Number Among Three Numbers
#includeint main() { int A, B, C; printf("Enter the numbers A, B and C: "); scanf("%d %d %d", &A, &B, &C); if (A >= B && A >= C) printf("%d is the largest number.\n", A); if (B >= A && B >= C) printf("%d is the largest number.\n", B); if (C >= A && C >= B) printf("%d is the largest number.\n", C); return 0; }
3. Compute Average of Two Numbers Without Overflow (C++)
#includeusing namespace std; int compute_average(int a, int b) { return (a + b) / 2; } int main() { int a = INT_MAX, b = INT_MAX; cout << "Actual average: " << INT_MAX << endl; cout << "Computed average: " << compute_average(a, b) << endl; return 0; }
4. Check if a Given Number is Prime or Not (C++)
#includeusing namespace std; bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i <= sqrt(n); i++) if (n % i == 0) return false; return true; } int main() { isPrime(11) ? cout << "true\n" : cout << "false\n"; return 0; }
5. C++ Program to Generate Fibonacci Triangle
#includeusing namespace std; int main() { int a = 0, b = 1, i, c, n, j; cout << "Enter the limit: "; cin >> n; for(i = 1; i <= n; i++) { a = 0; b = 1; cout << b << "\t"; for(j = 1; j < i; j++) { c = a + b; cout << c << "\t"; a = b; b = c; } cout << "\n"; } return 0; }