41
C CAMPUÓ PLACEMENÔ QUESTIONS -------------------- 1. #include <stdio.h> main() { int i; i =0x10+010+10; printf("%d",i); } ---------------- 2. main() { int x; x = 4 % 5 + 6 % 5; printf("x = %d",x); } --------------- 3. main() { int i; float j; i =5/2; j =5/2; printf("%f %d ",j,i); } -------------- 4. main() { float a =12.25,b =13.25; if(a = b) printf("RISC"); else printf("CISC"); } ------------- 5. main() { int x =100; if(!!x) printf("x =%d",!x); else printf("x =%d",x); } ------------- 6. main() { long i=65536 +65; printf("%c\n",i); char a; Š printf("%d",a); } --------------- 7. main() { long i=65536 +65; printf("%c\n",i); Page 1

DocumentC

Embed Size (px)

Citation preview

Page 1: DocumentC

C CAMPUÓ PLACEMENÔ QUESTIONS -------------------- 1. #include <stdio.h> main() { int i; i =0x10+010+10; printf("%d",i); } ---------------- 2. main() { int x; x = 4 % 5 + 6 % 5; printf("x = %d",x); } --------------- 3. main() { int i; float j; i =5/2; j =5/2; printf("%f %d ",j,i); } -------------- 4. main() { float a =12.25,b =13.25; if(a = b) printf("RISC"); else printf("CISC"); } ------------- 5. main() { int x =100; if(!!x) printf("x =%d",!x); else printf("x =%d",x); } ------------- 6. main() { long i=65536 +65; printf("%c\n",i); char a;Š printf("%d",a); } --------------- 7. main() { long i=65536 +65; printf("%c\n",i);

Page 1

Page 2: DocumentC

C char a; printf("%d",a); } ---------- 8. main() { int q =2,d=3,st; st = q*d/4-12/12+12/3*16/d; printf("st =%d",st); } ---------- 9. main() { int q =2,d=3,st; st = q*d/4-12/12+12/3*16/d; printf("st =%d",st); } --------- 10. main() { printf("%d %f\n",4,4); printf("%d %f\n",4.0,4.0); } -------- 11. #define MEAN(a,b,c,d,e) (a+b+c+d+e)/5 main() { int a,b,c,d,e,m; a=1;b=2;c=3;d=4;e=5; m = MEAN(a,b,c,d,e); printf("Mean of the five numbers is =%d",m); } -------------- 12. main() { printf("%d",1&2); } -------------- 13. main() { int x;Š x =3 * 4 % 5; printf("x = %d",x); } -------------- 14. main() { printf("%d %d %d %d ",72,072,0x72,0X72); } -------------- 15. main() { printf("%d", 4||2); } --------------

Page 2

Page 3: DocumentC

C 16. main() { printf("%d",3||2); } ------------- 17. main() { printf("%d",3&&2); } -------------- 19. main() { int g = 300 * 300 /3; printf("g =%d",g); } -------------- 20. main() { int g = 300 * 300 /3; printf("g =%d",g); } -------------- 21. main() { printf("%d",3>2); } -------------- 22. main() { float x = 5.5,y=8.0; x*= ++x;/*for float there is no effect in using post ++*/ y++; printf("%f %f",x,y);Š } ----------------- 23. main() { int x=2,y,z,s; x*= y=z=4; s=(y==z); printf("%d\n",x); printf("%d",s); } ---------------- 24. main() { int x,y,z; x=2;y=1;z=0; x=(x&&y)||z; printf("%d\n",x); printf("%d\n",x||y&&z); x=y=1; z=x++ -1; printf("%d\n",x); printf("%d\n",z);

Page 3

Page 4: DocumentC

C z+= x++ + ++y; printf("%d\n%d\n",x,z); } ----------------- 25. main() { int x = 0,z,y; z = !x|x; y = x|!x; printf("%d %d",z,y); } -------------- 26. #include <stdio.h> main() { int i=100,j=200; printf("%d %d"); } --------------- 27. main() { int x = 2,z; for(x=2;x<=10;x++) { printf("%d\t",x); printf("%d\n",~x); } x=2;Š z = ~(x|x); printf("%d",z); } ----------------- 28. main() { int x=1,y=1,z=1,aa; x+=y+=z; printf("%d %d %d\n",x,y,z); aa = x<y?x++:y++; printf("%d",aa); } ---------------- 29. main() { int x=-1,y=-1,z=-1,a; a=(x++ && y++) || ++z; printf("%d %d %d %d", x,y,z,a); } ---------------- 30. main() { int y=100,x; x = y= y++; printf("%d %d ", x,y); } ---------------- 31. main()

Page 4

Page 5: DocumentC

C { int y=100,x; x = y= y++; printf("%d %d ", x,y); } ---------------- 32. #include<stdio.h> main() { int x,y=1,z; if (z=(y==1)) x=5; else x=10; printf("x=%d\t y = %d\t z=%d ",x,y,z); } ---------------- 33. # include<stdio.h> main() { int x,y=1,z; if (z=y<0) x=3; elseŠ if (y==0) x=5; else x=7; printf ("%d %d %d",x,y,z); } ------------------ 34. #include<stdio.h> int i=0; main() { auto int i=1; printf("%d\n",i); { int i=2; printf("%d\n",i); { i+=1; printf("%d\n",i); } printf("%d\n",i); } printf("%d\n",i); } ------------------- 35. # include<stdio.h> main() { int a=6; a+= a++ + ++a; printf("%d",a);} ------------------ 36. main() { static char food[]="yummy"; char *ptr; ptr=food + strlen(food); while (--ptr>=food) puts(ptr);

Page 5

Page 6: DocumentC

