0% found this document useful (0 votes)
2 views23 pages

CSE014 Structured Programming

The document is an assignment focused on structured programming in C#, consisting of 87 multiple-choice questions covering various operators, loops, and control structures. It tests knowledge on assignment operators, logical operations, loop constructs, and conditional statements. Each question provides four answer options, with topics ranging from basic syntax to specific programming concepts.

Uploaded by

sugin.army
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views23 pages

CSE014 Structured Programming

The document is an assignment focused on structured programming in C#, consisting of 87 multiple-choice questions covering various operators, loops, and control structures. It tests knowledge on assignment operators, logical operations, loop constructs, and conditional statements. Each question provides four answer options, with topics ranging from basic syntax to specific programming concepts.

Uploaded by

sugin.army
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

ASSIGNMENT 2

On
STRUCTURED PROGRAMMING

1. Which of the following is the assignment operator in C#?

a) =
b) ==
c) !=
d) ===

2. Which operator is used to compare two values for equality in C#?

a) =
b) ==
c) !=
d) ===

3. What does the '!=' operator do in C#?

a) Assigns a value
b) Compares equality
c) Checks inequality
d) Performs addition

4. Which operator is used for addition in C#?

a) +
b) -
c) *
d) /

5. What is the output of 10 % 3 in C#?

a) 1
b) 3
c) 0
d) 10

6. Which operator increments a value by 1 in C#?

a) ++
b) +=
c) +
d) --

7. What is the result of true && false in C#?

a) true
b) false
c) 1
d) 0
8. What is the result of true || false in C#?

a) true
b) false
c) 1
d) 0

9. What does the '!' operator do in C#?

a) Adds 1
b) Negates a boolean
c) Subtracts 1
d) Multiplies by -1

10. What is the result of 5 * 2 + 3 in C#?

a) 13
b) 16
c) 10
d) 11

11. Which operator is used to subtract one value from another?

a) +
b) -
c) *
d) /

12. Which operator divides one number by another in C#?

a) /
b) *
c) -
d) %

13. What is the result of 10 / 3 in integer division?

a) 3
b) 3.33
c) 4
d) 0

14. What is the symbol for the modulo operator in C#?

a) %
b) /
c) *
d) #

15. Which of these is the logical OR operator?


a) &&
b) ||
c) !
d) &

16. Which of these is the logical AND operator?

a) ||
b) &&
c) !
d) &

17. Which operator is used to assign a value to a variable?

a) =
b) ==
c) !=
d) +

18. What does the '+=' operator do?

a) Adds two values


b) Adds and assigns
c) Compares values
d) None of these

19. What does the '-=' operator do?

a) Subtracts and assigns


b) Compares values
c) Subtracts only
d) None of these

20. What will be the value of x after this code: int x = 5; x += 3;

a) 3
b) 5
c) 8
d) 15

21. Which of the following is a unary operator?

a) ++
b) +
c) &&
d) ==

22. Which of the following is a binary operator?

a) --
b) !
c) ++
d) *

23. What does the expression !(5 > 3) return?

a) true
b) false
c) error
d) undefined

24. What does 'x++' do?

a) Increments x before evaluation


b) Increments x after evaluation
c) Decrements x
d) None

25. What does '++x' do?

a) Increments x before evaluation


b) Increments x after evaluation
c) Decrements x
d) None

26. What is the result of 2 * (3 + 4)?

a) 9
b) 10
c) 14
d) 12

27. Which of these is the comparison operator?

a) %
b) +=
c) &&
d) ==

28. Which of these is the arithmetic operator?

a) >
b) ==
c) *
d) &&

29. Which operator is used to concatenate two strings?

a) &
b) +
c) *
d) ||

30. What is the result of 5 < 3 || 4 > 2 ?

a) false
b) true
c) error
d) undefined

31. What does 'x *= 2' mean?

a) Add 2 to x
b) Compare x with 2
c) Multiply x by 2 and assign to x
d) Divide x by 2

32. Which of the following is not a valid relational operator?

a) <
b) >
c) ===
d) !=

33. What is the result of 'true && true'?

a) true
b) false
c) 0
d) 1

34. Which operator returns true only if both operands are false?

a) !
b) &&
c) ||
d) none

35. Which operator has the highest precedence?

a) *
b) +
c) =
d) &&

36. Which operator is right-associative in C#?

a) =
b) +
c) &&
d) ||

37. What does the '^' operator do in C#?

