CQuestions

  • Upload
    mahesh

  • View
    805

  • Download
    5

Embed Size (px)

Citation preview

[Q001] What will be the output of the following program : int main() { printf(); return(0); } (a)Run-Time Error (b)Compile-Time Error (c)No Output (d)None of these [Q002] What will be the output of the following program : int main() { printf(NULL); return(0); } (a)Run-Time Error (b)Compile-Time Error (c)No Output (d)None of these [Q003] What will be the output of the following program : int main() { printf("%%",7); return(0); } (a)7 (b)Compile-Time Error (c) % (d)%% ans:: c [Q004] What will be the output of the following program : int main() { printf("//",5); return(0); } (a)5 (b)Compile-Time Error (c)/ (d)// [Q005] What will be the output of the following program : int main() { printf("d%",8); return(0); } (a)8 (b)Compile-Time Error (c)d% (d)None of these

ans:: d

ans :: c

[Q006] What will be the output of the following program : int main() { printf("%d"+0,123); return(0); } (a)123(b)Compile-Time Error (c)No Output (d)None of these ans:: a

[Q007] What will be the output of the following program : int main() {

printf("%d"+1,123); return(0); } (a)123 (b)Compile-Time Error (c)d (d)No Output

ans:: c

[Q008] What will be the output of the following program : int main() { printf("%d",printf("Hi!")+printf("Bye")); return(0); } (a)ByeHi!6 (b)Hi!Bye6(c)Compile-Time Error (d)None of these ans:: b

[Q009] What will be the output of the following program : int main() { printf("%d",printf("Hi!")*printf("Bye")); return(0); } (a)ByeHi!6 (b)Hi!Bye9(c)Hi!Bye (d)None of these ans:: b

[Q010] What will be the output of the following program : int main() { printf("%d",printf("")+printf("")); return(0); }(a)0(b)No Output(c)Compile-Time Error(d)None of these

ans::a

[Q011] What will be the output of the following program : int main() { printf("Hi Friends"+3); return(0); } (a)Hi Friends (b)Friends (c)Hi Friends3(d)None of these ans:: b

[Q012] What will be the output of the following program : int main() { printf("C For ") + printf("Swimmers"); return(0); } (a)Compile-Time Error(b)C For Swimmers(c)Run-Time Error (d)None of these ans:: b

[Q013] What will be the output of the following program : int main() { printf("\/\*\-*\/"); return(0); } (a)Run-Time Error (b)\/*-*\/ (c)/*-*/(d)None of these ans:: c

[Q014] What will be the output of the following program : int main() { int main=7; { printf("%d",main); return main; } printf("Bye"); return(0); } (a)Compile-Time Error(b)Run-Time Error(c)7Bye (d)7 ans:: d

[Q015] What will be the output of the following program : int main() { main(); return(0); } ans:: c (a)Compile-Time Error(b)Run-Time Error(c)Infinite Loop(d)None of these

[Q016] What will be the output of the following program : int main() { printf("Work" "Hard"); return(0); } (a)Work (b)Hard (c)No Output (d)WorkHard

ans:: d

[Q017] What will be the output of the following program : int main() { char str[]="%d"; int val=25; printf(str,val); return(0); }a)Compile-Time Error(b)Run-Time Error(c)25 d)None of these ans:: c

[Q018] What will be the output of the following program : int main() { int val=75; printf("%d",val,.,.); return(0); }(a)Compile-Time Error(b)Unpredictable(c)75(d)None of these ans:: d

[Q019] What will be the output of the following program : int main() { int val=10; printf("%d",val+1,"%d",val--); return(0); } (a)10 (b)11 10 (c)11 9 (d)10 9

ans:: a

[Q020] What will be the output of the following program : int main() { int val=5; printf("%d %d %d %d",val,--val,++val,val--); return(0); } (a)3 4 6 5 (b)5 5 6 5 (c)4 4 5 5 (d)None of these ans:: c

[Q021] What will be the output of the following program [NOTE : ASSUME 2 values are entered by the user are stored in the variables 'val' & 'num' respectively] : int main() { int val=5,num; printf("%d",scanf("%d %d",&val,&num)); return(0); } (a)1 (b)2 (c)5 (d)None of these ans:: b

[Q022] What will be the output of the following program : #define Compute(x,y,z) (x+y-z) int main() { int x=2,y=3,z=4; printf("%d",Compute(y,z,(-x+y)) * Compute(z,x,(-y+z))); return(0); } (a)40 (b)30 (c)Compile-Time Error (d)None of these

ans:: b

[Q023] What will be the output of the following program : int main() { int m=10,n=20; printf("%d %d %d",m/* m-value */,/* n-value */n,m*/* Compute m*n */n); return(0); } ans:: b (a)Run-Time Error (b)10 20 200 (c)Compile-Time Error (d)None of these