C } -------------------- 37. # include>¨-------------------

    --------------------        #includå <stdio.h>    main()     {     inô i;     é =0x10+010+10;     printf("%d",i);     }    ----------------

    main()     {     inô x;     ø ½ ´ ¥ µ « ¶ ¥ 5;     printf("ø ½ %d",x);

     ý    ---------------    main()     {     inô i;     floaô j;     é =5/2;     ê =5/2;     printf("%æ %ä ",j,i);     }    --------------    main()     {     floaô á =12.25,â =13.25;     if(á ½ b)     printf("RISC");     else     printf("CISC");     }    -------------

    main()     {     inô ø =100;     if(!!x)     printf("ø =%d",!x);     else     printf("ø =%d",x);     }    -------------

Page 6

Page 7: DocumentC

CŠ    main()     {     lonç i=6553¶ +65;     printf("%c\n",i);     chaò a;     printf("%d",a);     }

    ---------------    

    main()     {     lonç i=6553¶ +65;     printf("%c\n",i);     chaò a;     printf("%d",a);     }    ----------

    main()     {     inô ñ =2,d=3,st;     sô ½ q*d/´-12/12+12/3*16/d;     printf("sô =%d",st);     }    ----------     main()     {     inô ñ =2,d=3,st;     sô ½ q*d/´-12/12+12/3*16/d;     printf("sô =%d",st);     }    ---------     main()     {     printf("%ä %f\n",4,4);     printf("%ä %f\n",4.0,4.0);     }     --------    #definå MEAN(a,b,c,d,e© (a+b+c+d+e)/5    main()    {     inô a,b,c,d,e,m;     a=1;b=2;c=3;d=4;e=5;     í ½ MEAN(a,b,c,d,e);     printf("Meaî oæ thå fivå numberó ió =%d",m);    }    --------------    main()    {     printf("%d",1&2);    }Š    --------------    main()    {     inô x;     ø =³ ª ´ ¥ 5;     printf("ø ½ %d",x);     }    --------------

Page 7

Page 8: DocumentC

C    main()     {     printf("%ä %ä %ä %ä ",72,072,0x72,0X72);     }    --------------    main()    {     printf("%d"¬ 4||2);    ý

    --------------     main()    {     printf("%d",3||2);    ý    -------------    main()    {     printf("%d",3&&2);    }    --------------    main()    {     inô ç ½ 30° ª 30° /3;     printf("ç =%d",g);    }    --------------    main()    {     inô ç ½ 30° ª 30° /3;     printf("ç =%d",g);    }    --------------    main()    {    printf("%d",3>2);    ý    --------------    main()    {     floaô ø ½ 5.5,y=8.0;     x*½ ++x;/*foò floaô therå ió nï effecô iî usinç posô ++*/     y++;     printf("%æ %f",x,y);     ý

Š    -----------------    main()    {    inô x=2,y,z,s;

    x*½ y=z=4;    s=(y==z);    printf("%d\n",x);    printf("%d",s);    }    ----------------    main()    {     inô x,y,z;     x=2;y=1;z=0;     x=(x&&y)||z;

Page 8

Page 9: DocumentC

C     printf("%d\n",x);     printf("%d\n",x||y&&z);     x=y=1;     z=x+« -1;     printf("%d\n",x);     printf("%d\n",z);     z+½ x+« « ++y;     printf("%d\n%d\n",x,z);     }    -----------------    main()     {     inô ø ½ 0,z,y;     ú ½ !x|x;     ù ½ x|!x;     printf("%ä %d",z,y);     }    --------------    #includå <stdio.h>    main()     {     inô i=100,j=200;     printf("%ä %d");     }    ---------------    main()     {     inô ø ½ 2,z;     for(x=2;x<=10;x++)     {     printf("%d\t",x);     printf("%d\n",~x);     }     x=2;     ú ½ ~(x|x);     printf("%d",z);     }

Š    -----------------    main()     {     inô x=1,y=1,z=1,aa;     x+=y+=z;     printf("%ä %ä %d\n",x,y,z);     aá ½ x<y?x++:y++;     printf("%d",aa);

     }    ----------------    main()     {     inô x½-1,y½-1,z½-1,a;     a=(x+« &¦ y++© |ü ++z;     printf("%ä %ä %ä %d"¬ x,y,z,a);     }    ----------------     main()     {     inô y=100,x;     ø ½ y½ y++;     printf("%ä %ä "¬ x,y);

Page 9

Page 10: DocumentC

C     }    ----------------    main()     {     inô y=100,x;     ø ½ y½ y++;     printf("%ä %ä "¬ x,y);     }    ----------------

    #include<stdio.h>    main()    {     inô x,y=1,z;     iæ (z=(y==1)© x=5;     elså x=10;     printf("x=%d\ô ù ½ %d\ô z=%ä ",x,y,z);    }    ----------------    £ include<stdio.h>    main()    {     inô x,y=1,z;     iæ (z=y<0© x=3;     else     iæ (y==0© x=5;     elså x=7;     printæ ("%ä %ä %d",x,y,z);     }

Š    ------------------     #include<stdio.h>     inô i=0;     main()     {     autï inô i=1;     printf("%d\n",i);     {     inô i=2;     printf("%d\n",i);     {     i+=1;     printf("%d\n",i);     }     printf("%d\n",i);     }     printf("%d\n",i);     }    -------------------    £ include<stdio.h>    main()    {    inô a=6;    a+½ a+« « ++a;    printf("%d",a);}    ------------------

    main()     {     statiã chaò food[]="yummy";     chaò *ptr;     ptr=fooä « strlen(food);

Page 10

Page 11: DocumentC

C     whilå ¨--ptr>=food)     puts(ptr);     }    --------------------

    £ include<stdio.h>    main()     {     statiã chaò food[]="yummy";     chaò *ptr;     ptr=fooä « strlen(food);     whilå ¨--ptr>=food)     puts(ptr);     }    -------------------    main()     {     inô é =10;     #include<stdio.h>     printf("%d",i);     }

Š    -------------------    £ definå FUN(k© a+b/*ä-bc*/c    main()    {     inô a,b,c,*d,bc;     a=6;b=5;c=4;bc=2;     d=&c;     printf("%d\n",FUN(K));     }    -------------------    main()    {     inô x,a,b,c;     a=10;b=5;c=5;     x=a==â « c++;     printf("%d",x);     }

    -------------------    include<stdio.h>    main()    {     inô *a=71;     printf("%ä %d",a,*a);     }    --------------------    £ include<stdio.h>    main()    {     statiã inô arr[]=û 9· ,9¸ ,9¹ ,10° ,10± ,10² ,10³ ,10´ };     inô *ptò ½ arr+1;     print(++ptr,ptò--,ptr,ptr++,++ptr);     }     print(inô *a,inô *b,inô *c,inô *d,inô *e)     {     printf("\n%ä %ä %ä %ä %d",*a,*b,*c,*d,*e);     }    ---------------------   

Page 11

Page 12: DocumentC

C    #includå <stdio.h>    main()    {    inô i;    inô a[Ý ½ {1,2,3,4,5,6,7};    for(i=0;i<=4;i++)    {     printf(¢ %ä ",a[i]);     }     }

Š    -----------------    main()    {     inô a,i;     é ½ 11;     á ½ i+« « ++é « --i;     printf("%ä %d",a,i);    }    -----------------------    main()    {     inô i=10;     printf("\î valuå oæ é =%ä addresó oæ é =%u",i,&i);     &i==7200;     printf("\nne÷ valuå oæ i=%ä ne÷ addresó oæ é =%u",i,&i);     }    ------------------------    main()    {     inô *i,*j,**k;     j=i+2;     ë =&i;     printf("\nk=%õ j=%õ i=%u",*k,j,i);     }    --------------------    main()    {     inô i=10;     printf("\î valuå oæ é =%ä addresó oæ é =%u",i,&i);     &i==7200;     printf("\nne÷ valuå oæ i=%ä ne÷ addresó oæ é =%u",i,&i);     }    --------------------    main()    {     inô *i,*j,**k;     j=i+2;     ë =&i;     printf("\nk=%õ j=%õ i=%u",*k,j,i);     } ----------------------    #includå <stdio.h>    main()     {     union{     strucô cathy{     inô cathy;     chaò joe;

Page 12

Page 13: DocumentC

C     }cat;     inô m;     }ass;     printf("\nsizå oæ :%ä ¢ ,sizeof(ass));     }

Š    -----------------    #include<stdio.h>    main()    {    inô i=3,j;    j½ i+« ª ++é ª ++i;    printf("%ä %d",j,i);     }    ---------------    main()     {     inô aa0aa1aa2aa3aa4aa5aa6aa7aa8aa9aazz1zz² =10;     printf("%d",aa0aa1aa2aa3aa4aa5aa6aa7aa8aa9aa);     }    -----------------    #include<stdio.h>    main()    {     chaò in;     whilå ((iî ½ getchar())!½ '*')     {     iæ ((iî >½ 'a'© &¦ (iî <='z'))     another();     }

     }     another()     {     statiã inô i=0;     i++;     printf("%d",i);     }    ---------------    #include<stdio.h>    main()    {    inô stud[5][2]={     {1234,56},     {1212,33},     {1434,80},     {1312,78},     {1203,75}     };    inô i,j;    for(i=0;i<=4;i++)     {     printf("\n");     for(j=0;j<=1;j++)     printf("%d",*(*(stud+i)+j));     }     }

Š    ---------------

Page 13

Page 14: DocumentC

C    £ includå <stdio.h>    £ definå BYTESIZE    main()     {     inô printbits(int);     inô ø =5;     printbits(~x);     }

    printbits(x)    inô x;     {     inô i;     for(i=0;i<BYTESIZE*sizeof(x);++i)     printf("%d",(vaì <<i&1<<BYTESIZE*sizeof(int©-1)?1:0);     putchar('\n');     }

    ------------------    #includå <stdio.h>    main()    {     inô i=12,j=3,ë =2;     /ª ± « ± ½ ° ¦ 1+° ü 0+± ½ ± foò XOÒ */     /ª precå =¾ complé ,AND,OR,XOÒ */     printf("%ä ",i^j&~k);     printf("%ä %d",é ¦ j,é ¦ ê &¦ k);     }

    -------------    main()    {

    /ª !ø giveó ° foò +ivå ¦ -ivå valueó ;onå foò ° */     inô ø ½ 2;     printf("!ø ½ %d\n",!x);     printf("%d\n",!x|x);     printf("%u\n",~x|x);     printf("%u\n",x<<1);     printf("%u\î ",x>>1);    }

    -----------------    #include<stdio.h>    main()    {     inô á =1,â =1,c=1,x;     a+½ b+=c;     ø ½ á ¼ â ?a++:b++;     printf("%d\n",x);     printf("%d\n",ã ½ a<â ¿ a++:b++);     printf("%d\î %d\n",b,c);    }Š

    -----------------------    #include<stdio.h>    main()    {     inô a,b,c;     á ½ â =c½ -1;     ++á |ü ++â &¦ ++ã ;

Page 14

Page 15: DocumentC

C     printf("á ½ %ä ,â ½ %ä ¬ ã ½ %d",a,b,c);

    }    -------------    #include<stdio.h>    main()    {     inô a,b,c;     á ½ â =c½ -1;     ++á |ü ++â &¦ ++ã ;     printf("á ½ %ä ,â ½ %ä ¬ ã ½ %d",a,b,c);

    }    -------------    #include<stdio.h>    main()    {     inô a,b,c;     á ½ â ½ -2;     ã ½ ++á &¦ ++â ;     printf("á ½ %ä ,â ½ %ä ¬ ã ½ %d",a,b,c);    }    --------------    main()    {    inô x,y=100;    ø ½ y½ y++;    printf("ø ½ %d,ù ½ %ä ",x,y);    }

    ---------------    #include<stdio.h>    main()    {    inô x,y,z;    ø ½ ù ½ 0;    while(ù <10)     {     ø +½ ++y;    printf("%ä %d\n",x,y);     }     }

Š    --------------    main()    inô x=1,y=1;    iæ (y<0)     iæ (y>0© x=3;     elså x=5;    printf("%d",x);    }    ---------------

    #include<stdio.h>    main()    {    inô c,nä =0,nï =0;    while((ã =getchar())!½ EOF)    switch(c© {

Page 15

Page 16: DocumentC

C     caså '0§ :     caså '1§ :     caså '2§ :     caså '3§ :     caså '4§ :     caså '5§ :     caså '6§ :     caså '7§ :     caså '8§ :     caså '9§ :

     nd++;     default:     no++;     break;     }

     printf("%ä %ä ",nd,no);    }    -------------------    main()    {    inô x=1,y=1;    iæ (y<0)     iæ (y>0© x=3;     elså x=5;    printf("%d",x);    }    -----------------    main()    {    inô x,y=1,z;    iæ (x=y=z);x=3;    printf("%ä %d",x,z);    }

Š    ----------------    main()     {     inô a,b;     á ½-³ - -3;     â ½-³ - -¨-3);     printf("á ½ %ä â =%d",a,b);     }    ----------------    #include<stdio.h>    main()     {     lonç count;     counô ½ 62000+1536+10;     printf("%lä ",count);

     }    ----------------    #include<stdio.h>    main()     {     lonç count;     counô ½ 62000+1536+10;     printf("%lä ",count);

