Best 50 Programming Questions On Basic Declaration and Expressions
Q 1. Declare two integer variables `a` and `b`, assign them values, and print their sum.
Expected Output:
Sum: 30
Q 2. Declare a float variable `f`, assign a value, and print it with two decimal places.
Expected Output:
Float: 12.35
Q 3. Declare two character variables `c1` and `c2`, assign them values, and print their ASCII values.
Expected Output:
ASCII value of A: 65
ASCII value of z: 122
Q 4. Declare an integer variable `num`, assign it a value, and check if it's positive or negative.
Expected Output:
Negative
Q 5. Declare an integer variable `x`, assign it a value, and print whether it is even or odd.
Expected Output:
15 is odd
Q 6. Declare two integer variables `a` and `b`, and print the result of `a` divided by `b` as a floating-point number.
Expected Output:
Result: 3.33
Q 7. Declare a float variable `f1`, assign it a value, and cast it to an integer. Print both the float and integer values.
Expected Output:
Float: 9.99, Integer: 9
Q 8. Declare two integer variables `a` and `b`, swap their values using a temporary variable, and print the result.
Expected Output:
After swap: a = 10, b = 5
Q 9. Declare an integer variable `n`, calculate its square, and print the result.
Expected Output:
Square of 4 is 16
Q 10. Declare three integer variables `a`, `b`, and `c`. Calculate and print the average of these three numbers.
Expected Output:
Average: 20.00
Q 11. Declare a variable `x`, assign it a value, and print its cube.
Expected Output:
Cube of 3 is 27
Q 12. Declare an integer variable `n`, and use it to calculate the remainder when divided by 5.
Expected Output:
Remainder when 14 is divided by 5: 4
Q 13. Declare an integer variable `x`, and use a compound assignment operator to add 10 to it and print the result.
Expected Output:
x after adding 10: 15
Q 14. Declare a float variable `f`, divide it by 2, and print the result.
Expected Output:
Result: 4.00
Q 15. Declare a variable `n` and use the modulus operator to check if it is divisible by 3.
Expected Output:
9 is divisible by 3
Q 16. Declare an integer variable `n`, and print the value of `n` after incrementing it by 1 using the increment operator.
Expected Output:
Value after increment: 8
Q 17. Declare two integer variables `a` and `b`, and print the result of `a` multiplied by `b`.
Expected Output:
Product: 42
Q 18. Declare an integer variable `x`, and use the decrement operator to subtract 1 from it. Print the result.
Expected Output:
Value after decrement: 4
Q 19. Declare a float variable `a`, assign it a value, and print the square root of `a`.
Expected Output:
Square root of 16.00 is 4.00
Q 20. Declare an integer variable `n`, assign it a value, and print its absolute value.
Expected Output:
Absolute value of -8 is 8
Q 21. Declare a float variable `x`, and print the result of `x` raised to the power of 3.
Expected Output:
Cube of 2.00 is 8.00
Q 22. Declare two integer variables `a` and `b`, and print the result of `a` divided by `b` as an integer.
Expected Output:
Result: 4
Q 23. Declare an integer variable `x`, and print the result of `x` multiplied by itself (x^2).
Expected Output:
Square of 4 is 16
Q 24. Declare two integer variables `a` and `b`, and print whether `a` is greater than `b`.
Expected Output:
10 is not greater than 20
Q 25. Declare a variable `x` and use the ternary operator to check if `x` is positive, negative, or zero.
Expected Output:
0 is Zero
Q 26. Declare two float variables `a` and `b`, and print the result of `a` divided by `b` with 3 decimal places.
Expected Output:
Result: 3.333
Q 27. Declare an integer variable `n`, and print the result of `n` modulus 7.
Expected Output:
Remainder when 20 is divided by 7: 6
Q 28. Declare an integer variable `x`, and print the result of `x` left shifted by 2 positions.
Expected Output:
Result after left shift: 20
Q 29. Declare an integer variable `x`, and print the result of `x` right shifted by 1 position.
Expected Output:
Result after right shift: 4
Q 30. Declare an integer variable `x`, and print the bitwise NOT of `x`.
Expected Output:
Bitwise NOT of 5 is -6
Q 31. Declare an integer variable `x` and print the value of `x` multiplied by 10.
Expected Output:
Result: 70
Q 32. Declare two integer variables `a` and `b`, and print the result of `a` divided by `b` using integer division.
Expected Output:
Result: 3
Q 33. Declare a float variable `f`, assign it a value, and print its value multiplied by 0.5.
Expected Output:
Result: 4.80
Q 34. Declare an integer variable `x`, assign it a value, and print whether `x` is less than 100.
Expected Output:
45 is less than 100
Q 35. Declare two integer variables `a` and `b`, and print the larger of the two numbers.
Expected Output:
Larger number is: 25
Q 36. Declare an integer variable `x`, and print whether `x` is a multiple of 5.
Expected Output:
20 is a multiple of 5
Q 37. Declare a character variable `c` and print whether it is an uppercase letter.
Expected Output:
G is an uppercase letter
Q 38. Declare a float variable `f` and print whether it is greater than 10.0.
Expected Output:
12.50 is greater than 10.0
Q 39. Declare an integer variable `n`, and print the result of `n` modulus 10.
Expected Output:
Remainder when 37 is divided by 10: 7
Q 40. Declare an integer variable `x`, and print the value of `x` multiplied by itself twice (x^3).
Expected Output:
Cube of 3 is 27
Q 41. Declare a float variable `f`, and print whether it is equal to 5.0 using an if-else statement.
Expected Output:
5.00 is equal to 5.0
Q 42. Declare an integer variable `n`, and print the result of `n` multiplied by 3 using a compound assignment operator.
Expected Output:
Result: 12
Q 43. Declare two integer variables `a` and `b`, and print the difference between `a` and `b`.
Expected Output:
Difference: 5
Q 44. Declare a float variable `f` and print its value after adding 3.14 to it.
Expected Output:
Result: 5.64
Q 45. Declare an integer variable `n`, and print whether `n` is greater than or equal to 50 using a ternary operator.
Expected Output:
60 is Greater than or equal to 50
Q 46. Declare a character variable `c` and print whether it is a lowercase letter.
Expected Output:
h is a lowercase letter
Q 47. Declare two float variables `f1` and `f2`, and print their sum.
Expected Output:
Sum: 4.00
Q 48. Declare an integer variable `x` and print the value of `x` modulo 2.
Expected Output:
Remiander when 7 is divided by 2: 1
Q 49. Declare a float variable `f` and print its value after subtracting 1.25 from it.
Expected Output:
Result: 4.25
Q 50. Declare an integer variable `n` and print the result of `n` left shifted by 3 positions.
Expected Output:
Result after left shift: 16
Bikki Singh
Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!