Sunteți pe pagina 1din 11

C programming questions and answer

C ,C++, Advance C Search Engine Java, Reasoning, Aptitude, Ebooks Search Engine Looping questions in c and answers Looping questions in c and answers

(1) What will be output of following c code? #include<stdio.h> extern int x; int main(){ do{ do{ printf("%o",x); } while(!-2); } while(0); return 0; } int x=8;

Explanation (2) What will be output of following c code? #include<stdio.h> int main(){ int i=2,j=2; while(i+1?--i:j++) printf("%d",i); return 0; }

Explanation (3) What will be output of following c code? #include<stdio.h> int main(){

int x=011,i; for(i=0;i<x;i+=3){ printf("Start "); continue; printf("End"); } return 0; }

Explanation

(4)What will be output of following c code?

#include<stdio.h> int main(){ int i,j; i=j=2,3; while(--i&&j++) printf("%d %d",i,j); return 0; }

Explanation

(5)What will be output of following c code?

#include<stdio.h> int main(){ static int i; for(++i;++i;++i) { printf("%d ",i); if(i==4) break; }

return 0; }

Explanation (6)What will be output of following c code? #include<stdio.h> int main(){ int i=1; for(i=0;i=-1;i=1) { printf("%d ",i); if(i!=1) break; } return 0; }

Explanation (7)What will be output of following c code? #include<stdio.h> int main(){ for(;;) { printf("%d ",10); } return 0; }

Explanation (8)What will be output of following c code? #include<stdio.h> int r(); int main(){ for(r();r();r()) { printf("%d ",r()); } return 0; } int r(){ int static num=7; return num--; }

Explanation

(9)What will be output of following c code? #include<stdio.h> #define p(a,b) a##b #define call(x) #x int main(){ do{ int i=15,j=3; printf("%d",p(i-+,+j)); } while(*(call(625)+3)); return 0; }

Explanation (10) #include<stdio.h> int main(){ int i; for(i=0;i<=5;i++); printf("%d",i) return 0; }

Explanation (11)What will be output of following c code? #include<stdio.h> int i=40; extern int i; int main(){ do{ printf("%d",i++); } while(5,4,3,2,1,0); return 0; }

Explanation (12)What will be output of following c code? #include<stdio.h> char _x_(int,...); int main(){

char (*p)(int,...)=&_x_; for(;(*p)(0,1,2,3,4); ) printf("%d",!+2); return 0; } char _x_(int a,...){ static i=-1; return i+++a; }

Explanation (13)What will be output of following c code? #include<stdio.h> int main(){ int i; for(i=10;i<=15;i++){ while(i){ do{ printf("%d ",1); if(i>>1) continue; }while(0); break; } } return 0; }

Explanation (14)How many times this loop will execute? #include<stdio.h> int main(){ char c=125; do printf("%d ",c); while(c++); return 0; }

Explanation (15)What will be output of following c code? #include<stdio.h> int main(){ int x=123; int i={

printf("c" "++") }; for(x=0;x<=i;x++){ printf("%x ",x); } return 0; }

Explanation

13 comments: Subhash Razput said... WAP to find out the factorial of a number greater then 25 by using A)for loop b) while loop??????? 1/27/10 6:44 PM Anonymous said... very nice questions on looping 4/4/10 12:22 PM asif islam hnd said... very good questions 4/18/10 11:02 PM hasan said... explanation should be implemented here for our understanding................beca use it's so difficult to understan 6/1/10 12:44 AM MD.MOSTAFIZUR RAHMAN said... VERY TRICKY && LOGICAL QUESTIONS....DIFFICULT TO SOLVE 6/14/10 2:19 AM vamshidhar said... write a program to find out the highest 4 numbers with one single iteration with out sorting the list? Please give the code for the above question 7/7/10 11:30 PM Ritesh kumar said... Hi Vamshidher your question is : write a program to find out the highest 4 numbers with one si ngle iteration without sorting the list? Answer: Solution 1: #include"stdio.h" int main(){ int m; int a,b,c,d; //Enter any five integer numbers printf("Enter any five integer : ");

scanf("%d%d%d%d",&a,&b,&c,&d); //finding the max of all four numbers if(a>b && a>c && a>d) m = a; else if(b>c && b>d) m = b; else if(c>d) m = c; else m = d; //printing the max of all four numbers printf("\nMax of all four numbers : %d",m); return 0; } Solution 2: #include"stdio.h" int max(int,int); int main(){ int m; int a,b,c,d; //Enter any five integer numbers printf("Enter any five integer : "); scanf("%d%d%d%d",&a,&b,&c,&d); //finding the max of all four numbers m = max(a,max(b,max(c,d))); //printing the max of all four numbers printf("\nMax of all four numbers : %d",m); return 0; } //finding the max of two numbers int max(int x,int y){ return x>y?x:y; } Solution 3: #include"stdio.h" int main(){ int m; int a,b,c,d; //Enter any five integer numbers printf("Enter any five integer : "); scanf("%d%d%d%d",&a,&b,&c,&d); //finding the max of all four numbers m = ((a>b?a:b)>c?(a>b?a:b):c)>d?((a>b?a:b)>c?(a>b?a:b):c):d; //printing the max of all four numbers printf("\nMax of all four numbers : %d",m);

return 0; } 7/8/10 9:33 AM Tarun said... write a program to print using for loop 1 23 456 78910 7/14/10 11:55 AM Ritesh kumar said... Hi Tarun, Your question is: write a program to print using for loop 1 23 456 78910 Answer: #include"stdio.h" int main(){ int i,x=1,y=1; for(i=1;i<=10;i++){ printf("%d",i); if(x==i){ printf("\n"); x = x + ++y;; } } return 0; } 7/15/10 8:54 AM Anonymous said... @ tarun.....very easy question dude....define an array of 1-10....then use two f or loops...one within other...one to control the number of elements in a line an d other to move to new line... :) 8/5/10 12:19 PM vipnip said... very nice and correct question perfect mix of hardwork and talent .....good work god bless.. 8/10/10 1:18 PM Anonymous said... write a program to find series solution as 1-x+x*x/2!+x*x*x/3!+...... 8/19/10 5:40 PM Anonymous said... find lcm of 12 and 18 as 2*3*2*3 8/19/10 5:42 PM

Post a Comment

Newer Post Older Post Home Subscribe to: Post Comments (Atom) C Questions & Explanation Big index of c questions C program examples Data type questions Variable naming rule questions Operators questions Control flow questions Switch case questions Looping questions Pointer questions More pointer questions Array questions String questions Function questions Printf,Scanf questions Preprocessor questions Structure questions Union questions File handling questions Commad line argument C questions in Linux C interview questions C online test C mixed practice sets

C tricky questions Good c questions C example code c examples with code C Interview Questions & Answer C interview questions Data type inteview questions Storage class interview questions String interview questions Pointer interview questions C Language Tutorials Memory map tutorial Data type tutorial Variable tutorial Storage class tutorial Operator tutorial Control flow tutorial Looping tutorial Array tutorial String tutorial Pointer tutorial Function tutorial Preprocessor tutorial Structure tutorial Union tutorial File handling tutorial Command line argument in c Advance c tutorial Other Topics Preparation of placement for fresher Java questions with solution

Sql questions with solution Advance java tutorial Download free ebooks Download PC softwares Share this tutorial at Subscribe To Posts Comments Standard of questions ? C Questions and Explanation Pages Home C lover community

Copyright@ritesh kumar. Picture Window template by Josh Peterson. Powered by Blo gger.

S-ar putea să vă placă și