Page 16

Page 17: DocumentC

C     }    ---------------    main()     {     lonç i;     é =65536+300;     printf("%lä ",i);     }     ---------------    main()    {     inô *a;     *á ½ 1;     printf("%ä %d",a,*a);    }    -----------------    #includå <stdio.h>    inô a[][2Ý ={1,2,3,4};    main()     {     inô i,j;     inô (*p)[2]=a;     for(i=0;i<2;i++)     {     for(j=0;j<2;j++)     printf("%õ \t\t%õ \n",*p+j,*(*p+j));     p++;     }     }

Š    ---------------    main()    {     inô *a=1;     printf("%ä %d",a,*a);     }    ---------------    main()    {     chaò a[]={"jeban"};

     printf("%*s",(40+strlen(a)),a);     }

     ----------    #includå <stdio.h>    voiä cube(inô *,inô *,inô *);    main()     {     inô x=5,y,z;     cube(&x,&y,&z);     printf("valuå oæ ø =%d",x);     printf("\nItó cubå =%d",z);     }    voiä cube(inô *a,inô *b,inô *c)    {     *â ½ (*a)*(*a);     *ã ½ (*b)*(*a);     }    ----------------    main()    {    inô i=2,j=3,k;

Page 17

Page 18: DocumentC

C     k=i+++j;     printf("%ä %ä %d",i,j,k);     }    -----------    compute(inô m,inô n)     {     if(m==0)     return(n+1);     else     {     if(n==0)     compute(í-1,1);     else     compute(m,compute(í-1,n));     }     }

