Вы находитесь на странице: 1из 25

http://www.cprogramming.com/tutorial/c/quiz/answer3.

html
1. What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run? A. 10 B. 9 C. 0 D. 1 Note: This quiz question probably generates more email to the webmaster than any other single item on the site. Yes, the answer really is 10. If you don't understand why, think about it this way: what condition has to be true for the loop to stop running? 2. When does the code block following while(x<100) execute? A. When x is less than one hundred B. When x is greater than one hundred C. When x is equal to one hundred D. While it wishes 3. Which is not a loop structure? A. For B. Do while C. While D. Repeat Until 4. How many times is a do while loop guaranteed to loop? A. 0 B. Infinitely C. 1 D. Variable

http://www.indiabix.com/c-programming/control-instructions/008001
1. How many times "IndiaBIX" is get printed?

#include<stdio.h>
int main() { int x; for(x=-1; x<=10; x++) { if(x < 5) continue; else break; printf("IndiaBIX"); } return 0; } A. C. Infinite times 0 times B. D. 11 times 10 times

View Answer C Compiler Report Discuss in Forum 2. How many times the while loop will get executed if a short int is 2 byte wide?

#include<stdio.h>
int main() { int j=1; while(j <= 255) { printf("%c %d\n", j, j); j++; } return 0; } A. C. Infinite times 256 times B. D. 255 times 254 times

View Answer C Compiler Report Discuss in Forum 3.

Which of the following is not logical operator? A. C. & || B. D. && !

View Answer C Compiler Report Discuss in Forum 4.

In mathematics and computer programming, which is the correct order of mathematical operators ?

A. B. C. D.

Addition, Subtraction, Multiplication, Division Division, Multiplication, Addition, Subtraction Multiplication, Addition, Division, Subtraction Addition, Division, Modulus, Subtraction

View Answer C Compiler Report Discuss in Forum 5. Which of the following cannot be checked in a switch-case statement? A. C. Character Float B. D. Integer enum

View Answer C Compiler Report Discuss in Forum

1.

What will be the output of the program?

#include<stdio.h>
int main() { int i=0; for(; i<=5; i++); printf("%d,", i); return 0; } A. C. 0, 1, 2, 3, 4, 5 1, 2, 3, 4 B. D. 5 6

View Answer C Compiler Report Discuss in Forum 2.

What will be the output of the program?

#include<stdio.h>
int main() { char str[]="C-program"; int a = 5; printf(a >10?"Ps\n":"%s\n", str); return 0; } A. C. C-program Error B. D. Ps None of above

View Answer C Compiler Report Discuss in Forum 3.

What will be the output of the program?

#include<stdio.h>
int main() { int a = 500, b = 100, c; if(!a >= 400) b = 300; c = 200; printf("b = %d c = %d\n", b, c); return 0; } A. C. b = 300 c = 200 b = 300 c = garbage B. D. b = 100 c = garbage b = 100 c = 200

View Answer C Compiler Report Discuss in Forum

4.

What will be the output of the program?

#include<stdio.h>
int main() { unsigned int i = 65535; /* Assume 2 byte integer*/ while(i++ != 0) printf("%d",++i); printf("\n"); return 0; } A. B. C. D. Infinite loop 0 1 2 ... 65535 0 1 2 ... 32767 - 32766 -32765 -1 0 No output

View Answer C Compiler Report Discuss in Forum 5.

What will be the output of the program?

#include<stdio.h>
int main() { int x = 3; float y = 3.0; if(x == y) printf("x and y are equal"); else printf("x and y are not equal"); return 0; } A. C. x and y are equal Unpredictable B. D. x and y are not equal No output

View Answer C Compiler Report Discuss in Forum 6. What will be the output of the program, if a short int is 2 bytes wide?

#include<stdio.h>
int main() { short int i = 0; for(i<=5 && i>=-1; ++i; i>0) printf("%u,", i); return 0; }

A. C.

1 ... 65535 No output

B. D.

Expression syntax error 0, 1, 2, 3, 4, 5

View Answer C Compiler Report Discuss in Forum 7.

What will be the output of the program?

#include<stdio.h>
int main() { char ch; if(ch = printf("")) printf("It matters\n"); else printf("It doesn't matters\n"); return 0; } A. C. It matters matters B. D. It doesn't matters No output

View Answer C Compiler Report Discuss in Forum 8.