[Q024] What will be the output of the following program : int main() { int m=10,n=20; /* printf("%d",m*n); return(0); } (a)VALID but No Output (b)VALID : Prints 200 (c)Compile-Time Error (d)None of these

ans:: c

[Q025] What will be the output of the following program : int main() { int val=97; "Printing..."+printf("%c",val); return(0); } (a)Printing...97 (b)97 (c)Compile-Time Error(d)a ans:: d

[Q026] What will be the output of the following program : int main() { int val=5; val=printf("C") + printf("Skills"); printf("%d",val); return(0); } (a)Skills5 (b)C1 (c)Compile-Time Error(d)CSkills7 ans :: d

[Q027] What will be the output of the following program : int main() { char str[]="Test"; if ((printf("%s",str)) == 4) printf("Success"); else

printf("Failure"); return(0); } a)TestFailure b)TestSuccess c)Compile-Time Error(d)Test ans:: b

[Q028] What will be the output of the following program : int main() { int val=5; printf("%*d",val); return(0); } (a)bbbbb5 (where b means blankspace) (b)5 (c)Compile-Time Error (d)None of these

ans:: a

[Q029] What will be the output of the following program : int main() { int val=5; printf("%d5",val); return(0); } ans:: c (a)Compile-Time Error (b)5 (c)55 (d)bbbbb5 (where b means blankspace)

[Q030] What will be the output of the following program : int main(){ int val=5; printf("%d",5+val++); return(0);} (a)Compile-Time Error (b)5 (c)10 (d)11 ans::c

[Q001] Determine which of the following are VALID identifiers. If invalid, state the reason. (a) sample1 (b) 5sample (c) data_7 (d) return (e) #fine (f) variable (g) 91-080-100 (h) name & age (i) _val (j) name_and_age

[Q002] Determine which of the following are VALID character constants. If invalid, state the reason. (a) 'y' (b) '\r' (c) 'Y' (d) '@' (e) '/r' (f) 'word' (g) '\0'

(h) '\?' (i) '\065' (j) '\'' (k) ' '

[Q003] Determine which of the following are VALID string constants. If invalid, state the reason. (a) 'Hi Friends' (b) "abc,def,ghi" (c) "Qualification (d) "4325.76e8" (e) "Don\'t sleep" (f) "He said, "You\'re great" (g) "" (h) " " (i) "Rs.100/-"

[Q004] Determine which of the following numerical values are valid constants. If a constant is valid, specify whether it is integer or real. Also, specify the base for each valid integer constant. (a) 10,500 (b) 080 (c) 0.007 (d) 5.6e7 (e) 5.6e-7 (f) 0.2e-0.3 (g) 0.2e 0.3 (h) 0xaf9s82 (i) 0XABCDEFL (j) 0369CF (k) 87654321l (l) 87654321

[Q005] Determine which of the following floating-point constants are VALID for the quantity (5 * 100000). (a) 500000 (b) 0.5e6 (c) 5E5 (d) 5e5 (e) 5e+5 (f) 500E3 (g) .5E6 (h) 50e4 (i) 50.E+4 (j) 5.0E+5 (k) All of the above (l) None of these

[Q006] What will be the output of the following program : int main() { printf("%f",123.); return(0); } (a)123 (b)Compile-Time Error (c)123.00 (d)123.000000 ans:: d

[Q007] What will be the output of the following program : int main() { printf("%d",sizeof(integer)); return(0); } (a)2 (b)Compile-Time Error(c)4 (d)None of these

ans:: b

[Q008] What will be the output of the following program : int main() { char str[]="C For Swimmers"; printf("%d",sizeof str);

return(0); } (a)14 (b)Compile-Time Error (c)15(d)None of these ans:: b

[Q009] What will be the output of the following program : int main() { char str[]="C For Swimmers"; printf("%d",++(sizeof(str))); return(0); } (a)14 (b)Compile-Time Error (c)15 (d)None of these ans:: b

[Q010] What will be the output of the following program : int main() { char str[]="C For Swimmers"; printf("%d",-sizeof(str)); return(0); } (a)14 (b)Compile-Time Error (c)-15 (d)-14 ans:: c

[Q011] What will be the output of the following program : int main() { printf("%d",!(100==100)+1); return(0); } (a)100 (b)0 (c)1 (d)2 ans:: c

[Q012] What will be the output of the following program : int main() { int x=5,y=6,z=2; z/=y/z==3?y/z:x*y; printf("%d",z); return(0); } (a)Compile-Time Error (b)2 (c)0 (d)1

[Q013] What will be the output of the following program : int main() { printf("%d %d %d",5,!5,25-!25); return(0); } (a)5 10 22 (b)5 5 25 (c)5 0 25 (d)5 1 24

[Q014] What will be the output of the following program : int main() { int a=500,b=100,c=30,d=40,e=19; a+=b-=c*=d/=e%=5; printf("%d %d %d %d %d",a,b,c,d,e); return(0); } (a)500 100 30 40 4 b)Run-Time Error c)700 200 300 10 4 d)300 -200 300 10 4

[Q015] What will be the output of the following program : int main() { int a=500,b=100,c=30,d=40,e=19; if((((a > b) ? c : d) >= e) && !((e a) && (c > b)) printf("%x",c); return(0); } (a)No Output (b)0xe75f (c)0xefff (d)None of these

[Q010] What will be the output of the following program : int main() { unsigned val=0xabcd; if (val>>16 | val b) printf("%d %d",d,c); else if (c > a) printf("%d %d",c,d); if (c > a) if (b < a) printf("%d %d",c,a); else if (b < c) printf("%d %d",b,c); return(0); } (a)4 3 3 4 (b)4 3 3 2 (c)4 32 3 (d)4 33 1

[Q016] What will be the output of the following program : int main() { int a=1,b=2,c=3,d=4; if (d > c) if (c > b) printf("%d %d",d,c); if (c > a) printf("%d %d",c,d); if (c > a) if (b < a) printf("%d %d",c,a); if (b < c) printf("%d %d",b,c);

return(0); } (a)4 32 3 (b)4 33 42 3 (c)4 3 3 4 2 3 (d)None of these

[Q017] What will be the output of the following program : int main() { int a=1; if (a == 2); printf("C Program"); return(0); } (a)No Output (b)C Program (c)Compile-Time Error

[Q018] What will be the output of the following program : int main() { int a=1; if (a) printf("Test"); else; printf("Again"); return(0); } a)Again (b)Test (c)Compile-Time Error (d)TestAgain

[Q019] What will be the output of the following program : int main() { int i=1; for (; ii=x; ptr->f=y; } int main() { temp a={111,777.007}; printf("%d %.2f\n",a.i,a.f); alter(&a,222,666.006); printf("%d %.2f",a.i,a.f); return(0); } (a)Compile-Time error (b)111 777.007 222 666.006 (c)111 777.01 222 666.01 (d)None of these

[Q009] What will be the output of the following program : typedef struct { int i; float f; }temp; temp alter(temp tmp,int x,float y) { tmp.i=x; tmp.f=y; return tmp; } int main() { temp a={111,777.007}; printf("%d %.3f\n",a.i,a.f); a=alter(a,222,666.006); printf("%d %.3f",a.i,a.f); return(0); } (a)Compile-Time error (b)111 777.007 222 666.006 (c)111 777.01 222 666.01 (d)None of these

[Q010] What will be the output of the following program :

typedef struct { int i; float f; }temp; temp alter(temp *ptr,int x,float y) { temp tmp=*ptr; printf("%d %.2f\n",tmp.i,tmp.f); tmp.i=x; tmp.f=y; return tmp; } int main() { temp a={65535,777.777}; a=alter(&a,-1,666.666); printf("%d %.2f",a.i,a.f); return(0); } (a)Compile-Time error (b)65535 777.777 -1 666.666 (c)65535 777.78 -1 666.67 (d)-1 777.78 -1 666.67

[Q011] What will be the output of the following program : struct my_struct1 { int arr[2][2]; }; typedef struct my_struct1 record; struct my_struct2 { record temp; }list[2]={1,2,3,4,5,6,7,8}; int main() { int i,j,k; for (i=1; i>=0; i--) for (j=0; j=0; k--) printf("%d",list[i].temp.arr[j][k]); return(0); } (a)Compile-Time Error (b)Run-Time Error (c)65872143 (d)56781243

[Q012] What will be the output of the following program : struct my_struct { int i; unsigned int j; }; int main() { struct my_struct temp1={-32769,-1},temp2; temp2=temp1;

printf("%d %u",temp2.i,temp2.j); return(0); } (a)32767 -1 (b)-32769 -1 (c)-32769 65535 (d)32767 65535 [Q013] What will be the output of the following program : struct names { char str[25]; struct names *next; }; typedef struct names slist; int main() { slist *list,*temp; list=(slist *)malloc(sizeof(slist)); // Dynamic Memory Allocation strcpy(list->str,"Hai"); list->next=NULL; temp=(slist *)malloc(sizeof(slist)); // Dynamic Memory Allocation strcpy(temp->str,"Friends"); temp->next=list; list=temp; while (temp != NULL) { printf("%s",temp->str); temp=temp->next; } return(0); } (a)Compile-Time Error (b)HaiFriends (c)FriendsHai (d)None of these

[Q014] Which of the following declarations is NOT Valid : (i) struct A { int a; struct B { int b; struct B *next; }tempB; struct A *next; }tempA; (ii) struct B { int b; struct B *next; }; struct A { int a; struct B tempB; struct A *next; }; (iii) struct B { int b; }tempB; struct { int a;

struct B *nextB; }; (iv) struct B { int b; struct B { int b; struct B *nextB; }tempB; struct B *nextB; }tempB; a) (iv) Only (b) (iii) Only (c)All of the these (d)None of these

[Q015] What will be the output of the following program : union A { char ch; int i; float f; }tempA; int main() { tempA.ch='A'; tempA.i=777; tempA.f=12345.12345; printf("%d",tempA.i); return(0); } (a)Compile-Time Error (b)12345 (c)Erroneous output (d)777

[Q016] What will be the output of the following program : struct A { int i; float f; union B { char ch; int j; }temp; }temp1; int main() { struct A temp2[5]; printf("%d %d",sizeof temp1,sizeof(temp2)); return(0); } (a)6 30 (b)8 40 (c)9 45 (d)None of these

[Q017] What will be the output of the following program : int main() { static struct my_struct { unsigned a:1; unsigned b:2; unsigned c:3; unsigned d:4; unsigned :6; // Fill out first word }v={1,2,7,12}; printf("%d %d %d %d",v.a,v.b,v.c,v.d); printf("\nSize=%d bytes",sizeof v); return(0); } (a)Compile-Time Error (b)1 2 7 12 Size=2 bytes (c)1 2 7 12 Size=4 bytes (d)None of these

[Q018] What are the largest values that can be assigned to each of the bit fields defined in [Q017] above. (a)a=0 b=2 c=3 d=4 (b)a=1 b=2 c=7 d=15 (c)a=1 b=3 c=7 d=15 (d)None of these

[Q019] What will be the output of the following program : int main() { struct sample { unsigned a:1; unsigned b:4; }v={0,15}; unsigned *vptr=&v.b; printf("%d %d",v.b,*vptr); return(0); } (a)Compile-Time Error (b)0 0 (c)15 15 (d)None of these

[Q020] What will be the output of the following program : int main() { static struct my_struct { unsigned a:1; int i; unsigned b:4; unsigned c:10; }v={1,10000,15,555}; printf("%d %d %d %d",v.i,v.a,v.b,v.c); printf("\nSize=%d bytes",sizeof v); return(0); } (a)Compile-Time Error (b)1 10000 15 555 Size=4 bytes (c)10000 1 15 555 Size=4 bytes (d)10000 1 15 555 Size=5 bytes

Q001] The following code is not well-written. What does the program do ? int main( ){int a=1, b=2,c=3,d=4;printf("%d %d", a,b);printf( " %d %d",c,d); return(0); } (a)Run-Time Error (b)Compile-Time Error (c)1 2 3 4 (d)None of these

[Q002] What will be the output of the following program : int main() { int a=1,b=2,c=3; c=(--a,b++)-c; printf("%d %d %d",a,b,c); return(0); } (a)0 3 -3 (b)Compile-Time Error (c)0 3 -1 (d)0 3 0

[Q003] What will be the output of the following program : int main()

{ int a=1,b=2,c=3,d=4,e; e=(a,a)+(b,c)+(c,d)-(d,b); printf("%d",e); return(0); } (a)Compile-Time Error (b)10 (c)6 (d)2

[Q004] What will be the output of the following program : int main() { float val=2.; printf("%.2",val); return(0); } (a)Compile-Time error (b)2.00 (c)%.2 (d)2.000000

[Q005] What will be the output of the following program : int main() { int a=5; int b=6;; int c=a+b;;; printf("%d",c);;;; return(0); } (a)Compile-Time Error (b)Run-Time Error (c)11 (d)None of these

[Q006] What will be the output of the following program : int main() { int i,j; for (i=1; i b) swap(a,b); printf("a=%d b=%d",a,b); return(0); } (a)a=5 b=6 (b)a=6 b=5 (c)a=6 b=0 (d)None of these

[Q008] What will be the output of the following program : int main() { unsigned int val=5; printf("%u %u",val,val-11); return(0); } (a)Compile-Time error (b)5 -6 (c)5 65530 (d)None of these

[Q009] What will be the output of the following program : int main() { int x=4,y=3,z=2; *&z*=*&x**&y; printf("%d",z); return(0); } (a)Compile-Time error (b)Run-Time Error (c)24 (d)Unpredictable

[Q010] What will be the output of the following program : int main() { int i=5,j=5; i=i++*i++*i++*i++;

printf("i=%d ",i); j=++j*++j*++j*++j; printf("j=%d",j); return(0); } (a)Compile-Time Error (b)i=1680 j=1680 (c)i=629 j=6561 (d)i=1681 j=3024

[Q011] What will be the output of the following program : int main() { int i=5; printf("%d %d %d %d %d",++i,i++,i++,i++,++i); return(0); } a)Compile-Time Error (b)10 9 8 7 6 (c)9 8 7 6 6 (d)10 8 7 6 6

[Q012] What will be the output of the following program : int main() { unsigned ch='Y'; printf("%d",sizeof ch); return(0); } (a)Compile-Time Error (b)2 (c)4 (d)1

[Q013] What will be the output of the following program : int main() { int a=5; printf("%d"); return(0); } (a)Compile-Time Error (b)5 (c)Unpredictable (d)No Output

[Q014] What will be the output of the following program : int main() { int a=5,b=6; printf("%d");

return(0); } (a)Compile-Time Error (b)5 (c)6 (d)Unpredictable

[Q015] What will be the output of the following program : int main() { int a=5,b=6,c=7; printf("%d %d %d"); return(0); } (a)Compile-Time Error (b)5 6 7 (c)7 6 5 (d)Unpredictable

[Q016] What will be the output of the following program : #define Swap if (a != b) { \ temp=a; \ a = b; \ b = temp; \ //Swapping Done } int main() { int a=10,b=5,temp; Swap; printf("a=%d a=%d",a,b); return(0); } (a)Compile-Time Error (b)a=5 b=10 (c)a=10 b=5 (d)None of these

[Q017] What will be the output of the following program : int main() { int val=50; void *ptr; ptr=&val; printf("%d %d",val,*(int *)ptr); return(0); } (a)Compile-Time Error (b)50 50 (c)50 0 (d)None of these

[Q018] What will be the output of the following program : int main() { int a=5,b=6; Printf("%d %d %d",a,b,--a*++b); return(0); } (a)Compile-Time Error (b)5 6 30 (c)4 7 28 (d)None of these

[Q019] What will be the output of the following program : int main() { int val=5; void *ptr; *(int *)ptr=5; val=ptr; printf("%d %d",*(int *)val,*(int *)ptr); return(0); } (a)Compile-Time Error (b)Unpredictable (c)5 5 (d)None of these

[Q020] What will be the output of the following program : int main() { int val=2; val = - --val- val--- --val; printf("%d",val); return(0); } (a)Compile-Time Error (b)3 (c)-1 (d)0

[Q021] What will be the output of the following program : int main() { int i,n=10; for (i=1; i

void Swap(int *a,int *b,int *c) { *a = *a + *b + *c; *b = *a - (*b + *c); *c = *a - (*b + *c); *a = *a - (*b + *c); } int main() { int x=1,y=2,z=3; clrscr(); printf("BEFORE SWAPPING : %d %d %d\n",x,y,z); Swap(&x,&y,&z); printf("AFTER SWAPPING : %d %d %d",x,y,z); return(0); } /* End of Main */

[Q002] W.A.P. in C to find the Fifth root of the sum of the squares of the first 100 ODD numbers only. /* To find the Fifth root of the sum of the squares of the first 100 ODD numbers ONLY */ #include< stdio.h > #include< conio.h > #include< math.h > int main(void) { long i,oddnum=1,sqrnum,sum=0; for (i=1; i int main() { long int i,n,mul,mul2,count,temp,a,b,sum,carry,res,tot;

printf("\nEnter any 2 numbers : "); scanf("%ld %ld",&mul,&n); mul2=temp=mul; for (i=2; i>1; mul2=mul2>>1; tot+=res*sum; res=res*2; } mul2=tot; } printf("\n%3ld * %3ld = %3ld",mul,i-1,tot); getch(); return(0); } /* End of Main */