Š    main()    {     inô i;     é ½ compute(2,3);     printf("%d",i);     }    ------------------    main()    {    inô i=0;    chaò *caô ="city\0ki0ng";     while(*cat++)     {     i++;     printf("%d\n",i);     }     }

    ------------------    #includå <stdio.h>    inô i;    main()     {     chaò joe[10Ý ½ "city\0ki0ng";     chaò ch;     for(i=0;(ch=joe[i]!=0);i++)     {     ch=ch+'a§-'A';     printf("%d\n",ch);     }    }    --------------

    #includå <stdio.h>    inô i;    main()     {

Page 18

Page 19: DocumentC

C     chaò joe[10Ý ½ "city\0ki0ng";     chaò ch;     for(i=0;(ch=joe[i]!=0);i++)     {     ch=ch+'a§-'A';     printf("%d\n",ch);     }    }    -----------

Š    #includå <stdio.h>    main()    {     FILÅ *fp;     chaò str[20];     fð ½ fopen("new.out","w");     if(fð =½ 0)     printf("Filå openinç error");     else     {     printf("Enteò youò name:");     scanf("%s",str);     fprintf(fp,"%s",str);     fclose(fp);     }    }    ----------------    #includå <stdio.h>    main()    {     FILÅ *fp;     chaò str[20];     fð ½ fopen("new.out","w");     if(fð =½ 0)     printf("Filå openinç error");     else     {     printf("Enteò youò name:");     scanf("%s",str);     fprintf(fp,"%s",str);     fclose(fp);     }    }    ---------------    #includå <stdio.h>    main()    {     FILÅ *fp;     chaò a;     fð ½ fopen("old.out","w");     if(fð =½ 0)     printf("Filå openinç error");     else     {     for(scanf("%c",&a);a!=EOF;scanf("%c",&a))     fprintf(fp,"%c",a);     fclose(fp);     }

Page 19

Page 20: DocumentC

C    }

Š    -------------------    main()    {     inô a=(10,15,12,77);     printf("%ä ",a);     }

    -----------------    main()    {     chaò a;     printf("%d",(2^3)+(a^a));    }    -----------------    main()    {    inô é ½ 5;     printf("%d",i);    return(991211233232132323232242243333322232344233232323232342342242422);    printf("hai");    }    -----------------    main()    {     inô i=4,*j,*k;

     j=&i;     printf("\n%d\n",j);     j=j+1;     printf("\n%d\n",j);     j=j+9;     k=j+3;     printf("%ä %ä %ä ",é ,ê ,k);     }    --------------    #include<stdio.h>    #include<conio.h>    #definå CÌ printf("%c%c%c%c",27,91,50,74)    #definå MC(x,y© printf("%c%c%d%c%d%c",27,91,x,59,y,72)    #definå VÒ printf("%c%c%c%c",27,91,55,109)    #definå VÂ printf("%c%c%c%c",27,91,53,109)    #definå VÏ printf("%c%c%c%c",27,91,53,109)    main()    {     CL;     MC(12,33);     printf("hai");     VR» /*macrï foò reverså videï oî */     printf("\nhallo");     VO» /*macrï foò reverså videï ofæ */     printf("\nbye¢ );     MC(17,25);     VB» /ª macrï foò videï blinë */     printf("\nHELLO");     }Š    ---------------

Page 20

Page 21: DocumentC

C    main()    {     printf("%d",0.3.);    }

    ----------------    main()    {     inô a=3,b=2;     iæ (a=b)     printf("Thå twï numberó arå same");     else     printf("Thå twï numberó arå noô same");    }    ---------------    #includå <stdio.h>    main()    {     chaò *s="abc";     chaò *t;     foò (t=s;*t!='\0';++t)     û switcè (*t)     {     caså 'a':     putchar('1');     caså 'b':     putchar('2');     caså 'c':     putchar('3');     break;     }     }     putchar('\n');     }

    -------------------    #includå <stdio.h>    main()    {     strucô word     {     chaò *string;     inô length;     };     strucô worä dict[2];     strucô worä *ð =dict;

     ð->strinç ½ "structure";ð->lengtè =9;     (++p©->strinç ="word";ð->length½ 5;     printf("%d\n",¨--p©->length);     printf("%c",*(ð->string));     }Š

    ------------------------    #includå <stdio.h>    chaò *strchr(chaò *s,chaò c)    {     while(*s++!½ c);     returî s;    }

Page 21

Page 22: DocumentC

C    main()    {     chaò str[30];     gets(str);     puts(strchr(str,'a'));    }    ----------------    #includå <stdio.h>    voiä main(void)    {     inô i=5;     printf("\n%d",i);     change(i/2);     printf("\n%d",i);     i=change(i/2);     printf("\n%d",i);     }

    inô change(inô i)    {     returî i<=µ ¿ ² º µ ;    }    -------------     #includå <stdio.h>     main()     {     printf("%d",func());     }

    inô func()    {     _AX=100;    }     -------

Š    #includå <stdio.h>     chaò *mycopy(str)     chaò *str;     {     chaò ptr[20];

     strcpy(ptr,str);     return(ptr);     }     main()     {     chaò name[20];     chaò parm[20];

     strcpy(name,"malini");     parí =mycopy(name);     puts(parm);     }

