Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
83 views

Convert the following while loop into for loop

Uploaded by

aamirshahzad3321
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views

Convert the following while loop into for loop

Uploaded by

aamirshahzad3321
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

19. Convert the following while Code 44.

Write equivalent statement in


loop into for loop: ```C C language for the following:
Code void main() { s=vit+12at2s = vit + \frac{1}
```C int i; {2}at^2s=vit+21at2
int i = 5; 45. Predict output of the
for (i = 1; i <= 10; i++)
while (i <= 10) { following code segment:
printf("Pakistan");
Code
printf("%d \n", i); }
```C
i++;
int x = 7;
} 28. Determine output of the
following code: int y = 3;
20. Predict the output of the Code printf("%d %d", x % y, y %
following code segment and x);
```C
draw flow chart: ```
int i, p = 1;
for (i = 1; i < 6; i += 1) {
```C 46. Find errors in the following
p *= 2; code:
char g;
printf("%d", p); Code
if (g == 'M') {
} ```C
printf("Male");
} else { void main() {
10. Write the following statement
printf("Female"); int f = 7;
in C language code: "Speed
} not greater than 60." printf("%d", f);
Code }
21. Predict the output of the ```C
following code segment: if (speed <= 60) { 47. Find errors in the following
Code printf("Speed is not greater than 60"); code segment:
```C } Code
int x = 1; ```C
while (x++ <= 5) { 11. Predict the output of the void main() {
printf("%d \n", x); following code: int x = 5;
} Code int y = 3;
```C sum = x + y;
22. What is the purpose of void int main() { printf("%d", sum);
used in the following function int n1 = 15, n2 = 5; }
declaration? printf("%d %d", n1, n2);
void counter(void); } 53. Trace output of the following
code segment:
26. Determine output of the 12. Find errors in the following Code
following code segment: code: ```C
Code Code int p = 3, q = 5;
```C ```C
if (p > q
int x = 1, y = 2, z = 3; float avg;
p = p + 1;
if ((x == y) printf("Enter a number: ");
scanf("%f", avg); else
printf("Yes");
``` p = p - 1;
else
printf("%d", p);
printf("No");
13. Predict output of the
```
following code:
printf("Hello \n 1. Convert the following code
27. Convert the following code Pakistan \n"); into a while loop:
into while loop: printf("123 \t Over!");
C
. C 59. Find the errors in the
void main() .
following code:
{ a = 2b^2c^3
int a, k=1;
for (a=1; a<=10; a++) C
printf("%d", k+a);
37. Find the errors in the .
} following code: Integer x, y;

C 60. Determine the output of the


3. Predict output: .
following code:
Integer x, y;
C
. C
a=3; 38. Determine the output of the .
for (i=5; i>0; i--) following code: x = 10, y = 20.5;
a=a+i; printf("%d", x++);
printf("%d\n", a); C
.
4. Write down equivalent C x = 10, y = 20.5; 1. Find any two errors:
printf("%d", x++);
statement for: (a-b)^2
5. Find errors in the following C
39. Find errors in the following .
code segment:
code segment: a=10,
b=40,
C print("Sum", a*b)
. C
int x = 10 + 20; .
scanf("%d", x); void main() { 13. Find any two errors:
printf("value of x = %d", x); printf(OK);
} C
20. What is the output of the .
41. What will be the output of the void main();
following code segment: float i=15.6;
following code?
printf("%d", i);
C
. C
int x = 2, y = 3, z; . 14. Write the given expression in
z = (x + 5) / (y + 5); printf("\" Hello \\n Dear"); C-Language:
printf("%d", x + y + z);
42. Find any two errors: C
21. Find the errors in the .
C a = 2b^2c^3
following code segments:
.
a=10, 16. Find the errors in the
C
b=40, following code:
.
print("Sum", a*b)
int l = 10, w = 5, area;
l * w = area; C
printf("Area = %d", area); 56. Find any two errors: .
Integer x, y;
23. What is the output of the C
. 17. Determine the output of the
following code segment: void main();
float i=15.6; following code:
C printf("%d", i);
. C
char ch1 = 'A', ch2 = 'B'; .
ch1 = ch2; 57. Write the given expression in x = 10, y = 20.5;
ch2 = ch1; C-Language: printf("%d", x++);
printf("%c%c", ch1, ch2);
C 18. Determine the output:
24. Write the given expression in .
a = 2b^2c^3
C-Language: C
.
int a=1, b=5; while (count <= 10) 1. Convert the following code
if ((a+b)<6) {
into while loop:
printf("Result %d ",b); printf("%d \n", count);
else count++;
printf("Answer-%d", a+b); } C
.
for(i=1; i<=5; i++)
21. Write the output of the 35. Write the output of the printf("In Pakistan");
following code: following code segment:
3. Predict the output of the
C C
following code segment:
. .
k=0; int a = 3, b = 2;
while(k<=5) printf("Result = %d", a % b); C
{ .
printf("%3d%3d\n", k, 10- int n;
k); for(n=10; n>-10; n--)
k++; 50. Predict the output of the printf("%d", n);
} following code segment:
4. Write the following statement
23. Convert the following code C in C-Language code:
.
by using a for loop: int a=10, b=5;
C
printf("Punjab");
C .
printf("KPK");
. “Temp between 15 and 32
int count = 1; inclusive”
while (count <= 10)
{ 48. Find any two errors: 10. Write errors in the following
printf("%d \n", count); code:
count++; C
} .
C
void main();
.
24. Determine the output: int a=10, b;
int m, y;
printf("%d", b);
m = 10.3;
C y = 5,
. 37. Write down the following printf("%d %d", m, y);
int a=1, b=5; statement in C-language:
if ((a+b)<6) 11. Predict the output of the
printf("Result %d ",b); C
else following code segment:
.
printf("Answer-%d", a+b); "Age is between 18 years and
C
50 years"
.
32. Write the output of the int x = 5, y = 10;
following code: 46. Find any two errors: x = x + y;
y = y - x;
C C printf("%d %d", x, y);
. .
k=0; integer x, y, z=x+y; 12. Find errors in the following
while(k<=5) printf("z=%d", z);
{ code:
printf("%3d%3d\n", k, 10-
k);
47. Find output: C
k++; .
} C #include< studio.h>
. int n = 512, b;
a=5; void main()
34. Convert the following code printf("Result = %d", a++); {
by using a for loop: int a = 10;
printf("%d", a);
C }
.
int count = 1;
14. Convert the following for C C
. .
loop into while loop:
int price = 19; int x=10, y=-6, t=-3;
if (price != 10) if (x+y<y+t)
C printf("Price "); printf("%d", y+t);
. else
for(int i = 1; i <= 5; i++) printf("%d", x+t);
printf("%d\n", i); 32. Convert the following do-
while loop into for loop:
49. Convert the following into a
19. Predict the output of the
C while loop:
following code:
.
int c = 2; C
C do { .
. c = c * 2; for(i=1; i<=5; i++)
for(int n = 10; n > -10; n--) } while (c < 5); printf("Pakistan");
printf("%d", n); printf("%d", c);
51. Predict the output of the
20. Convert the expression A = B 34. Predict the output of the following code:
+ C into C-language. following code:
21. If x = 2, give the output of the C
following code: C .
. char x;
C int x = 5, y = 3; do {
. do { printf("%c", x);
printf("%d\n", ++x); x = x * 2; x = x + 2;
printf("\n%d ", x++); y = y + 2; } while (x <= 'K');
} while (y < 10);
printf("%d", x);
25. Indicate the errors in the
following code: 58. Write the following
40. Find errors in the following expression in C-language:
C code:
. C
int x = 32; C .
int y = 4; . “The product of ‘A’ and ‘B’ is
printf("%d and %d is %d", x, int A, B; greater than 10”
y, x% y); A=10;
"Weather is greater than 10
and less than 20" 67. Find errors In the following
27. What is the output of the Code:
following code:
43. Convert the following
C
C statement into C-language: .
. int a; b;
int main(void) { C [a=10]
const int pi = 3.1415; . [b=5]
int r = 2; "Weather is greater than 10 printf("%d"; a +b);
printf("%f", pi*r*r); and less than 20"
}
1. Determine the output of the
44. Find the output of the
28. Indicate errors in the following code segment:
following code:
following code: C
C .
C . int x, y, sum;
. x=2; [x=5,y=10]
int x, y; y=3; sum = x + y;
x++; z=4; printf("Sum-%d", Sum);
printf("%d", x+y); printf("Answer=%d", x + y*z);

2. Convert the following loop


29. Predict the output of the 45. Predict the output of the
into a for loop:
following code: following code:
C
.
while(i<=20)
{
printf("%d", i);
i++;
}

5. What is the output of the


following code when a=1000
and b=5000?

C
.
if (a > b)
printf("a is larger");
else
printf("b is larger or
equal");

You might also like