a) XOR
b) AND
c) OR
d) Negate

38. What is the value of y after running: int x = 3; int y = ++x;

a) 4
b) 3
c) 5
d) error

39. What is the value of y after running: int x = 3; int y = x++;

a) 3
b) 4
c) 5
d) error

40. Which loop is best suited when the number of iterations is known beforehand?
a) while
b) do-while
c) for
d) foreach

41. Which loop guarantees at least one execution?


a) while
b) for
c) do-while
d) foreach

42. Which of the following is the correct syntax for a for loop in C#?
a) for i = 0 to 10
b) for (int i = 0; i < 10; i++)
c) foreach (int i = 0; i < 10; i++)
d) loop (i = 0; i < 10; i++)

43. Which loop is specifically used to iterate through arrays or collections?


a) while
b) foreach
c) do-while
d) loop
44. What is the output of: for(int i = 0; i < 3; i++) { Console.Write(i); }?
a) 0123
b) 123
c) 012
d) 0 1 2

45. Which of the following is true about the foreach loop?


a) It modifies elements directly
b) It can iterate backwards
c) It provides read-only access to elements
d) It requires index declaration

46. What happens if the condition in a while loop is always true?


a) It throws an error
b) The loop executes only once
c) The loop executes indefinitely
d) The program terminates

47. What is the output of the following?

int i = 1; while(i < 4) { Console.Write(i); i++; }


a) 1234
b) 123
c) 012
d) 234

48. Which statement can be used to exit a loop prematurely?


a) exit
b) return
c) continue
d) break

49. What is the purpose of continue in a loop?


a) Exit the loop
b) Skip current iteration
c) End the method
d) Restart loop from the beginning

50. What type must the condition in a while or for loop evaluate to?
a) int
b) char
c) bool
d) string

51. How many times will this run? for(int i=0; i<5; i++)
a) 6
b) 4
c) 5
d) Infinite

52. What will happen if i-- is used instead of i++ in a for loop

for(int i=0; i<5;i++)?

a) Infinite loop
b) Compile error
c) Loop ends immediately
d) Loop runs backwards

53. Which of the following loops is not available in C#?


a) for
b) do-while
c) foreach
d) repeat-until

54. Which of these can iterate over a collection without using indexes?
a) for
b) while
c) foreach
d) do-while

55. Which of the following loops allows the body to be skipped entirely if the condition
is false initially?
a) do-while
b) loop
c) foreach
d) while

56. How can an infinite loop be created using for?


a) for true
b) for(int i=0;i<1000;i++)
c) while(true)
d) All of the above

57. What is true about do-while loop?


a) Executes before checking condition
b) Executes only once
c) Executes condition first
d) Never ends

58. Which of the following is a correct use of a nested loop?


a) for(int i=0; i<5; i++) for(int j=0; j<3; j++) Console.Write(j);
b) for i in range(5) { for j in range(3) Console.Write(j); }
c) foreach (int i in range) { (int j in range) }
d) loop (int i=0; i<5; i++) loop (int j=0; j<3; j++)
59. What is the output of this code:

int i = 0; do { i++; } while(i < 0); Console.Write(i);


a) 0
b) 1
c) -1
d) Error

60. How do you reverse loop from 10 to 1 in C#?


a) for(int i=10; i>=1; i--)
b) for(i=1; i<=10; i++)
c) foreach(int i in 10..1)
d) loop reverse(10 to 1)

61. What keyword skips the remaining code inside the loop for current iteration?
a) skip
b) continue
c) return
d) break

62. Which loop would you use to keep asking for a password until it's correct?
a) for
b) foreach
c) while
d) for-each

63. Which of the following would create an infinite loop?


a) while(true)
b) while(5>#)
c) do { } while(true);
d) All of the above

64. What happens when break is used inside nested loops?


a) Exits all loops
b) Exits current iteration
c) Exits innermost loop
d) Restarts loop

65. Which of these loops is preferred when modifying elements by index?


a) foreach
b) while
c) do-while
d) for

66. Which of the following loops runs at least once?


a) for
b) foreach
c) do-while
d) while

67. What will this loop print? for (int i=2; i<=6; i+=2) Console.Write(i);
a) 23456
b) 246
c) 2468
d) 13579

68. Which loop should be avoided if you don't know the number of items?
a) for
b) foreach
c) while
d) do-while

69. Which loop iterates through an array without using index?


a) for
b) while
c) foreach
d) do-while