What will be the output of the program?

#include<stdio.h>
int main() { unsigned int i = 65536; /* Assume 2 byte integer*/ while(i != 0) printf("%d",++i); printf("\n"); return 0; } A. B. C. D. Infinite loop 0 1 2 ... 65535 0 1 2 ... 32767 - 32766 -32765 -1 0 No output

View Answer C Compiler Report Discuss in Forum 9.

What will be the output of the program?

#include<stdio.h>
int main() {

float a = 0.7; if(0.7 > a) printf("Hi\n"); else printf("Hello\n"); return 0; } A. C. Hi Hi Hello B. D. Hello None of above

View Answer C Compiler Report Discuss in Forum 10. What will be the output of the program?

#include<stdio.h>
int main() { int a=0, b=1, c=3; *((a) ? &b : &a) = a ? b : c; printf("%d, %d, %d\n", a, b, c); return 0; } A. C. 0, 1, 3 3, 1, 3 B. D. 1, 2, 3 1, 3, 1

View Answer C Compiler Report Discuss in Forum 11. What will be the output of the program?

#include<stdio.h>
int main() { int k, num = 30; k = (num < 10) ? 100 : 200; printf("%d\n", num); return 0; } A. C. 200 100 B. D. 30 500

View Answer C Compiler Report Discuss in Forum 12. What will be the output of the program?

#include<stdio.h>
int main() { int a = 300, b, c; if(a >= 400)

b = 300; c = 200; printf("%d, %d, %d\n", a, b, c); return 0; } A. C. 300, 300, 200 300, Garbage, 200 B. D. Garbage, 300, 200 300, 300, Garbage

View Answer C Compiler Report Discuss in Forum 13. What will be the output of the program?

#include<stdio.h>
int main() { int x=1, y=1; for(; y; printf("%d %d\n", x, y)) { y = x++ <= 5; } printf("\n"); return 0; } 2 3 4 5 6 7 2 3 4 5 1 1 1 1 1 0 1 1 1 1

A.

B.

2 3 4 5 6

1 1 1 1 1

C.

D.

2 3 4 5

2 3 4 5

View Answer C Compiler Report Discuss in Forum 14. What will be the output of the program?

#include<stdio.h>
int main() { int i = 5; while(i-- >= 0) printf("%d,", i); i = 5; printf("\n"); while(i-- >= 0) printf("%i,", i); while(i-- >= 0) printf("%d,", i); return 0; }

A.

4, 3, 2, 1, 0, -1 4, 3, 2, 1, 0, -1

B.

5, 4, 3, 2, 1, 0 5, 4, 3, 2, 1, 0 5, 4, 3, 2, 1, 0 5, 4, 3, 2, 1, 0 5, 4, 3, 2, 1, 0

C.

Error

D.

View Answer C Compiler Report Discuss in Forum 15. What will be the output of the program?

#include<stdio.h>
int main() { int i=3; switch(i) { case 1: printf("Hello\n"); case 2: printf("Hi\n"); case 3: continue; default: printf("Bye\n"); } return 0; } A. C. Error: Misplaced continue No output B. D. Bye Hello Hi

View Answer C Compiler Report Discuss in Forum 16. What will be the output of the program?

#include<stdio.h>
int main() { int x = 10, y = 20; if(!(!x) && x) printf("x = %d\n", x); else printf("y = %d\n", y); return 0; } A. C. y =20 x = 10 B. D. x=0 x=1

View Answer C Compiler Report Discuss in Forum 17. What will be the output of the program?

#include<stdio.h>
int main() { int i=4; switch(i) { default: printf("This case 1: printf("This break; case 2: printf("This break; case 3: printf("This } return 0; } This is default This is case 1 This is case 1 This is case 3

is default\n"); is case 1\n"); is case 2\n"); is case 3\n");

A.

B.

This is case 3 This is default

C.

D.

This is default

View Answer C Compiler Report Discuss in Forum 18. What will be the output of the program?

#include<stdio.h>
int main() { int i = 1; switch(i) { printf("Hello\n"); case 1: printf("Hi\n"); break; case 2: printf("\nBye\n"); break; } return 0; } Hello Hi Hi Hello Bye Bye

A.

B.

C.

D.

View Answer C Compiler Report Discuss in Forum 19. What will be the output of the program?

#include<stdio.h>