Page 22

Page 23: DocumentC

C    ---------------    £ include<stdio.h>    £ include<ctype.h>    main()    {    chaò a;    á ½ getchar();     iæ isupper(a)

     printf("entereä valuå ió upper");     else     printf("entereä valuå ió lower");     }    --------------    main()    {     inô *a=1;     printf("%ä %d",a,*a);     }    -----------------    maiî ()    {     inô á ½ 10,b=5;     á ^=b^=a^=b;     printf("%ä %ä ",a,b);     }     ----------------    main()    {     inô á ½ 10,b=5;     á ^=b^=a^=b;     printf("%ä %ä ",a,b);     }

Š     -----------------    main()    {     floaô a=0.131200;     printf("%ä ",a);     }    ------------------

    main()    {     floaô a=0.131200;     printf("%ä ",a);     }    ---------------    #includå <stdio.h>    main()     {     inô *i,j;     é =&j;     é =i« 5;     printf("%ä %d",i,&j);     }    ----------------------    #includå <stdio.h>    #definå TABLE_SIZÅ 45

Page 23

Page 24: DocumentC

C    #includå "table.h"    #definå ø 10    #undeæ x    #definå ø 12    main()    {    inô j;    CL;    MC(12,32);    VO;    printf("thå tablå sizå ió %d",TABLE_SIZE);    incr(j,1,20)    printf("\nê ió %d",j);    printf("\nThå ø ió %d",x);    }    --------------    main()    {    chaò a[10],*pc;     inô j;     pã ½ a;     pã =pã « sizeof(a);     j=pã-a;    printf("%d",j);    }

    ---------------

Newsgroups: placementReceived: from MAILQUEUE by VAYU (Mercury 1.21); 30 Jul 99 08:45:17 IST+530Resent-from: "ARVIND RAMAN" <[email protected]>Resent-to: placement%[email protected]: Fri, 30 Jul 1999 08:45:16 IST+530Received: from MAILQUEUE by VAYU (Mercury 1.21); 29 Jul 99 17:53:34 IST+530From: "Dhanush" <[email protected]>Organization: R.E.C., Tiruchirappalli, INDIATo: [email protected]: Thu, 29 Jul 1999 17:53:09 IST+530Subject: Solved C questionsPriority: normalX-mailer: Pegasus Mail v3.21

C problems no. of questions - 86

-------------------- 1. #include <stdio.h> main() { int i; i =0x10+010+10; printf("%d",i); } ans : 34 ---------------- 2. main() {

Page 24

Page 25: DocumentC