70. What will for(int i=5; i>0; i--) Console.Write(i); output?


a) 54321
b) 12345
c) 01234
d) 43210

71. What does break do in a loop?


a) Skips to next iteration
b) Terminates loop
c) Jumps to the start
d) Throws error

72. What will the loop print? int i=10; while(i>7){ Console.Write(i); i--; }
a) 987
b) 10987
c) 1098
d) 8765

73. Which loop construct is safest against infinite loops?


a) for
b) while
c) foreach
d) do-while

74. How can a loop be exited based on a condition?


a) Use continue
b) Use break
c) Use skip
d) Use exit
75. Which of the following is the correct syntax for an if statement in C#?
a) if condition then statement
b) if (condition) statement;
c) if {condition} statement;
d) if [condition] statement;

76. What is the purpose of the else keyword in C#?


a) Executes when an if statement is false
b) Defines the loop structure
c) Checks for multiple conditions
d) Terminates the program

77. Which of the following is the correct way to write an else if statement in C#?
a) else if (condition) statement;
b) elseif (condition) statement;
c) else if condition statement;
d) else (if condition) statement;

78. What will the following code output?

int x = 5; if (x > 3) Console.Write("Yes"); else Console.Write("No");

a) Yes
b) No
c) Error
d) Nothing

79. Which of the following can be used for multiple conditions in C#?
a) only if
b) if, else
c) if, else if, else
d) for, while

80. What is the purpose of switch statement in C#?


a) Used for handling multiple conditions based on a single expression
b) Executes code only when the condition is true
c) Used for looping
d) Used for recursion

81. What will happen if no break is used in a switch statement?


a) The program will exit the switch statement immediately
b) The code will fall through to the next case
c) The switch statement will be ignored
d) An error will occur

82. Which of the following operators is used for logical AND in C#?
a) &&
b) &
c) AND
d) |

83. What will the following code print?

int x = 10;
if (x < 5) Console.Write("Low");
else if (x > 5) Console.Write("High");
else Console.Write("Equal");

a) Low
b) High
c) Equal
d) Error

84. How do you check if a number is equal to 5 in C#?


a) if (num = 5)
b) if (num == 5)
c) if (num === 5)
d) if (num equals 5)

85. Which of these is the correct syntax for a switch statement in C#?
a) switch { case x: break; }
b) switch(x) { case 1: break; }
c) switch (x) case 1: break;
d) case switch (x) { 1: break; }

86. Which of the following operators is used for logical OR in C#?


a) ||
b) OR
c) |
d) and

87. What will be the output of the following code?

int x = 4;
if (x == 5) Console.Write("Yes");
else Console.Write("No");

a) Yes
b) No
c) Error
d) Nothing

88. What is the result of this expression: x > 5 && x < 10 when x = 7?
a) True
b) False
c) Error
d) Undefined

89. What will be the output of this code?


int x = 10;
if (x == 10) Console.Write("Ten");
else Console.Write("Not Ten");

a) Ten
b) Not Ten
c) Error
d) Nothing

90. Which of these is used to represent a condition that must be checked in if


statements?
a) if keyword
b) expression
c) boolean value
d) else keyword

91. In a switch statement, what happens if no case matches the value?


a) A default case is executed
b) The program exits immediately
c) The program throws an error
d) The program keeps asking for input

92. How do you write a default case in a switch statement?


a) default case:
b) default:
c) default { }
d) case default:

93. What will the following code output?

int x = 5; if (x != 5) Console.Write("Yes"); else Console.Write("No");

a) Yes
b) No
c) Error
d) Nothing

94. Which keyword is used to exit a switch case?


a) exit
b) break
c) continue
d) return

95. What is the correct syntax to use else if in C#?


a) if (x == 1) { … } else if (x == 2) { … }
b) if (x == 1) { … } else if x == 2 { … }
c) if x == 1 { … } else if x == 2 { … }
d) if (x == 1) else if (x == 2)
96. Which of the following conditions evaluates to true?

int x = 5; x >= 3 && x < 10


a) True
b) False
c) Error
d) Undefined

97. What is the value of x in the following code?

int x = 10; if (x == 10) x = 20; else x = 30;

a) 10
b) 20
c) 30
d) Error

98. What happens if you use else without an if statement?


a) Syntax error
b) Infinite loop
c) The else will be ignored
d) It will execute automatically

99. Which of the following will cause a syntax error?