int main() { char j=1; while(j < 5) { printf("%d, ", j); j = j+1; } printf("\n"); return 0; } A. B. C. D. 1 2 3 ... 127 1 2 3 ... 255 1 2 3 ... 127 128 0 1 2 3 ... infinite times 1, 2, 3, 4

View Answer C Compiler Report Discuss in Forum 20. What will be the output of the program?

#include<stdio.h>
int main() { int x, y, z; x=y=z=1; z = ++x || ++y && ++z; printf("x=%d, y=%d, z=%d\n", x, y, z); return 0; } A. C. x=2, y=1, z=1 x=2, y=2, z=2 B. D. x=2, y=2, z=1 x=1, y=2, z=1

View Answer C Compiler Report Discuss in Forum

Point out errors


1. Point out the error, if any in the for loop.

#include<stdio.h>
int main() { int i=1; for(;;) { printf("%d\n", i++); if(i>10) break; } return 0; } A. B. C. D. There should be a condition in the for loop The two semicolons should be dropped The for loop should be replaced with while loop. No error

View Answer C Compiler Report Discuss in Forum 2. Point out the error, if any in the program.

#include<stdio.h>
int main() { int a = 10; switch(a) { } printf("This is c program."); return 0; } A. B. C. D. Error: No case statement specified Error: No default specified No Error Error: infinite loop occurs

View Answer C Compiler Report Discuss in Forum 3.

Point out the error, if any in the program.

#include<stdio.h>
int main()

{ int i = 1; switch(i) { printf("This is c program."); case 1: printf("Case1"); break; case 2: printf("Case2"); break; } return 0; } A. B. C. D. Error: No default specified Error: Invalid printf statement after switch statement No Error and prints "Case1" None of above

View Answer C Compiler Report Discuss in Forum 4. Point out the error, if any in the while loop.

#include<stdio.h>
int main() { int i=1; while() { printf("%d\n", i++); if(i>10) break; } return 0; } A. B. C. D. There should be a condition in the while loop There should be at least a semicolon in the while The while loop should be replaced with for loop. No error

View Answer C Compiler Report Discuss in Forum 5.

Which of the following errors would be reported by the compiler on compiling the program given below?

#include<stdio.h>

int main() { int a = 5; switch(a) { case 1: printf("First"); case 2: printf("Second"); case 3 + 2: printf("Third"); case 5: printf("Final"); break; } return 0; } A. B. C. D. There is no break statement in each case. Expression as in case 3 + 2 is not allowed. Duplicate case case 5: No error will be reported.

View Answer C Compiler Report Discuss in Forum 6. Point out the error, if any in the program.

#include<stdio.h>
int main() { int P = 10; switch(P) { case 10: printf("Case 1"); case 20: printf("Case 2"); break; case P: printf("Case 2"); break; } return 0; } A. B. C. Error: No default value is specified Error: Constant expression required at line case P: Error: There is no break statement in each case.

D.

No error will be reported.

View Answer C Compiler Report Discuss in Forum 7.

Point out the error, if any in the program.

#include<stdio.h>
int main() { int i = 1; switch(i) { case 1: printf("Case1"); break; case 1*2+4: printf("Case2"); break; } return 0; } A. B. C. D. Error: in case 1*2+4 statement Error: No default specified Error: in switch statement No Error

View Answer C Compiler Report Discuss in Forum 8. Point out the error, if any in the while loop.

#include<stdio.h>
int main() { void fun(); int i = 1; while(i <= 5) { printf("%d\n", i); if(i>2) goto here; } return 0; } void fun() { here: printf("It works"); } A. No Error: prints "It works"

B. C. D.

Error: fun() cannot be accessed Error: goto cannot takeover control to other function No error

View Answer C Compiler Report Discuss in Forum 9.

Point out the error, if any in the program.

#include<stdio.h>
int main() { int a = 10, b; a >=5 ? b=100: b=200; printf("%d\n", b); return 0; } A. C. 100 Error: L value required for b B. D. 200 Garbage value

View Answer C Compiler Report Discuss in Forum

Point out correct statements


1. Which of the following statements are correct about the below program?

#include<stdio.h>
int main() { int i = 10, j = 20; if(i = 5) && if(j = 10) printf("Have a nice day"); return 0; } A. B. C. D. Output: Have a nice day No output Error: Expression syntax Error: Undeclared identifier if