C int x; x = 4 % 5 + 6 % 5; printf("x = %d",x); } ans : 5 --------------- 3. main() { int i; float j; i =5/2; j =5/2; printf("%f %d ",j,i); } ans : 2.000, 2 -------------- 4. main() { float a =12.25,b =13.25; if(a = b) printf("RISC"); else printf("CISC"); } ans : RISC ------------- 5. main() { int x =100; if(!!x) printf("x =%d",!x); else printf("x =%d",x); } ans : 0 ------------- 6. main() { long i=65536 +65; printf("%c\n",i); char a; printf("%d",a); } error. --------------- 7. main() { int q =2,d=3,st; st = q*d/4-12/12+12/3*16/d; printf("st =%d",st); } ans : 21 ---------- 8. main() { printf("%d %f\n",4,4); printf("%d %f\n",4.0,4.0);

Page 25

Page 26: DocumentC

C } ans : 4 garbage 0 0 -------- 9. #define MEAN(a,b,c,d,e) (a+b+c+d+e)/5 main() { int a,b,c,d,e,m; a=1;b=2;c=3;d=4;e=5; m = MEAN(a,b,c,d,e); printf("Mean of the five numbers is =%d",m); } ans : 3 -------------- 10. main() { printf("%d",1&2); } ans : 0 -------------- 11. main() { int x; x =3 * 4 % 5; printf("x = %d",x); } ans : 12 -------------- 12. main() { printf("%d %d %d %d ",72,072,0x72,0X72); } ans : 72 58 114 114 -------------- 13. main() { printf("%d", 4||2); } ans : 1 -------------- 14. main() { printf("%d",3||2); } ans : 1 ------------- 15. main() { printf("%d",3&&2); } ans : 1 -------------- 16. main() { int g = 300 * 300 /3; printf("g =%d",g); }

Page 26

Page 27: DocumentC

C ans : 8154 -------------- 17. main() { printf("%d",3>2); } ans : 1 -------------- 18. main() { float x = 5.5,y=8.0; x*= ++x;/*for float there is no effect in using post ++*/ y++; printf("%f %f",x,y); } ans 15.75 9 ----------------- 19. main() { int x=2,y,z,s; x*= y=z=4; s=(y==z); printf("%d\n",x); printf("%d",s); } ans : 8 1 ---------------- 20. main() { int x,y,z; x=2;y=1;z=0; x=(x&&y)||z; printf("%d\n",x); printf("%d\n",x||y&&z); x=y=1; z=x++ -1; printf("%d\n",x); printf("%d\n",z); z+= x++ + ++y; printf("%d\n%d\n",x,z); } ans : 1 1 2 0 3 4 ----------------- 21. main() { int x = 0,z,y; z = !x|x; y = x|!x; printf("%d %d",z,y); } ans : 1 1 --------------

Page 27

Page 28: DocumentC

C 22. #include <stdio.h> main() { int i=100,j=200; printf("%d %d"); } ans : 100 200 --------------- 23. main() { int x = 2,z; for(x=2;x<=10;x++) { printf("%d\t",x); printf("%d\n",~x); } x=2; z = ~(x|x); printf("%d",z); } ans : 2 -3 3 -4 ... 10 -11 -3 ----------------- 24. main() { int x=1,y=1,z=1,aa; x+=y+=z; printf("%d %d %d\n",x,y,z); aa = x<y?x++:y++; printf("%d",aa); } ans : 3,2,1,2 ---------------- 25. main() { int x=-1,y=-1,z=-1,a; a=(x++ && y++) || ++z; printf("%d %d %d %d", x,y,z,a); } ans :0,0,-1,1 ---------------- 26. main() { int y=100,x; x = y= y++; printf("%d %d ", x,y); } ans : 100, 101 ---------------- 27. #include<stdio.h> main() { int x,y=1,z; if (z=(y==1)) x=5;

Page 28

Page 29: DocumentC

C else x=10; printf("x=%d\t y = %d\t z=%d ",x,y,z); } ans:5 1 1 ---------------- 28. # include<stdio.h> main() { int x,y=1,z; if (z=y<0) x=3; else if (y==0) x=5; else x=7; printf ("%d %d %d",x,y,z); } ans : 7 1 0 ------------------ 29. #include<stdio.h> int i=0; main() { auto int i=1; printf("%d\n",i); { int i=2; printf("%d\n",i); { i+=1; printf("%d\n",i); } printf("%d\n",i); } printf("%d\n",i); } ans : 1 2 3 3 1 ------------------- 30. # include<stdio.h> main() { int a=6; a+= a++ + ++a; printf("%d",a);} ans : 22 ------------------ 31. main() { static char food[]="yummy"; char *ptr; ptr=food + strlen(food); while (--ptr>=food) puts(ptr); } ans : y my mmy ummy yummy -------------------- 32. main() {

Page 29

Page 30: DocumentC

C int i =10; #include<stdio.h> printf("%d",i); } ans : 10 ------------------- 33. # define FUN(k) a+b/*d-bc*/c main() { int a,b,c,*d,bc; a=6;b=5;c=4;bc=2; d=&c; printf("%d\n",FUN(K)); } ans : 8 ------------------- 34. main() { int x,a,b,c; a=10;b=5;c=5; x=a==b + c++; printf("%d",x); } ans : 1 ------------------- 35. include<stdio.h> main() { int *a=71; printf("%d %d",a,*a); } ans : 71, garbage /*my comment : error in Unix. Core will be dumped*/ -------------------- 36. # include<stdio.h> main() { static int arr[]={ 97 ,98 ,99 ,100 ,101 ,102 ,103 ,104 }; int *ptr = arr+1; print(++ptr,ptr--,ptr,ptr++,++ptr); } print(int *a,int *b,int *c,int *d,int *e) { printf("\n%d %d %d %d %d",*a,*b,*c,*d,*e); } ans : 100 100 100 99 99 --------------------- 37. #include <stdio.h> main() { int i; int a[] = {1,2,3,4,5,6,7}; for(i=0;i<=4;i++) { printf(" %d ",a[i]); } } ans : 1 2 3 4 5 -----------------