a) if (x == 10) { } else { }
b) if x == 10 { } else { }
c) if (x == 10) Console.Write("Yes"); else Console.Write("No");
d) if (x == 10) { } else if (x == 5) { }

100. Which of the following is the correct syntax for a ternary operator in C#?
a) condition ? value1 : value2
b) condition : value1 ? value2
c) value1 : value2 ? condition
d) condition value1 ? : value2

101. What is the purpose of the && operator in conditional statements?


a) To check if both conditions are true
b) To check if either condition is true
c) To negate a condition
d) To compare two values

102. Which of these is the correct order of precedence in C#?


a) !, &&, ||
b) &&, !, ||
c) ||, &&, !
d) &&, ||, !

103. Which of the following is an invalid switch case?


a) case 1: break;
b) case "1": break;
c) case x: break;
d) case 1.0: break;

104. What will happen if you try to use a string expression in a switch statement?
a) Error
b) It will work fine
c) It will only work with integers
d) It will work only in else if statements

105. Which operator is used for logical NOT in C#?


a) ~
b) !
c) NOT
d) &&

106. Which of the following is a valid conditional expression?


a) x == y
b) x => y
c) x <=> y
d) x === y

107. What does else if do in C#?


a) Runs the code if the if condition is false
b) Defines the last condition
c) Specifies another condition to check after if fails
d) Repeats the same condition

108. Which of the following statements is true about the switch statement?
a) It allows multiple conditions with a single variable
b) It always checks all cases in sequence
c) It can only be used with integers
d) It cannot be used with strings

109. Which is the correct syntax for using default in a switch statement?
a) default case:
b) default:
c) case default:
d) default switch:

110. Which of the following will result in true for x == 5 and y == 10?
a) x == 5 & y == 10
b) x == 5 || y == 5
c) x == 5 && y == 10
d) x != 5 && y == 10

111. Which is the correct expression for checking if a number is either greater than 5
or less than 10?
a) x > 5
b) x > 5 && x < 10
c) x < 5 || x > 10
d) x > 5 || x < 10

112. What happens when you use multiple else if conditions?


a) Only one of the conditions executes
b) All of the conditions execute
c) No condition executes
d) It loops through conditions indefinitely

113. Which operator is used to compare values for inequality in C#?


a) <>
b) ==
c) <
d) !=

114. Which keyword is used to declare a method that does not return a value in C#?

a) method
b) void
c) function
d) def

115. What is the return type of a method that does not return a value?

a) null
b) none
c) void
d) empty

116. Which keyword is used to return a value from a method?

a) exit
b) return
c) stop
d) break

117. Which of the following is a correct method declaration?

a) void Add()
b) function Add()
c) Add(): void
d) method Add()
118. How do you call a method named Print() in the same class?

a) call Print()
b) Print()
c) Print
d) invoke Print

119. Which of the following is a valid method with parameters?

a) void Greet(name)
b) void Greet(string name)
c) Greet(name: string)
d) void Greet(name: string)

120. What is the output of a method that ends with 'return 5;'?

a) 5
b) 0
c) void
d) error

121. Can methods in C# be nested?

a) Yes
b) No
c) Only static
d) Only private

122. Which method declaration is valid?

a) int Sum(int a, int b)


b) Sum(int a, int b)
c) int Sum(a, b)
d) Sum(): int

123. What is the return type of the method: int GetNumber()?

a) void
b) object
c) int
d) float

124. What is the default value of an int array element in C#?

a) 0
b) 1
c) null
d) undefined

125. How do you declare a one-dimensional array of integers in C#?

a) int[] arr;
b) array int arr[];
c) int arr{};
d) int arr;

126. Which of the following initializes an array with 5 elements?

a) int[] arr = new int[5];


b) int arr = int[5];
c) new int[5];
d) int arr[] = 5;

127. How do you access the third element of an array named 'nums'?

a) nums(2)
b) nums[3]
c) nums[2]
d) nums->2

128. Which loop is commonly used to iterate through an array?

a) foreach
b) while
c) goto
d) do-while

129. Which statement adds 1 to every element of an int[] array 'a'?

a) foreach (int i in a) { i++; }


b) for (int i=0; i<a.Length; i++) { a[i]++; }
c) a++;
d) a += 1;

130. What does a.Length return for array a = new int[10];?

a) 9
b) 10
c) 11
d) undefined

131. What is the index of the first element in a C# array?


a) 0
b) 1
c) -1
d) undefined

132. How are elements stored in an array?