[Q004] W.A.P. in C to check whether given number x is equal to the value 2 POWER i or something, where i>=0 using BITWISE operators ONLY. [Hint : Check whether the given number x is equal to the value 2 POWER i or something using BITWISE operators ONLY] /* Check whether the given number x is equal to the value 2 power i or not using BITWISE operators ONLY */ #include< stdio.h > #include< conio.h > int main(void) { long x; printf("Enter a number : ");

scanf("%ld",&x); if ((x & 0x1) == 0x0) // Checking the Least significant bit printf("The given number %ld is EQUAL to the value 2 POWER something",x); else printf("The given number %ld is NOT EQUAL to the value 2 POWER something",x); getch(); return(0); } /* End of Main */

[Q005] W.A.P. in C to maintain 2 STACKS within a SINGLE ARRAY and the values of one stack should not overwrite the values of another stack. /* Maintaining TWO STACKS within a SINGLE ARRAY */ #include< stdio.h > #include< conio.h > #define MAX 10 int stack[MAX],top1,top2; void init() { top1=-1; top2=10;} void Push1(int item) { stack[++top1]=item;} void Push2(int item) { stack[--top2]=item;} int Pop1() { return stack[top1--]; } int Pop2() { return stack[top2++];} void Display() { int i; if(top1==-1) printf("\nStack1 : Empty"); else { printf("\nContent of Stack1 :\n"); for(i=0;i=top2;i--) printf("%d\t",stack[i]);

} } int main() { int item,ch; init(); while(1) {printf("\n\n\tMenu\n1.Push1\n2.Push2\n3.Pop1\n4.Pop2\n5.Display\n6.Exit"); printf("\nEnter your choice:"); scanf("%d",&ch); switch(ch) { case 1 : if ((top1 + 1) < top2) { printf("\nEnter item to Push into Stack1:"); scanf("%d",&item); Push1(item); } else printf("\nMemory is Full. Overflow Error"); break; case 2 : if ((top2 - 1) > top1) { printf("\nEnter item to Push into Stack2:"); scanf("%d",&item); Push2(item); } else printf("\nMemory is Full. Overflow Error"); break; case 3 : if(top1 = 10) printf("\nError : Underflow on pop2"); else printf("\nPopped item from stack2 is : %d",Pop2()); break; case 5 : Display(); break; case 6 : exit(0); default: printf("\nInvalid Choice"); } } return(0); } /* End of Main */