Page 30

Page 31: DocumentC

C 38. main() { int a,i; i = 11; a = i++ + ++i + --i; printf("%d %d",a,i); } ans:33 12 ----------------------- 39. main() { int i=10; printf("\n value of i =%d address of i =%u",i,&i); &i==7200; printf("\nnew value of i=%d new address of i =%u",i,&i); } ans : no change ------------------------ 40. main() { int *i,*j,**k; j=i+2; k =&i; printf("\nk=%u j=%u i=%u",*k,j,i); } ans : addr pnted by i, addr pnted + 4, addr in i -------------------- 41. #include <stdio.h> main() { union{ struct cathy{ int cathy; char joe; }cat; int m; }ass; printf("\nsize of :%d " ,sizeof(ass)); } ans : 3 ----------------- 42. #include<stdio.h> main() { int i=3,j; j= i++ * ++i * ++i; printf("%d %d",j,i); } ans : 125 6 --------------- 43. main() { int aa0aa1aa2aa3aa4aa5aa6aa7aa8aa9aazz1zz2 =10; printf("%d",aa0aa1aa2aa3aa4aa5aa6aa7aa8aa9aa); } ans : 10 (Compiler dependent) ----------------- 44.

Page 31

Page 32: DocumentC

C #include<stdio.h> main() { char in; while ((in = getchar())!= '*') { if ((in >= 'a') && (in <='z')) another(); } } another() { static int i=0; i++; printf("%d",i); } ans : if abc* is given as input then output is 123 --------------- 45. #include<stdio.h> main() { int stud[5][2]={ {1234,56}, {1212,33}, {1434,80}, {1312,78}, {1203,75} }; int i,j; for(i=0;i<=4;i++) { printf("\n"); for(j=0;j<=1;j++) printf("%d",*(*(stud+i)+j)); } } ans: 123456 121233 143480 .. --------------- 46. # include <stdio.h> # define BYTESIZE main() { int printbits(int); int x =5; printbits(~x); } printbits(x) int x; { int i; for(i=0;i<BYTESIZE*sizeof(x);++i) printf("%d",(val <<i&1<<BYTESIZE*sizeof(int)-1)?1:0); putchar('\n'); } ans : error. ------------------ 47. #include <stdio.h> main()

Page 32

Page 33: DocumentC

C { int i=12,j=3,k =2; /* 1 + 1 = 0 & 1+0 | 0+1 = 1 for XOR */ /* prece => compli ,AND,OR,XOR */ printf("%d ",i^j&~k); printf("%d %d",i & j,i & j && k); } ans : 13 0 0 ------------- 48. main() { /* !x gives 0 for +ive & -ive values ;one for 0 */ int x = 2; printf("!x = %d\n",!x); printf("%d\n",!x|x); printf("%u\n",~x|x); printf("%u\n",x<<1); printf("%u\n ",x>>1);

} ans : 0 2 65535 (Depends on the machine) 4 1 ----------------- 49. #include<stdio.h> main() { int a,b,c;e a = b =c= -1; ++a || ++b && ++c ; printf("a = %d ,b = %d , c = %d",a,b,c);

} ans : 0 0 -1 ------------- 50. #include<stdio.h> main() { int a,b,c; a = b = -2; c = ++a && ++b ; printf("a = %d ,b = %d , c = %d",a,b,c); } ans : -1 -1 1 -------------- 51. #include<stdio.h> main() { int x,y,z; x = y = 0; while(y <10) { x += ++y; printf("%d %d\n",x,y); } } ans : 1 1

Page 33

Page 34: DocumentC

C 3 2 6 3 10 4 15 5 21 6 28 7 36 8 45 9 55 10 -------------- 52. main() { int x=1,y=1; if (y<0) if (y>0) x=3; else x=5; printf("%d",x); } ans : 1 --------------- 53. #include<stdio.h> main() { int c,nd =0,no =0; while((c =getchar())!= '\n') switch(c) { case '0' : case '1' : case '2' : case '3' : case '4' : case '5' : case '6' : case '7' : case '8' : case '9' :

nd++; default: no++; break; } printf("%d %d ",nd,no); } ans : when input is 123abc<enter> , nd=3 no = 6 ------------------- 54. main() { int x,y=1,z; if (x=y=z);x=3; printf("%d %d",x,z); } ans : x=3 z=garbage ---------------- 55. main() { int a,b; a =-3 - -3; b =-3 - -(-3);

Page 34

Page 35: DocumentC

C printf("a = %d b =%d",a,b); } ans : a=0 b=-6 ---------------- 56. #include<stdio.h> main() { long count; count = 62000+1536+10; printf("%ld ",count); }e ans : 63546 ---------------- 57. main() { long i; i =65536+300; printf("%ld ",i); } ans : 65836 --------------- 58. main() { int *a; *a = 1; printf("%d %d",a,*a); } ans : garbage, 1 ----------------- 59. #include <stdio.h> int a[][2] ={1,2,3,4}; main() { int i,j; int (*p)[2]=a; for(i=0;i<2;i++) { for(j=0;j<2;j++) printf("%u \t\t%u \n",*p+j,*(*p+j)); p++; } } ans : 158 1 160 2 162 3 164 4 --------------- 60. main() { int *a=1; printf("%d %d",a,*a); } ans : 1, garbage --------------- 61. main() { char a[]={"jeban"};

Page 35

Page 36: DocumentC

C