a) Contiguously in memory
b) Randomly
c) In stack
d) In dictionary

133. Which keyword creates a new array in C#?

a) new
b) create
c) make
d) array

134. What is the output of int[] a = {1,2,3}; Console.WriteLine(a[1]);

a) 1
b) 2
c) 3
d) 0

135. How do you find the length of an array?

a) array.len
b) array.Length
c) array.Count
d) Length(array)

136. What happens when you access an index out of bounds?

a) Returns null
b) Throws exception
c) Returns 0
d) Ignores

137. Which of these correctly declares and initializes an array?

a) int[] a = {1,2,3};
b) array a = [1,2,3];
c) int a = [1,2,3];
d) int a() = {1,2,3};
138. Can an array hold elements of different data types?

a) Yes
b) No
c) Sometimes
d) Only in special cases

139. Which data type can a one-dimensional array contain?

a) Only int
b) Only string
c) Any data type
d) Only bool

140. What is the maximum index in int[] a = new int[5];?

a) 5
b) 4
c) 0
d) 1

141. How do you call a method named Print() in the same class?

a) call Print()
b) Print()
c) Print
d) invoke Print

142. Which of the following is a valid method with parameters?

a) string Greet()
b) void Greet(name as string)
c) Greet(name: string)
d) void Greet(name: string)

143. Which method declaration is valid?

a) int Sum(int a, double b, string c)


b) Sum(int a, double b, string c)
c) int Sum(a, b)
d) Sum(): int, double, string

144. What is the return type of the method: float GetNumber(double N)?

a) void
b) object
c) int
d) float

145. Which of the following initializes an array with 7 elements?

a) int[] arr = new int[7];


b) int arr = int[7];
c) new int[7];
d) int arr[] = 7;

146. How do you access the fourth element of an array named 'nums'?

a) nums(2)
b) nums[3]
c) nums[2]
d) nums->2

147. Which statement adds 2 to every element of an int[] array 'a'?

a) foreach (int i in a) { i++; }


b) for (int i=0; i<a.Length; i++) { a[i]+=2; }
c) a++;
d) a += 1;

148. What does a.Length return for array a = new int[12];?

a) 9
b) 10
c) 11
d) 12

149. What is the index of the second element in a C# array?

a) 0
b) 1
c) -1
d) undefined

150. What the index of the last element in the array a that is created with the following
statement

array a = new int[10];?

a) 9
b) 10
c) 11
d) undefined

Essay Questions – Program-Based


1. Write a C# program to print all even numbers from 1 to 100 using a loop.
2. Draw a flow chart and create a C# program that prints whether a given number is
positive, negative, or zero using conditional statements.
3. Write a C# program that uses a for loop to calculate and display the sum of numbers
from 1 to 50.
4. Draw a flow chart and develop a program that asks the user to enter the width and the
length of a rectangle, then it calculates the Area and Perimeter and prints them.
5. Create a C# program to find the factorial of a given number using a loop.
6. Write a program that uses a switch statement to perform a simple calculator
operation (+, -, , /) based on user input.
7. Write a C# program to print a pattern like a right-angled triangle using nested loops
(e.g., a triangle of *, as shown next).

*
**
***
****
*****
8. Create a program that reads a number and prints whether it is divisible by both 3 and
5 using logical operators and conditional statements.
9. Draw a flow chart and write a program that calculates the average of 5 numbers
entered by the user without using loops.
10. Write a program that calculates the average of 5 numbers entered by the user with
using loops.
11. Write a C# program that accepts a student's marks and prints the grade using if-
else statements.
12. Create a program that prints all odd numbers between 1 and 100 using a while loop.
13. Write a program in C# that accepts three numbers and finds the largest using
conditional statements.
14. Write a program in C# that reads three double numbers and pass them to a method
that returns the largest number of the three numbers.
15. Write a program in C# that reads three double numbers and pass them to a method
that returns the average of the three numbers.
16. Write a program that calculates and prints the square and cube of numbers from 1 to
10 using loops and arithmetic operators.
17. Write a program in C# that reads three double numbers and pass them to a method
that returns the largest number of the three numbers.
18. Write a C# program that defines a method to check whether a number is even or odd.
Call this method from Main.
19. Write a C# program that defines a method CalculateFactorial(int n) to return the
factorial of a number using a loop.
20. Write a C# program that reads 10 integer elements from the user into an array of
integers and prints the count of even numbers in this array.

You might also like