[Q006] W.A.P. in C that act as a guessing game in which the user has eight tries to guess a randomly generated number. The program will tell the user each time whether he guessed high or low. The user WINS the game when the number guessed is same as randomly generated number. /* Guessing Game Solution */ #include< stdlib.h > #include< stdio.h > #include< time.h > int main(void) { int i=8,rval,val,flag=1; randomize(); // Initialize the random number generator rval=random (100); // Generates a random number in the range 0 to 99 printf("Welcome to Guessing Game.\n"); printf("RULES:\n1. Only 8 chances to guess the randomly generated number."); printf("\n2. You can WIN the game when the number guessed is same as the"); printf("randomly generated number.\n3. Follow the hints."); printf("\n\n$$$ Good Luck. Start Guessing $$$"); for (i=1; i rval) printf("Your value is GREATER THAN the randomly generated number"); else if (val < rval) printf("Your value is LESSER THAN the randomly generated number"); else { flag=1; break; } } if (flag) printf("\n\n*** You are the WINNER. No. of tries = %d ***",i); else printf("\n\n*** You are the LOSER. ***"); return(0); } /* End of Main */

[Q007] W.A.P. to determine how much money is in a piggy bank that contains several 50 paise coins, 25 paise coins, 20 paise coins, 10 paise coins and 5 paise coins. Use the following values to test your program : Five 50 paise coins, Three 25 paise coins, Two 20 paise coins, One 10 paise coin and Fifteen 5 paise coins. (Answer : Rs. 4.50) /* To determine how much money in a piggy bank */ #include< stdio.h > #include< string.h > #include< conio.h > int main(void) { float coin1=0.50,coin2=0.25,coin3=0.20,coin4=0.10,coin5=0.05,total=0.0; int ncoins; clrscr(); printf("How many 50 paise coins : "); scanf("%d",&ncoins); total += (ncoins * coin1); printf("** %.2f **",total); printf("\nHow many 25 paise coins : "); scanf("%d",&ncoins); total += (ncoins * coin2); printf("** %.2f **",total); printf("\nHow many 20 paise coins : "); scanf("%d",&ncoins); total += (ncoins * coin3); printf("** %.2f **",total); printf("\nHow many 10 paise coins : "); scanf("%d",&ncoins); total += (ncoins * coin4); printf("** %.2f **",total); printf("\nHow many 5 paise coins : "); scanf("%d",&ncoins); total += (ncoins * coin5); printf("\n\nThe total amount is Rs.%.2f",total); getch(); return(0); } /* End of Main */