printf("%*s",(40+strlen(a)),a); } ans : 45 spaces + jeban ---------- 62. #include <stdio.h> void cube(int *,int *,int *); main() { int x=5,y,z; cube(&x,&y,&z); printf("value of x =%d",x); printf("\nIts cube =%d",z); } void cube(int *a,int *b,int *c) { *b = (*a)*(*a); *c = (*b)*(*a); } ans: x=5 z=125 ---------------- 63. main() { int i=2,j=3,k; k=i+++j; printf("%d %d %d",i,j,k); } ans : 3 3 5 ----------- 64. compute(int m,int n) { if(m==0) return(n+1); else { if(n==0) compute(m-1,1); else compute(m,compute(m-1,n)); } }

main() { int i; i = compute(2,3); printf("%d",i); } ans : bull shitting question ------------------ 65. main() { int i=0; char *cat ="city\0ki0ng"; while(*cat++) { i++; printf("%d\n",i); }

Page 36

Page 37: DocumentC

C } ans : 1 2 3 4 ------------------ 66. #include <stdio.h> int i; main() { char joe[10] = "city\0ki0ng"; char ch; for(i=0;(ch=joe[i]!=0);i++) { ch=ch+'a'-'A'; printf("%d\n",ch); } } ans : 33 33 33 .. -------------- 67. #include <stdio.h> main() { FILE *fp; char str[20]; fp = fopen("new.out","w"); if(fp == 0) printf("File opening error"); else { printf("Enter your name:"); scanf("%s",str); fprintf(fp,"%s",str); fclose(fp); } } ans : too simple ---------------- 68. #include <stdio.h> main() { FILE *fp; char a; fp = fopen("old.out","w"); if(fp == 0) printf("File opening error"); else { for(scanf("%c",&a);a!=EOF;scanf("%c",&a)) fprintf(fp,"%c",a); fclose(fp); } } ans : same as the previous one ------------------- 69. main() { int a=(10,15,12,77); printf("%d ",a);

Page 37

Page 38: DocumentC

C } ans : 77 ----------------- 70. main() { char a; printf("%d",(2^3)+(a^a)); } ans: 1 ----------------- 71. main() { int i = 5; printf("%d",i);

return(991211233232132323232242243333322232344233232323232342342242422); printf("hai"); } ans : 5 ----------------- 72. main() { int i=4,*j,*k;

j=&i; printf("\n%d\n",j); j=j+1; printf("\n%d\n",j); j=j+9; k=j+3; printf("%d %d %d ",i ,j ,k); } ans : too simple -------------- 73. #include<stdio.h> #include<conio.h> #define CL printf("%c%c%c%c",27,91,50,74) #define MC(x,y)printf("%c%c%d%c%d%c",27,91,x,59,y,72) #define VR printf("%c%c%c%c",27,91,55,109) #define VB printf("%c%c%c%c",27,91,53,109) #define VO printf("%c%c%c%c",27,91,53,109) main() { CL; MC(12,33); printf("hai"); VR; /*macro for reverse video on */ printf("\nhallo"); VO; /*macro for reverse video off */ printf("\nbye" ); MC(17,25); VB; /* macro for video blink */ printf("\nHELLO"); } ans : prints some bull shit --------------- 74. main() {

Page 38

Page 39: DocumentC

C printf("%d",0.3.); } ans : error. ---------------- 75. main() { int a=3,b=2; if (a=b) printf("The two numbers are same"); else printf("The two numbers are not same"); } ans : two numbers are same --------------- 76. #include <stdio.h> main() { char *s="abc"; char *t; for (t=s;*t!='\0';++t) { switch (*t) { case 'a': putchar('1'); case 'b': putchar('2'); case 'c': putchar('3'); break; } } putchar('\n'); } ans : 123233 ------------------- 77. #include <stdio.h> main() { struct word { char *string; int length; }; struct word dict[2]; struct word *p =dict;

p->string = "structure";p->length =9; (++p)->string ="word";p->length= 5; printf("%d\n",(--p)->length); printf("%c",*(p->string)); }

ans : 9 s ------------------------ 78. #include <stdio.h> char *strchr(char *s,char c) { while(*s++!= c); return s;

Page 39

Page 40: DocumentC

C }

main() { char str[30]; gets(str); puts(strchr(str,'a')); } ans : input given "onometapoiea"; output is poiea ---------------- 79. #include <stdio.h> void main(void) { int i=5; printf("\n%d",i); change(i/2); printf("\n%d",i); i=change(i/2); printf("\n%d",i); }

int change(int i) { return i<=5 ? 2 : 5 ; } ans : 5 5 2 ------------- 80. #include <stdio.h> main() { printf("%d",func()); }

int func() { _AX=100; } ans : 100 ------- 81. #include <stdio.h> char *mycopy(str) char *str; { char ptr[20]; strcpy(ptr,str); return(ptr); } main() { char name[20]; char parm[20];

strcpy(name,"malini"); parm =mycopy(name); puts(parm); } ans : error --------------- 82. # include<stdio.h>

Page 40

Page 41: DocumentC

C # include<ctype.h> main() { char a; a = getchar(); if isupper(a) printf("entered value is upper"); else printf("entered value is lower"); } ans : input 'a'. output: entered value is lower -------------- 83. main () { int a = 10,b=5; a ^=b^=a^=b; printf("%d %d ",a,b); } ans : 5 10 ---------------- 84. main() { float a=0.131200; printf("%d ",a); } ans : 0 ------------------ 85. #include <stdio.h> main() { int *i,j; i =&j; i =i+ 5; printf("%d %d",i,&j); } ans : (compiler dependent) &j+10, &j ---------------------- 86. main() { char a[10],*pc; int j; pc = a; pc =pc + sizeof(a); j=pc-a; printf("%d",j); } ans : 20-------------------------------------------

Page 41