View Answer C Compiler Report Discuss in Forum 2.

Which of the following statements are correct about the below program?

#include<stdio.h>
int main() { int i = 10, j = 15; if(i % 2 = j % 3) printf("IndiaBIX\n"); return 0; } A. C. Error: Expression syntax Error: Rvalue required B. D. Error: Lvalue required The Code runs successfully

View Answer C Compiler Report Discuss in Forum 3.

Which of the following statements are correct about the program?

#include<stdio.h>
int main() { int x = 30, y = 40; if(x == y) printf("x is equal to y\n"); else if(x > y) printf("x is greater than y\n"); else if(x < y) printf("x is less than y\n")

return 0; } A. C. Error: Statement missing Error: Lvalue required B. D. Error: Expression syntax Error: Rvalue required

View Answer C Compiler Report Discuss in Forum 4. Which of the following statements are correct about an if-else statements in a C-program? 1: Every if-else statement can be replaced by an equivalent statements using ?: operators 2: Nested if-else statements are allowed. 3: Multiple statements in an if block are allowed. 4: Multiple statements in an else block are allowed. A. C. 1 and 2 1, 2 and 4 B. D. 2 and 3 2, 3, 4

View Answer C Compiler Report Discuss in Forum 5.

Which of the following statements are correct about the below program?

#include<stdio.h>
int main() { int i = 0; i++; if(i <= 5) { printf("IndiaBIX\n"); exit(0); main(); } return 0; } A. B. C. D. The program prints 'IndiaBIX' 5 times The program prints 'IndiaBIX' one time The call to main() after exit() doesn't materialize. The compiler reports an error since main() cannot call itself.

View Answer C Compiler Report Discuss in Forum 6. Which of the following statements are correct about the below C-program?

#include<stdio.h>

int main() { int x = 10, y = 100%90, i; for(i=1; i<10; i++) if(x != y); printf("x = %d y = %d\n", x, y); return 0; } 1 : The printf() function is called 10 times. 2 : The program will produce the output x = 10 y = 10 3 : The ; after the if(x!=y) will NOT produce an error. 4 : The program will not produce output. A. C. 1 3, 4 B. D. 2, 3 4

View Answer C Compiler Report Discuss in Forum 7. Which of the following sentences are correct about a for loop in a C program? 1: for loop works faster than a while loop. 2: All things that can be done using a for loop can also be done using a whileloop. 3: for(;;); implements an infinite loop. 4: for loop can be used if we want statements in a loop get executed at least once. A. C. 1 2, 3 B. D. 1, 2 2, 3, 4

View Answer C Compiler Report Discuss in Forum 8.

Which of the following statements are correct about the below program?

#include<stdio.h>
int main() { int n = 0, y = 1; y == 1 ? n=0 : n=1; if(n) printf("Yes\n"); else printf("No\n"); return 0; } A. B. Error: Declaration terminated incorrectly Error: Syntax error

C. D.

Error: Lvalue required None of above

View Answer C Compiler Report Discuss in Forum 9. Which of the following sentences are correct about a switch loop in a C program? 1: switch is useful when we wish to check the value of variable against a particular set of values. 2: switch is useful when we wish to check whether a value falls in different ranges. 3: Compiler implements a jump table for cases used in switch. 4: It is not necessary to use a break in every switch statement. A. C. 1,2 2,4 B. D. 1,3,4 2

View Answer C Compiler Report Discuss in Forum

Write a C program to find larger number between two numbers entered by user.

#include <stdio.h> int main(){ float a,b; printf("Enter two numbers: "); scanf("%f%f",&a,&b); if (a>b) printf("%.2f is larger.",a); else printf("%.2f is larger.",b); return 0; }

Write a C program to find larger integer among 4 integers entered by user

#include <stdio.h> int main(){ int a,b,c,d; printf("Enter 4 integers: "); scanf("%d%d%d%d",&a,&b,&c,&d); if (a>b && a>c && a>d) printf("%d is largest integer.",a); else if (b>a && b>c && b>d) printf("%d is larger integer.",b); else if (c>a && c>b && c>d) printf("%d is larger integer.",c); else printf("%d is largest integer.",d); return 0; }

Write a C program to make a simple calculator using switch...case statements.