[Q008] Modify the program given in [Q007] to accept total amount (in rupees) and convert them into paise.(Vice-versa of [Q007])

/* Denominations */ #include< stdio.h > #include< string.h > #include< conio.h > int main(void) { int nc1,nc2,nc3,nc4,nc5,temp; float total; clrscr(); printf("Enter the amount : "); scanf("%f",&total); temp = total * 100; nc1 = temp / 50; temp = temp % 50; nc2 = temp / 25; temp = temp % 25; nc3 = temp / 20; temp = temp % 20; nc4 = temp / 10; temp = temp % 10; nc5=temp; printf("\n\nNo. of 50 paise coins = %d",nc1); printf("\nNo. of 25 paise coins = %d",nc2); printf("\nNo. of 20 paise coins = %d",nc3); printf("\nNo. of 10 paise coins = %d",nc4); printf("\nNo. of 5 paise coins = %d",nc5); getch(); return(0); } /* End of Main */

[Q09] W.A.P. in C to determine how many of the characters are vowels and how many are consonants in a given line of text. Also terminate the string when the input character encountered is other than the alphabets(a-z or A-Z) and Blank spaces. [Hint:(a) When the input string is 'C FOR SWIMMERS, TEST YOUR C PROGRAMMING STRENGTHS'. Consider the string 'C FOR SWIMMERS' only Because ',' is encountered. (b) When the input string is 'Y2K PROBLEM'. Consider the character 'Y' only Because the '2' is encountered.] /* Counting vowels and consonants in a given line of text */ #include< stdio.h > #include< string.h > #include< conio.h >

