0% found this document useful (0 votes)
224 views15 pages

H Computer Solved Errors & Output Notes by Youth Academy

The document outlines various programming errors and outputs related to C code, providing a list of code snippets along with their respective errors or outputs. It includes examples of syntax errors, logical errors, and the correct usage of loops and conditional statements. Additionally, it emphasizes the importance of proper syntax and variable declarations in programming.

Uploaded by

jy333106
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)
224 views15 pages

H Computer Solved Errors & Output Notes by Youth Academy

The document outlines various programming errors and outputs related to C code, providing a list of code snippets along with their respective errors or outputs. It includes examples of syntax errors, logical errors, and the correct usage of loops and conditional statements. Additionally, it emphasizes the importance of proper syntax and variable declarations in programming.

Uploaded by

jy333106
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/ 15

COMPUTER

Solved Errors &


Output Notes
Champions!
LOVE YOU ALL

YOUR TEACHER
SIR USAMA KHALID KAMBOH
YOUTH ACADEMY YOUTUBE CHANNEL SIR USAMA

ERRORS AND OUTPUPTS


100% IMPORTANT
SOLVED QUESTIONS
Code Description Error/Output/Action
1. What will be the Output of the following code: Output: 1 (7 divided by 3 leaves a remainder of 1).
int m=7; int y=3; printf("%d", m%y);
2. What will be the output of the following: int Error: Variable x not declared.
number = 6; x=number--; printf("%d ",x);
3. Trace out from the following code: int k; for Error: Incorrect use of commas. Should be
(k=0, k<=10, k++); printf("%d", k) semicolons for the loop syntax.
4. Convert the following code into while loop: int i=1; while(i<=10) { printf("loop"); i++; }
void main() { int i; for(i=1; i<=10;i++)
printf("loop") }
5. Convert the following code into while loop: int i = 3; while(i <= 21) { printf("%d \n",i); i += 3; }
i=3; do { printf("%d \n",i); i+=3; } while (i<=21);
6. Convert the following do while loop into for for(int c = 2; c <= 5; c++) { printf("%d \n",c); }
loop: int c=2; do printf("%d \n",c)
while(c++<=5);
7. Convert the following while loop into do while int i = 0; do { printf("while vs do while"); } while(i ==
loop: void main() { int i=0; while(i==1) { 1); printf("out of loop");
printf("while vs do while") } printf("out of
loop") }
8. Convert the following program segment into int i=3; while(i<=3) { printf("*\n*\n*\n"); i++; }
while loop: for(int i=3; i<=3, i++) {
printf("*\n*\n*\n"); }
9. Convert the following for loop into do while int i=3; do { printf("%d \n",i); i+=6; } while(i<=39);
loop: int i; for(i=3; i<=39; i+=6) printf("%d
\n",i);
10. Determine the output of the following code: Error: Infinite loop due to semicolon after
int j=0; while(j<=10); { printf ("Pakistan\n"); while(j<=10);
j=j+2 }
11. Determine the output: int x=0; Output: Squares of odd numbers from 1 to 15 (1, 9,
for(x=1;x<=15;x++) { printf(" %d\n", x*x); x++; 25, 49, 81, 121, 169, 225, 289, 361).
}
12. Make a flowchart of while loop. N/A
13. Convert the following loop code into Do-while int n=1; do { printf("**\n"); n++; } while(n<=10);
loop: int n=1; while (n<=10) printf("**\n");
n++;

Youth Academy Official Website: www.youthacademy.pk


YOUTH ACADEMY YOUTUBE CHANNEL SIR USAMA

Code Description Error/Output/Action


14. Trace the output: int a=1; while(a<=6) { Output: a=1, a=2, a=3, a=4, a=5, a=6
printf("\n a=%d",a); a+=1; }
15. Rewrite the following code using do-while int x=10; do { printf("%d", x%2); x--; } while(x>=1);
loop: int x=10; while(x>=1) { printf("%d",x%2);
x--; }
16. Find the errors from the following code Error: Missing ; after x++ and syntax issues with the
segment: int x=1; while(x<=6); { printf("%d"x); printf call.
a++:
17. What is the output of following code: int n=1; Output: Odd numbers from 1 to 10 (1, 3, 5, 7, 9).
while(n<=10) { if(n % 2==1) printf("%d", n);
a++; }
18. Convert the following code into "for" loop: int for(int i=1; i<=10; i+=2) { printf("%d",i); }
i=1; while(i<=10) { printf("%d",i); i=i+2; }
19. Determine the output: int i=1; While(i<10) { Output: 1 2 3 4 5 6 7 8 9
printf(" %d", i); i++; }
20. Show output of the given code: int m; int m; Output: 0 2 4 6 8
for(m=0; m<10; m=m+2) printf("%d",m);
21. Determine the output of the following code Output: 1 2 3 4
segment: int n; for(n=1; n<5; n++)
printf("%d\n", n);
22. Find the error: void main() { Far(int n=1;n<=5, Error: Syntax error (Far instead of for, and improper
n++) printf("%d",n); } loop structure).
23. Write the output of the following code: int Output: 5 7 9
m=5; while(m<10) { printf("%d\n", m);
m=m+2; }
24. Define post-test loop. A post-test loop is a loop where the condition is
checked after executing the loop's body (e.g., do-
while).
25. Convert the following for loop statement into int a = 1; while(a <= 5) { printf("%d\n", a + k); a++; }
while loop: int a; int k=1; for(a=1;a<=5;a++)
printf("%d\n",a+k);
26. Convert the code given below in do while: int int m=8; do { printf("%d", m%2); m--; } while(m>=1);
m=10; for(m=8;m>=1;m--) printf("%d", m%2);
27. Determine the output of the following code n"); }`
segment: `int m=3, n=5; for(k=n; k>0; --k) {
for(f=m;j>0; --j) { printf("*"); } printf("
28. Write the output of the following code: Output: ONE
if(100>50) printf("ONE") else printf("TWO");
29. Write a C statement that assigns 1 to the if(x>0) variable=1; else y=1;
variable if the value of the variable x is greater
than 0. Otherwise it assigns 1 to the variable
y.
30. Determine the output of the following code Error: Syntax error in orintf. Should be printf.
segment: int x=10; (x%2==0? printf("even");
orintf("odd"));

Youth Academy Official Website: www.youthacademy.pk


YOUTH ACADEMY YOUTUBE CHANNEL SIR USAMA

Code Description Error/Output/Action


31. What is the value of the variable price after Error: Missing semicolon after the first if statement.
executing the following code? int price=10;
if(price!=10) price=0 else price+=2;
32. Trace Output: if(7%3==0) printf("Punjab"); Output: KPK
else printf("KPK");
33. Trace Output: int x=5, y=10; if(x>y) y=y+1; Output: Value of y=10
printf("Value of y=%", y);
34. Find the error: void main() { int y=10; Error: IFF should be if, and === should be ==.
IFF(y===5) printf("%d",y); }
35. Predict the output of the following code Error: Incorrect condition format. Should be && for
segment: int a=1, b=2, c=3; if((a==b) (b==c) logical AND.
(c==4)) printf("Yes"); else printf("No");
36. Determine the output of the given code: int Output: 6
a=1; int b=6; if(a+b<7) printf("%d", a); else
printf("%d", b);
37. Find the errors in the given code: int n=2 Errors: Missing semicolon after int n=2, and a is not
if(a=1) printf("Ok"); Else printf("Cancel"); declared. Should use == for comparison.
printf("%d", n);
38. The output of the following code: `#include
void main() { char grade ="c"; if(grade="a"
39. Find errors: void main() { int a=2 if(a=1) print Errors: Missing semicolon, incorrect print f (should
f("Ok"); else printf("Cancel"); getch() } be printf), and missing return 0; in main().
40. Find output: `int x=1; int y=2; int z=3; if((x==y)
41. Write down output of the following code: void Error: Invalid operator ! 10. Should be x != 10.
main() {int x=10; if(x! 10) printf("Hello"); else
printf("World"); }
42. Determine the output: int x==1, y=2, z=3; If Error: Incorrect if syntax. Should be if (condition).
{(x==y) (y==z) (z==2)} printf("yes"); else
printf("No");
43. Convert the following conditional expression if(x<0) { y=10; } else { z=20; }
into if else statement: x<0? y=10 : z=20;
44. Convert the following code to an equivalent if- if(x>y) Answer=x*y; else Answer=x+y;
else statement: Answer=(x>y)?x*y:x+y;
45. Find errors in the following code segment: int Error: Missing semicolon after int a=20, and
a=20 if(a=10); printf("OK"); else improper comparison operator (= should be ==).
printf("cancel");
46. What will be the output of the following: int Output: Even
x=10; (x%2==0)? printf("Even"): printf("odd");
47. Find errors: void main(void), { intx=10; if(x=10) Error: Missing semicolon after intx=10;, should use
printf("True"); end if } if(x==10) and end if should be replaced by }.
48. Show Output: if (1==2) printf("Programming"); Output: Correct it
else if (2==1) printf("Language"); else
printf("Correct it");
49. Write down output: int x=20; if (x!=10) Output: Nothing
printf("Nothing"); else printf("Hello");
Youth Academy Official Website: www.youthacademy.pk
YOUTH ACADEMY YOUTUBE CHANNEL SIR USAMA

Code Description Error/Output/Action


50. Convert the following code to an equivalent if- if(x>y) { result=x*y; } else { result=x+y; }
else statement: (x>y)? x*y:x+y;
51. Determine the output of the following code KPK: The condition 2 == 4 is false, so the else block is
segment: if(2==4) printf ("PUNJAB"); else executed.
printf ("KPK");
52. What is the output of the following code: if (2 Bad: 2 % 3 is 2, and 2 >= 1 is true, so "Good" is
% 3 >= 1) printf ("Good"); else printf ("Bad"); printed.
53. Write a C-statement that assigns 1 to the y = (x > 0) ? 1 : -1;
variable y if the value of the variable x is
greater than 0. Otherwise, it assigns -1 to the
variable y.
54. Convert the following conditional expression if (x < 0) { y = 31; } else { z = 21; }
into if-else statement: x<0? y=31:z=21;
55. Write a code to increase the value of max by max += 5;
5.
56. Find and remove the errors in the following Error: == should be =. Corrected: int a = 405; a = a *
code: int a==405; a=a*2; printf("%d",a); 2; printf("%d",a);
57. Write C statement to declare integer variable int x = 8;
X and assign value 8 to x in a single statement.
58. Write down output of following code: int 20 is greater: Since a is not greater than b, the else
a=10; int b=20; if (a>b) printf ("%d is greater" block is executed.
,a); else printf ("%d is greater",b);
59. What will be the output of the following code: 10: y = ++x assigns 11 to y, then x = 11, y = 11. y--
int x=10, y=++x; x=y--; printf ("%d", y); makes y 10, but the value y before decrement is
printed.
60. Write down output: int N=65; printf("% c", N); A: The ASCII value 65 corresponds to A.
61. Trace output: printf ("Pakistan is t Pakistan is t homeland: The output is the string as it
homeland"); is, no error in the syntax.
62. Discuss the role of " ". " " (a pair of double quotes) is used to represent a
string literal in C.
63. Trace error from the following code: int x; Error: x should be passed as a reference. Corrected:
scanf("%d",x); scanf("%d", &x);
64. Write C statement to print the value of double printf("%.2f", b);
variable b with two digits showing after the
decimal point.
65. Write C statement to print the value of printf("%lu", x);
unsigned long x.
66. Find error in the following code segment: Error: print should be printf, and missing a
#include; void main() { print("Hello world") } semicolon. Corrected: #include <stdio.h> void main()
{ printf("Hello world"); }
67. Find error in the following code segment: . Error: include should be #include and missing
include main() { int i=10; printf("%d",i); } semicolon after int i=10.
68. Trace the error in the following code segment: Error: #include should have angle brackets < >. scanf
#include(stdio.h) main() { float n; should have &n. Corrected: #include <stdio.h>
scanf("%d",n); printf("the number is %f",n); }
Youth Academy Official Website: www.youthacademy.pk
YOUTH ACADEMY YOUTUBE CHANNEL SIR USAMA

Code Description Error/Output/Action


main() { float n; scanf("%f", &n); printf("the number
is %f", n); }
69. Trace the error in the following code segment: Error: p is undeclared. It should be n. Corrected: int
int n; printf("enter any number"); n; printf("enter any number"); scanf("%d", &n);
scanf("%c",&p); printf("number=",n) printf("number=%d",n);
70. Trace the errors: #include; void main () { printf Error: Missing #include <stdio.h>, and missing
("High Level Language") } semicolon after printf. Corrected: #include <stdio.h>
void main () { printf("High Level Language"); }
71. Find the errors in the following code: #include; Errors: Missing #include <stdio.h>, r is undeclared.
void main () { float area; r; scanf ("%c",&r); Corrected: #include <stdio.h> void main () { float
area=3.14*r*r; printf ("area=%f",area); } area, r; scanf("%f", &r); area = 3.14 * r * r;
printf("area=%f", area); }
72. Find errors of C code: in a=10, b=40; print Errors: in should be int and print should be printf.
("sum: ",a+b) Corrected: int a = 10, b = 40; printf("sum: %d", a +
b);
73. Write output of following code: int x = 4 * 5 / 2 23: Calculation is 4 * 5 = 20, 20 / 2 = 10, 10 + 9 = 19.
+ 9; printf(" %d", x);
74. Write the output of following code: int a, b, c; The sum of a + b = 15
a = 5; b = 10; c = a + b; printf("The sum of a + b
= %d", c);
75. Determine the Output: printf("77 n"); 77 n77: The n is printed as a normal character.
printf("77");
76. Determine the Output: int num = 10; num *= 50: The *= operator multiplies num by 5.
5; printf("%d", num);
77. Write the code to input a value for an integer scanf("%d", &n);
n.
78. Determine the output of the following code: A: The ASCII value 65 corresponds to the character
int N=65; printf("%c", N); A.
79. What is the output of the following code f= 1.341: The value is rounded to 3 decimal places.
segment: float f = 1.341129; printf ("f=%7.3f",
f);
80. Determine the output of the following Code f=6.32: The value is rounded to 2 decimal places.
Segment: float f = 6.3159; printf("f=%3.2f", f);
81. Write a Single C statement to print the printf("Hello to\nThe World of\nC programming");
following Output: Hello to The World of C
programming
82. Find Errors: #include (Stdio.n); #include void Errors: Incorrect include syntax, then should be
main () { if (16>10)then printf("%C", removed, and getch is missing #include <conio.h>.
"Pakistan"); getch(); }
83. Predict the output of the following code Yes: 2 % 3 = 2, and 2 >= 1 is true.
segment: if (2%3>=1) printf ("Yes"); else
printf("No");
84. Find the errors: if (x=1 or 2) printf ("%d",x); Error: or should be `
85. Rewrite the expression x+2, without using x = x + 2;
compound assignment operator.

Youth Academy Official Website: www.youthacademy.pk


YOUTH ACADEMY YOUTUBE CHANNEL SIR USAMA

Code Description Error/Output/Action


86. Determine the output of following code: int 4: Integer division of 9 / 2 gives 4.
b=9; b=b/2; printf("%d", b);
87. What will be the output of the following: int 6: The post-decrement operator first assigns 6 to x,
number = 6; x = number--; printf ("%d", x); then decreases the value of number.
88. Determine output of the code: int x = 15; int y 0 3: 15 % 5 = 0 and 15 / 5 = 3.
= 5; printf("%d %d", x % y, x / y);
89. Convert the following sentence into C Age >= 20
expression: "Age is greater than equal to 20"
90. Find the errors: int n = 4.2; Error: n should be a float, not an integer. Corrected:
float n = 4.2;
91. Write a statement to declare an integer int i = 10;
variable i initialized to 10.
92. Write the following statement in C Language if (speed <= 60)
code: Speed not greater than 60.
93. Predict the output of the following code: int m 3 4: 15 % 4 = 3 and 4 % 15 = 4.
= 15, n = 4; printf ("%d %d", m % n, n % m);
94. Write errors in the following code: Float avg; Error: Float should be float and avg should be &avg.
printf ("Enter a number: "); scanf ("%f", avg); Corrected: float avg; scanf("%f", &avg);
95. Find errors in the following code: Void main (); Errors: Void should be void, and nj should be n1.
{ float n₁ = 4.5, n₂ = 7.2; printf ("%f /t %f", nj, Corrected: void main() { float n1 = 4.5, n2 = 7.2;
n2); } printf("%f /t %f", n1, n2); }
96. printf("Male"); else printf ("Female"); Error: else should be connected with an if.
97. Convert the following while loop into for loop: for (int i = 5; i <= 10; i++) { printf("%d\n", i); }
int i = 5; while (i <= 10) { printf("%d\n", i); }

Code Description Error/Output/Action


98. Find any two errors: char ch, ch1, sum; chl='2'; Errors: 1. chl='2'; should be ch1='2'; (variable names
ch2='6'; don't match). 2. ch2='6'; should be ch1='6'; (variable
name incorrect).
99. Find output: int x = 7; int y = 3; printf("%d and Output: 2 and 1 Explanation: x/y = 7/3 = 2 (integer
%d", x/y, x%y); division), x%y = 7%3 = 1 (remainder).
100. Find any two errors: void main (); { int B = Errors: 1. void main (); should be void main() {
20; printf("%d ", b); } (incorrect syntax). 2. b should be B (case-sensitive).
101. Write down the output of the following Output: Pakistan Zindabad We Pakistani people (Tab
code: printf("Pakistan \t Zindabad \n"); space \t and newline \n affect output formatting).
printf("We \t \t Pakistani \t people ");
102. Predict the output of the following code Output: No output, as neither condition is true.
segment: if (50 == 70) printf("HAPPY"); else if
(80== 100) printf("NOT HAPPY ");
103. Convert the following while() loop into a Converted for loop: for(int i = 5; i <= 10; i++) {
for() loop: int i = 5; while (i <= 10) { printf("%d\n", i); }
printf("%d\n", i); }

Youth Academy Official Website: www.youthacademy.pk


YOUTH ACADEMY YOUTUBE CHANNEL SIR USAMA

Code Description Error/Output/Action


104. Predict the output of the following code Output: 1 3 5 7 9 (The loop increments by 2 each
segment: int c; for (c = 1; c <= 10; c = c + 2) time).
printf("%d ", c);
105. Find any two errors: int a 10, b = 40, Errors: 1. int a 10; should be int a = 10; (missing =). 2.
The declaration should end with ;.
106. Find any two errors: Void main (); Errors: 1. Void main (); should be void main() {. 2.
printf("Sum =:", a* b) The syntax printf("Sum =:", a* b) should be
printf("Sum =: %d", a * b); (missing format specifier).
107. Write the output of the following code: Output: Escape sequence is a " cool "feature of 'C-
printf("Escape sequence is a \" cool \"feature language"
of \'C-language\"");
108. Find any two errors: Void main (); float i = Errors: 1. Void should be void. 2. printf("%d", i)
15.6; printf("%d", i), should be printf("%f", i) to match the type float.
109. Find errors in the following code segment: Errors: 1. m = 10.3; should be m = 10; (can't assign a
int m, n; m = 10.3; i. n = 5; ii. printf("%d", m) float to an int). 2. i. and ii. are unnecessary and
should be removed.
110. Predict output of the following code Output: 10 8 (2*x = 10, 3+x = 8).
segment: int x = 5; printf("%d \t%d", 2*x, 3 +
x);
111. Convert the following code into do-while Converted do-while loop: int i=0; do { printf("loop
loop: int i=0; while (i == 1) { printf("loop statement"); i+=2; } while(i == 1);
statement"); i+=2; }
112. Predict the output: int a = 5; if (a%2==0) Output: Zindabad (Since a%2 is 1, the else block is
printf("Pakistan"); else printf("Zindabad"); executed).
113. Trace the output of the following code: Output: Book reading is a very good
printf("Book\t reading \n"); printf("is a \t very
good");
114. Convert the following code to an Converted to if-else: if (x > y) { result = x * y; } else {
equivalent if-else statement: (x>y)? x * y:x + y; result = x + y; }
115. Trace output: if 10 mod 5 == 1 then print Error: Incorrect syntax. Should be: if (10 % 5 == 1) {
"OK" End if printf("OK"); }
116. How many times does the following loop Infinite loop because the condition i > 1 is always
execute? i = 10; do while i > 1 i = i + 1 loop true after i starts at 10.
117. Find errors in the following Code: int a; b; Errors: 1. Missing semicolon after b = 5;. 2. The printf
a = 10; b = 5; printf("%d"; a+b); should be printf("%d", a + b);.
118. Write the following expression in C Corrected: n = 5 * m * z * 2; (assuming m and z are
language: n = 5mz2 defined).
119. Predict the output of the following Code Output: I LOVE PAKISTAN
Segment: printf("I\t\n LOVE \t\t\t\n PAKISTAN
");
120. Determine the output of the following Error: Sum should be sum (case-sensitive).
Code Segment: int x, y, sum; x = 5; y = 10; sum
= x + y; printf("Sum = %d", Sum);

Youth Academy Official Website: www.youthacademy.pk


YOUTH ACADEMY YOUTUBE CHANNEL SIR USAMA

Code Description Error/Output/Action


121. Find errors in the following Code segment: Errors: 1. Incorrect inclusion of header: #include
# include (Stdio.h) main() { char a = 'b’; <stdio.h>. 2. print should be printf.
print("% C", a); }
122. Convert the following loop into a for loop: Converted for loop: for (int i = 10; i <= 20; i++) {
i = 10; while (i <= 20) printf("Loop"); printf("Loop"); }
123. What is the Output of the following Code, Output: b is larger or equal because a is not greater
when a = 1000 and b = 5000? If (a > b) than b.
printf("a is larger"); else printf("b is larger or
equal");
124. What is the output of the following Code: Output: 7 8 9 10 11 12 13 14 15
x = 7; while (x <= 15) { printf("%d", x); x++; }
125. Write output of the following Code Output: 2 4 6 8 10
Segment: m = 1; do { printf(m * 2); m++; }
while (m <= 5);
126. Trace Output: void main () { int a = 5; a* = Output: 10 (5 * 2 = 10).
2; printf("%d", a); }
127. Trace Errors in the following: Char ch = a; Errors: 1. Char should be char. 2. scanf("%d, ch);
scanf("%d, ch); should be scanf("%c", &ch); for reading a character.
128. Write the output of the following code: Output: 79.2 (The space adds padding for the
Float p = 79.23; printf("% 10.1f", p); width).
129. Convert the following sentence into C C Expression: marks > 70 && marks < 80
Expression: "marks are greater than 70 and
less than 80"

Question Solution/Explanation
130. Predict the output of the following code Output: PUNJAB because a > b is true.
segment: int a = 10, b = 5; if (a > b)
printf("PUNJAB"); else printf("KPK");
131. Convert the following code into a while Converted while loop: int i = 1; while (i <= 5) {
loop: int i; for (i = 1; i <= 5; i++) { printf("In printf("In Pakistan"); i++; }
Pakistan"); }
132. Trace the output: if (10 MOD 3 == 0) Then Output: NO because 10 MOD 3 is 1, not 0.
print("YES") else print("NO")
133. Write errors in the following code: int m, Errors: 1. m = 10.3; should be m = 10; (int cannot
y; m = 10.3; y = 5; print("%d %d", m, y) hold a float). 2. print should be printf.
134. Predict the output of the following code: Output: 15 -5 Explanation: x = 5 + 10 = 15, y = 10 - 15
int x = 5, y = 10; x = x + y; y = y - x; printf("%d = -5.
%d", x, y);
135. Find errors in the following code: #include Errors: 1. #include <studio> should be #include
<studio> void main() { int a = 10; printf("%d", <stdio.h>. 2. void main() is acceptable but int main()
a); } is preferable.
136. Predict the output of the following code: Output: 512 2 because n % 10 returns the remainder
int n = 512, b; b = n % 10; printf("%d \n %d", when n is divided by 10.
n, b);

Youth Academy Official Website: www.youthacademy.pk


YOUTH ACADEMY YOUTUBE CHANNEL SIR USAMA

Question Solution/Explanation
137. Predict the output of the following code: Output: pass because ch is assigned 'p', so the
char ch; ch = 'p'; if (ch == 'p') printf("pass"); condition is true.
else printf("fail");
138. Give output of the following code: for (int Output: 1 4 9 16 25 because the squares of 1, 2, 3, 4,
x = 1; x <= 5; x++) printf("%d\n", x * x); 5 are printed.
139. Convert the following for loop into a while Converted while loop: int i = 1; while (i <= 5) {
loop: for (int i = 1; i <= 5; i++) printf("%d\n", i); printf("%d\n", i); i++; }
140. Write output of following code segment: x Output: 2 4 6 8 10 12 14 (x starts at 0, increments by
= 0 while x <= 15 print x + 2 x = x + 2 wend 2 each time).
141. What will be the value of x and y? If x = 7; Explanation: x = 7, y = 7 (post-increment: x++ gives y
y = x++; = 7 but then increments x to 8).
142. Find the errors: int a, b = 20; Error: The declaration should be int a = 0, b = 20;
(uninitialized a causes an issue).
143. Determine the output of the following Output: 555 It999In 444 (The outputs are printed
code segment: void main() { printf("555 It"); consecutively).
printf("999"); printf("In 444"); }
144. Determine the output of the following Output: KPK because the condition 2 == 4 is false.
code segment: if (2 == 4) printf("PUNJAB");
else printf("KPK");
145. Convert the following for loop into a while Converted while loop: int i = 1; while (i <= 5) {
loop: for (i = 1; i <= 5; i++) printf("ok"); printf("ok"); i++; }
146. Find the errors in the following code: Errors: 1. integer should be int. 2. y = 20.5; should be
integer x, y; x = 10, y = 20.5; y = 20; or use float.
147. Write the given expression in C-Language: Correct C Expression: a = 2 * b * 2 * c * 3;
a = 2b2c3
148. Determine the output of the following Output: 2 because x++ first increments x to 2 and
code: int x = 1; x++; printf("%d", x++); then prints 2.
149. Find errors in the following code: void Errors: 1. printf(OK) should be printf("OK"); (missing
main() { printf(OK); } quotes around string).
150. What will be the output of the following Output: HelloWn Dear! (No errors; the message is
code: printf("HelloWn Dear!"); printed as it is).
151. What does "4+" mean in file handling? Explanation: 4+ typically indicates a file mode in file
handling (e.g., reading and writing), though the
exact context might vary.
152. Trace the output of the following code Output: 2 because the else block executes (p > q is
segment: int p = 3, q = 5; if ((p > q) && (p != false).
4)) p = p + 1; else p = p - 1; printf("%d", p);
153. Convert the following code into a while Converted while loop: int a = 1; while (a <= 10) {
loop: void main(void) { int a, k = 1; for (a = 1; printf("%d\n", k + a); a++; }
a <= 10; a++) printf("%d\n", k + a); }
154. Trace the output: If (10 MOD 3 == 0) Then Output: NO because 10 MOD 3 is 1, not 0.
Print("YES") Else Print("NO") End if
155. What is the output of the following code? Output: x=7 and y=12 because y = 2 + 10 = 12 and x =
int y = 10; int x = 2; y = x + y; x = x + 5; 2 + 5 = 7.
printf("x=%d and y=%d", x, y);
Youth Academy Official Website: www.youthacademy.pk
YOUTH ACADEMY YOUTUBE CHANNEL SIR USAMA

Question Solution/Explanation
156. Indicate the errors in the following lines: Errors: 1. Variable 5 is invalid. 2. printf('%s', x);
int 5 = x; x = +x; printf('%s', x); should use double quotes: printf("%s", x);.
157. Find out the errors: void main(void) { int Errors: 1. total marks should be total_marks. 2. float
total marks = 500; int OM = 300; float p = 0M p = 0M * 100 total marks; is invalid. It should be
* 100 total marks; printf("%f", p); } corrected to float p = (OM * 100.0) / total_marks;.
158. Predict the output: int x = y = 5; Output: 6 6 because ++x increments before printing,
printf("%d\n %d", ++x, x++); and x++ increments after printing.
159. Convert the following code segment into a Converted while loop: int i = 1; while (i <= 20) {
while loop: void main() { int i; for (i = 1; i <= printf("loop"); i++; }
20; i++) printf("loop"); }
160. Predict the output of the following code Output: 7654321 (The numbers are printed in
segment: int n; for (n = 7; n >= 1; n--) decreasing order).
printf("%d", n);
161. Find errors in the following code segment: Errors: 1. scanf("%d", x); should be scanf("%d", &x);
int x = 10 + 20; scanf("%d", x); printf("value of because x is an integer.
x = ", x);
162. What is the output of the following code Output: 7 because z = (2 + 5) / (3 + 5) = 7 / 8 = 0.
segment: int x = 2, y = 3, z; z = (x + 5) / (y + 5);
printf("%d", x + y + z);
163. Find the errors in the following code Errors: 1. L * W = A;
segment: int L = 10, W = 5, A; L * W = A;
printf("Area = %d", Area);
164. Question Solution/Explanation
165. Predict the output of the following code Output: PUNJAB because a > b is true.
segment: int a = 10, b = 5; if (a > b)
printf("PUNJAB"); else printf("KPK");
166. Convert the following code into a while Converted while loop: int i = 1; while (i <= 5) {
loop: int i; for (i = 1; i <= 5; i++) { printf("In printf("In Pakistan"); i++; }
Pakistan"); }
167. Trace the output: if (10 MOD 3 == 0) Then Output: NO because 10 MOD 3 is 1, not 0.
print("YES") else print("NO")
168. Write errors in the following code: int m, Errors: 1. m = 10.3; should be m = 10; (int cannot
y; m = 10.3; y = 5; print("%d %d", m, y) hold a float). 2. print should be printf.
169. Predict the output of the following code: Output: 15 -5 Explanation: x = 5 + 10 = 15, y = 10 - 15
int x = 5, y = 10; x = x + y; y = y - x; printf("%d = -5.
%d", x, y);
170. Find errors in the following code: #include Errors: 1. #include <studio> should be #include
<studio> void main() { int a = 10; printf("%d", <stdio.h>. 2. void main() is acceptable but int main()
a); } is preferable.
171. Predict the output of the following code: Output: 512 2 because n % 10 returns the remainder
int n = 512, b; b = n % 10; printf("%d \n %d", when n is divided by 10.
n, b);
172. Predict the output of the following code: Output: pass because ch is assigned 'p', so the
char ch; ch = 'p'; if (ch == 'p') printf("pass"); condition is true.
else printf("fail");

Youth Academy Official Website: www.youthacademy.pk


YOUTH ACADEMY YOUTUBE CHANNEL SIR USAMA

Question Solution/Explanation
173. Give output of the following code: for (int Output: 1 4 9 16 25 because the squares of 1, 2, 3, 4,
x = 1; x <= 5; x++) printf("%d\n", x * x); 5 are printed.
174. Convert the following for loop into a while Converted while loop: int i = 1; while (i <= 5) {
loop: for (int i = 1; i <= 5; i++) printf("%d\n", i); printf("%d\n", i); i++; }
175. Write output of following code segment: x Output: 2 4 6 8 10 12 14 (x starts at 0, increments by
= 0 while x <= 15 print x + 2 x = x + 2 wend 2 each time).
176. What will be the value of x and y? If x = 7; Explanation: x = 7, y = 7 (post-increment: x++ gives y
y = x++; = 7 but then increments x to 8).
177. Find errors in the following code: int a, b = Error: The declaration should be int a = 0, b = 20;
20; (uninitialized a causes an issue).
178. Determine the output of the following Output: 555 It999In 444 (The outputs are printed
code segment: void main() { printf("555 It"); consecutively).
printf("999"); printf("In 444"); }
179. Determine the output of the following Output: KPK because the condition 2 == 4 is false.
code segment: if (2 == 4) printf("PUNJAB");
else printf("KPK");
180. Convert the following for loop into a while Converted while loop: int i = 1; while (i <= 5) {
loop: for (i = 1; i <= 5; i++) printf("ok"); printf("ok"); i++; }
181. Find the errors in the following code: Errors: 1. integer should be int. 2. y = 20.5; should be
integer x, y; x = 10, y = 20.5; y = 20; or use float.
182. Write the given expression in C-Language: Correct C Expression: a = 2 * b * 2 * c * 3;
a = 2b2c3
183. Determine the output of the following Output: 2 because x++ first increments x to 2 and
code: int x = 1; x++; printf("%d", x++); then prints 2.
184. Find errors in the following code: void Errors: 1. printf(OK) should be printf("OK"); (missing
main() { printf(OK); } quotes around string).
185. What will be the output of the following Output: HelloWn Dear! (No errors; the message is
code: printf("HelloWn Dear!"); printed as it is).
186. Trace the output of the following code Output: 2 because the else block executes (p > q is
segment: int p = 3, q = 5; if ((p > q) && (p != false).
4)) p = p + 1; else p = p - 1; printf("%d", p);
187. Convert the following code into a while Converted while loop: int a = 1; while (a <= 10) {
loop: void main(void) { int a, k = 1; for (a = 1; printf("%d\n", k + a); a++; }
a <= 10; a++) printf("%d\n", k + a); }
188. Trace the output: If (10 MOD 3 == 0) Then Output: NO because 10 MOD 3 is 1, not 0.
Print("YES") Else Print("NO") End if
189. What is the output of the following code? Output: 195 because 'a' + 'b' is the sum of their ASCII
printf("%d", 'a' + 'b'); values (97 + 98).
190. Indicate the errors in the following lines: Errors: 1. Variable 5 is invalid. 2. printf('%s', x);
int 5 = x; x = +x; printf('%s', x); should use double quotes: printf("%s", x);.
191. Find out the errors: void main(void) { int Errors: 1. total marks should be total_marks. 2. float
total marks = 500; int OM = 300; float p = 0M p = 0M * 100 total marks; is invalid. It should be
* 100 total marks; printf("%f", p); } corrected to float p = (OM * 100.0) / total_marks;.

Youth Academy Official Website: www.youthacademy.pk


YOUTH ACADEMY YOUTUBE CHANNEL SIR USAMA

Question Solution/Explanation
192. Predict the output: int x = y = 5; Output: 6 6 because ++x increments before printing,
printf("%d\n %d", ++x, x++); and x++ increments after printing.
193. Write two uses of loop: Explanation: 1. To repeat a set of instructions until a
condition is met. 2. To iterate over a collection or
array.
194. Convert the following code segment into a Converted for loop: for (int count = 1; count <= 10;
for loop: int count = 1; while(count <= 10) { count++) { printf("%d\n", count); }
printf("%d\n", count); count++; }
195. Predict the output of the following code Output: 7654321 (The numbers are printed in
segment: int n; for (n = 7; n >= 1; n--) decreasing order).
printf("%d", n);
196. Find errors in the following code segment: Errors: 1. scanf requires the address of the variable,
int x = 10 + 20; scanf("%d", x); printf("value of so it should be scanf("%d", &x);.
x = ", x);
197. What is the output of the following code Output: 7 because z = (2 + 5) / (3 + 5) = 7 / 8 = 0.
segment: int x = 2, y = 3, z; z = (x + 5) / (y + 5);
printf("%d", x + y + z);
198. Find the errors in the following code Errors: 1. L * W = A; should be A = L * W;. 2.
segment: int L = 10, W = 5, A; L * W = A; printf("Area = %d", Area); should be printf("Area =
printf("Area = %d", Area); %d", A);.
199. What is the output of the following code Output: BC because ch1 is assigned the value of ch2
segment: char ch1 = 'A', ch2 = 'B'; ch1 = ch2; before ch2 is changed to 'C'.
ch2 = 'C'; printf("%c%c", ch1, ch2);
200. Determine the output: int a = 1, b = 5; if Output: Answer-6 because the if condition is false,
((a + b) < 6) printf("Result-%d", b); and only the second printf is executed.
printf("Answer-%d", a + b);
201. Write the output of the following code: int Output: 0 10 1 9 2 8 3 7
K = 0; while(K <= 5) { printf("%3d%3d\n", K,
10 - K); K++; }

Youth Academy Official Website: www.youthacademy.pk


‫‪YOUTH ACADEMY YOUTUBE CHANNELS‬‬

‫‪FEATURES OF YOUTH ACADEMY‬‬

‫اپاتسکنیکبسےسڑبی‪ONLINE‬اڈیکیم‬

‫‪1‬رکوڑےسزادئابلطءوک ‪YouTube‬رپ ڑپاھےنواالوادحااار‬

‫‪ 1‬رکوڑابلطءوکااحتمانتیکایتریرکواےنواالوادحااار‬

‫ےلھچپ‪5‬اسولںےسابلطءاکرپاامتعاااار‬

‫بسےسزایا ونسٹرفامہرکےنواالوادحااار‬

‫‪YouTube‬رپ‪Plans, Strategies,‬اےنیواالالہپااار‬

‫اپاتسکنںیمیلہپابر ‪LIVE CLASSES‬‬

‫ابلطءوکرھگےھٹیبااحتمنیکایتریرکواےنواالااار‬
Youth Academy: Premier Online Learning Platform
‫ رہ اسل زہاروں ہبلط ویھت اڈیکیم اک ہصح نب رک رھگ ےھٹیب اٰیلع ایعمر یک میلعت احلص رک رےہ ںیہ۔ مہ ابلطء وک ااحتمین ایتری‬،‫ادمحلہلل‬
:‫ ومشبل‬،‫ےک ےیل امتم رضوری واسلئ رفامہ رکےت ںیہ‬
‫سل‬
(Monthly Syllabus)‫ اماہہن یبس‬
(Test Series)‫ ٹسیٹ ریسزی‬
(Pakistan's Best Notes)‫ اپاتسکن ےک رتہبنی ونسٹ‬
(Live Lectures)‫ الویئ رچکیلز‬
(Online Teacher Support)‫ آن النئ رچیٹ وپسرٹ‬

!‫ہی امتم وہسایلت یسک تمعن ےس مک ںیہن‬


Why Choose Youth Academy?
One-Time Affordable Fee – Only Rs. 2000/2500

‫روےپ اک افدئہ – ااہتنیئ مک تمیق رپ رتہبنی یمیلعت ایعمر‬50,000+


‫سل‬
‫لمکم یبس ےک اطمقب ایتر دشہ‬-Pakistan’s Best Notes

Key Features:
 Fast Revision Tools
 Exam-Focused Preparation
 Live & Recorded Lectures
 Interactive Classes
 Test Series
 Past Papers Analysis
 Live Teacher Support
 Subject Specialist Teachers
 Mobile App Access
 Practice Questions
 Guess Papers
 Authentic Pairing Schemes

Enroll Now!
Visit: www.youthacademy.pk / Contact on WhatsApp Number Available on Website
Youth Academy – Affordable Excellence in Education!

You might also like