#include <stdio.h> int main(){ char operator; float num1,num2; printf("Enter operator +, - , * or / :\n"); operator=getche(); printf("\nEnter two operands:\n"); scanf("%f%f",&num1,&num2); switch(operator) { case '+': printf("num1+num2=%.2f",num1+num2); break; case '-': printf("num1-num2=%.2f",num1-num2); break; case '*': printf("num1*num2=%.2f",num1*num2);

break; case '/': printf("num2/num1=%.2f",num1/num2); break; default: printf(Error! operator is not correct"); break; } return 0; }

Write a C program to check whether a number entered by user is prime or not.

#include <stdio.h> int main() { int num,i,flag=0; printf("Enter number to check whether it is prime or not\n"); scanf("%d",&num); for(i=2;i<=(num/2);++i){ if((num%i)==0){ printf("%d in not prime.",num); flag=1; break; } } if(flag==0) printf("%d is prime.",num); return 0; }

Write a C program to check whether a number is Armstrong number of not.

#include <stdio.h> int main(){ int num,i,sum=0,remain,temp; printf("Enter a number to check: "); scanf("%d",&num); temp=num; while(num!=0){ remain=(num%10); sum+=remain*remain*remain; num=num/10; } if(sum==temp) printf("%d is Armstrong\n",temp); else printf("%d is not Armstrong\n",temp); return 0;

Write a C program to print the multiple of a number, where number is entered by a user.(Find multiple upto 10)

#include <stdio.h> int main() { int num,i; printf("Enter a number to find multiple.\n"); scanf("%d",&num); for(i=1;i<=10;++i){ printf("%d*%d=%d\n",num,i,num*i); } return 0; }

Write a C program to display the characters from A to Z using loops. (Assume, you don't know the ASCII value of alphabets.)

#include <stdio.h> int main() { int c; for(c='A';c<='Z';++c) printf("%c ",c); return 0; }

Write a C program to display all the prime numbers between two numbers entered by a user.

#include <stdio.h> int main() { int n1,n2,temp,i,j,flag; printf("Enter two numbers\n"); scanf("%d%d",&n1,&n2); if(n1>n2){ temp=n1; n1=n2; n2=temp; } printf("List of prime numbers between %d and %d are:\n",n1,n2); for(i=n1+1;i<n2;++i){ flag=0; for(j=2;j<=i/2;++j){ if(i%j==0){ flag=1;

break; } } if(flag==0) printf("%d ",i); } return 0; }

Write a C program to display a Pascal's triangle using loops.

1 1 1 1 1 4 3 6 2 3 4 1 1 1 1

#include <stdio.h> int main() { int c,i,j,k,h; printf("Enter the vertical height of Pascal's triangle"); scanf("%d",&h); for(i=0;i<h;i++) { c=1; for(j=1;j<=2*(h-1-i);j++) printf(" "); for(k=0;k<=i;k++) { printf("%3d ", c); c=c*(i-k)/(k+1); } printf("\n"); } return 0; }

Write a C program to check for, whether a number is a prime number or Armstrong number or lies on Fibonacci sequence according to instruction from user using switch...case statement.

#include <stdio.h> int main(){ char check; int i, flag, num,temp,sum=0; printf("Enter number: "); scanf("%d",&num); printf("-----------------------Instructions--------\n"); printf("Enter 'a' to check for Armstrong number.\n"); printf("Enter 'p' to check for prime number.\n"); printf("Enter 'f' to check for Fibonacci sequence.\n"); printf("------------------------------------------\n"); printf("Enter a character according to instruction specified: ");

check=getche(); switch(check) { case 'a': temp=num; while(num!=0){ sum+=(num%10)*(num%10)*(num%10); num=num/10; } if(sum==temp) printf("\n\nResult: %d is Armstrong\n",temp); else printf("\n\nResult: %d is not Armstrong\n",temp); break; case 'p': flag=0; for(i=2;i<=(num/2);++i){ if((num%i)==0){ printf("\n\nResult: %d in not prime.",num); flag=1; break; } } if(flag==0) printf("\n\nResult: %d is prime.",num); break; case 'f': i=0,flag=1; while(flag<=num) { if (flag==num){ printf("\n\nResult: %d lies in Fibonacci.",num); break; } temp=flag; flag+=i; i=temp; } if (flag!=num) printf("\n\nResult: %d does not lies in Fibonacci.",num); break; default: printf("Error! "); break; } return 0; }

Вам также может понравиться