int main(void) { char *str; int i,vow=0,cons=0; clrscr(); printf("Enter a string : "); scanf("% [ ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz]",str); for (i = 0; i < strlen(str); i++) if (str[i]=='A' || str[i]=='E' || str[i]=='I' || str[i]=='O' || str[i]=='U' || str[i]=='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u') vow++; else if (str[i] != ' ') // Ignore BLANK characters cons++; printf("\n\nThe given string is %s",str); printf("\n\nThe total number of VOWELS in a given string is %d",vow); printf("\nThe total number of CONSONANTS in a given string is %d",cons); return(0); } /* End of Main */

[Q010] W.A.P. in C to perform 4-letter WORD UNSCRAMBLING i.e. List all possible combinations of 4-letters in a word. Ex: The word 'TEST' can be unscrambled as TEST,TETS,TSET,TSTE,TTSE,TTES,etc. /* 4-letter word unscrambling */ #include< stdio.h > #include< conio.h > #include< string.h > int main() { int i,j,k,l,sum=6; char *str; clrscr(); printf("Enter a 4-letter word or string : "); scanf("%s",str); if (strlen(str) == 4) { printf("The possible combinations of the given 4-letter word is shown."); for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) if (i != j) { for (k = 0; k < 4; k++) if ((k != i) && (k != j)) {

l = sum - (i + j + k); printf("\n%c%c%c%c",str[i],str[j],str[k],str[l]); }} printf("\nTotal combinations = %d",4*3*2*1); } else printf("\nInvalid string. Length of the string must be 4-letters only"); getch(); return(0); } /* End of Main */

[Q001] What will be the output of the following program : int func(int *ptr,int a,int b) { return (a+b); *ptr=25; } int main() { int var=7,sum; sum=func(&var,5,6); printf("%d %d",sum,var); return(0); } (a)Compile-Time Error (b)11 25 (c)11 7 (d)None of these

[Q002] What will be the output of the following program : int func(int *ptr,int a,int b) { return (a+b); *ptr=25; return *ptr; } int main() { int var=7,sum; sum=func(&var,5,6); printf("%d %d",sum,var); return(0); } (a)Compile-Time Error (b)11 25 (c)11 7 (d)None of these

[Q003] What will be the output of the following program : int func(int *ptr,int a,int b) { *ptr=25; return *ptr; return (a+b); } int main() { int var=7,sum; sum=func(&var,5,6); printf("%d %d",sum,var); return(0); } (a)Compile-Time Error (b)11 25 (c)11 7 (d)25 25

[Q004] What will be the output of the following program : #define ToStr(s) #s #define Swap(x,y) y##x int Swap(in,ma)() { if (printf(ToStr("Friends"))){} return(0); } (a)Compile-Time error (b)"Friends" (c)Friends (d)None of these

[Q005] What will be the output of the following program : int main() { int a=(5,a=50)/a++; printf("%d",a); return(0); } (a)51 (b)0 (c)6 (d)1

[Q006] What will be the output of the following program : int main()

{

int a=(5,a=50)/++a; printf("%d",a); return(0); } (a)51 (b)0 (c)6 (d)1

[Q007] What will be the output of the following program : int main() { int a=7; if ((++a < 7) && (++a < 9) && (++a < 25) printf("%d",a); return(0); } (a)7 (b)8 (c)9 (d)10

[Q008] What will be the output of the following program : int main() { int a=7; if ((++a < 7) && (a++ < 9) && (++a < 25); printf("%d",a); return(0); } (a)7 (b)8 (c)9 (d)10

[Q009] What will be the output of the following program : int main() { for ( ; ; ) main(); return(0); } a)Compile-Time error (b)Run-Time Error (c)Infinite Loop (d)None of these

[Q010] What will be the output of the following program : int main() { int a=0,b=1,c; c = a=0 ? (a=1) : (b=2); printf("%d %d %d",a,b,c); return(0); } a)Compile-Time Error (b)2 2 2 (c)1 1 1 (d)None of these

[Q011] What will be the output of the following program : int main() { int a=5,b=1,c; c = a ? a=1 : b=2; printf("%d %d %d",a,b,c); return(0); } (a)Compile-Time Error (b)2 2 2 (c)1 1 1 (d)None of these

[Q012] What will be the output of the following program : int main() { unsigned _=5; _=_--- ++_; printf("%d",_); return(0); } (a)Compile-Time Error (b)5 (c)65535 (d)-1

[Q013] What will be the output of the following program : int main() { unsigned _=5; _=_--- ++_; printf("%u",_);

return(0); } (a)Compile-Time Error (b)5 (c)65535 (d)-1

[Q014] What will be the output of the following program : int fun(int a,int b) { #define NUM 5 return a+b; return(0); } int main() { printf("Sum=%d",fun(NUM,NUM)); return(0); } (a)Compile-Time Error (b)Run-Time Error (c)Sum=10 (d)None of these

[Q015] What will be the output of the following program : int main() { int a=5,b=6,c=7; printf("%d %d",a,b,c); return(0); } (a)Compile-Time Error (b)5 6 (c)Run-Time Error (d)5 6 7

[Q016] What will be the output of the following program : int add(int a,int b) { return a+b; } int main() { int a=1,b=2; printf("%d",add(add(add(a,b),add(a,b)),add(add(a,b),add(a,b)))); return(0); } (a)Garbage Value (b)Compile-Time Error (c)Run-Time Error (d)12

[Q017] What will be the output of the following program : #define S(s)char x[]="Welcome to ";s #define P(s) #s #define Q(x)char x[]=#x #define A(x,y)y##x #define B(x,y)A(y,x) #define C(x,y)B(y,x) S(B(A(a,m),A(n,i))(){Q(C(B(A(n,e),d),B(A(r,f),i))s);B(A(t, s),B(A(c,r),A(y,p)))(C(B(A(n,e),d),B(A(r,f),i))s,P(c4swimmers) );B(A(r,p),B(A(n,i),A(f,t)))("%s%s",x,C(B(A(n,e),d),B(A(r,f),i))s) ;B(A(e,r),B(A(u,t),A(n,r))) 0;}) (a)Compile-Time Error (b)Welcome to c4swimmers (c)Welcome to (d)c4swimmers

[Q018] What will be the output of the following program : int main() { int a=5,b=6,c=7,d=8,e; e = a ? b , c : c , d; printf("%d",e); return(0); } a)Compile-Time Error (b)6 (c)7 (d)8

[Q019] What will be the output of the following program : int main() { int a=5,b=6,c; c++ = b % (b - a); printf("%d",c); return(0); } a)Compile-Time Error (b)6 (c)7 (d)None of these

[Q020] What will be the output of the following program : int main() { int x=5,y=6,z; z = x++ +++y; printf("%d %d %d",x,y,z); return(0); } a)Compile-Time Error (b)3 (c)-1 (d)0

[Q001] Write a program (W.A.P.) in C to clear the screen and print C FOR SWIMMERS on each line, forming a diagonal pattern running from upper-left to lower right.[Use suitable delay]

[Q002] W.A.P. in C to SORT the array of strings based on first 3-LETTERS ONLY.

[Q003] Some C Functions take variable argument list in addition to taking a number of fixed (known) parameters. Implement using USER-DEFINED C FUNCTION that take VARIABLE ARGUMENT LIST and COMPUTE THE SUM OF VALUES specified in the list. Ex: int Sum(int a,...) // Here ... means VARIABLE ARGUMENT LIST { // Your Code Goes Here to access the values in the variable argument list } void main(void) { printf("%d",Sum(5,6,7,8,9,10)); //Prints the RESULT (Sum of these values=45) }

[Q004] W.A.P. in C to compute the sum of two values using function that takes two arguments (INTEGERS) and IT SHOULD RETURN the sum WITHOUT USING the RETURN statement but the return type of function is INTEGER ('int' data type). [NOTE : DO NOT MAKE USE OF ANY GLOBAL VARIABLES OR POINTER CONCEPT]

[Q005] W.A.P. in C to SWAP the contents of TWO VARIABLES WITHOUT using ASSIGNMENT OPERATOR. [HINT : USE 'asm' statement]

[Q006] W.A.P. in C to FIND THE LARGEST of two numbers (integer) WITHOUT using ?: operator, if, if...else and switch statements. [HINT : USE 'asm' statement]

[Q007] W.A.P. in C to print the following output WITHOUT USING GOTO STATEMENT, CONDITIONAL STATEMENTS (if, if...else & switch statements) and ANY LOOP STATEMENTS (for, while & do..while) : (a) ***** **** *** ** * (b) * ** *** **** *****

[Q008] W.A.P. in C to REVERSE THE WORDS IN A GIVEN LINE OF TEXT. [HINT : USE Built-in function 'strtok' in 'string.h' header file]

[Q009] W.A.P. in C to CONVERT THE TEXT within /* ... */ to UPPER-CASE (all occurrences) from the SPECIFIED C Source Code File and save the file without altering the remaining text.

[Q010] W.A.P. in C to READ a line of text and WRITE it out BACKWARDS using RECURSIVE Function.

[Q001] Whether the following program is a LEGAL code or ILLEGAL code. If it is a LEGAL code, then what will be the output : #include main(t,_,a) char *a; {return!0