76) #include <stdio.h> #define MAXI 100 main(){ int x=6,done,i; done=i=0; do { if((x/=2)>1) {i++; continue;} else done++; }while ((i < MAXI) && !done); printf("%d %d\n",i,done); } 77) #include <stdio.h> main() { extern int i; i=20; printf("%d\n",sizeof(i)); } 78) #include <stdio.h> fun() { printf("Yes\n"); } #define fun() printf("No\n") main() { fun(); (fun)(); } 79) #include <stdio.h> main() { int i = 1; switch(i) { printf("\nHello, "); case 1: printf("One, "); i++; break; case 2: printf("Two"); break; } } 80) #include <stdio.h> #define DESHAWCURRENTDEBUGLEVEL 1 void main(void) { int i = 10 ; int j = 15 ; #ifdef DESHAWCURRENTDEBUGLEVEL printf("%d\n",i); #else printf("%d\n",j); #endif } 81) #include <stdio.h> #define scanf "%s DE Shaw" main() { printf(scanf,scanf); } 82) #include <stdio.h> main() { char *p="abc"; char *q="abc123"; while(*p==*q) { printf("%c %c",*p,*q); p++;q++; } } 83) #include <stdio.h> #define INTPTR int * main() { INTPTR pi, pj; int i,j; i=10;j=20; pi = &j; pj = &j; j++; i= *pi; printf("%d,",i); j++; // i= *pj; printf("%d",pj); } 84) #include <stdio.h> #include<string.h> main() { char strp[] = "Never ever say no"; char *chp, c='e'; int i,j; chp = strrchr(strp, c); i = chp-strp; for(j=0;j<=i;j++)printf("%c",strp[j]); } 85) #include <stdio.h> main() { char str[] ="abcdef"; printf("str is %s",str); str = "DESIS"; printf("str is %s",str); } 86) #include <stdio.h> main() { int i = 10; printf(" %d %d %d \n", ++i, i++, ++i); } 87) #include <stdio.h> #include<string.h> main() { char *str ="India pvt. ltd."; char *str1 = "DESIS"; printf("str is %s",str); printf("str is %s",str1); strcpy(str,str1); printf("str is %s",str); } 88) #include <stdio.h> #include<string.h> main() { char str[] ="DESIS India pvt. ltd."; const char *str1= str; strcpy(str1,"DESHAW"); printf("str is %s",str); } 89) #include <stdio.h> main() { int i=4,j=2,k=0; char c1='a',c2='b'; if(k==0)printf("k is zero\n"); else if(j==2)printf("j is 2\n"); else if(i==4)printf("i is 4\n"); if(c1!='a')printf("c1 is not a\n"); else if (c2=='a')printf("c2 is b"); else printf("Hello\n"); } 90) #include <stdio.h> main() { int a[3] = {1,2,3}; int i= 2; printf("\n %d %d\n", a[i], i[a]); } 91) #include <stdio.h> void fun(int, int*); main() { int j,i; int * intptr; printf("enter an integer\n"); scanf("%d",&i); intptr = &j; j = i; printf("i and j are %d %d \n",i,j); fun(j,intptr); printf("i is:%d",i); printf("\n j is:%d",j); } void fun(int k, int *iptr) { k++; (*iptr)++; return; } 92) #include <stdio.h> main() { int x; x = printf("%d\n",x=printf("%d\n",100)); printf("%d\n",x); } 93) #include <stdio.h> main() { int i; char c; for (i=0;i<5;i++){ scanf("%d",&c); printf("%d",i); } } 94) #include <stdio.h> main() { int x = 10,y=2,z; z=x/*y+y*/+y; printf("%d\n",z); } 95) #include <stdio.h> main() { int a[] = {0,1,2,3,4}; int *p[] = {a,a+1,a+2,a+3,a+4}; int **pp = p; printf("%d, %d, %d ", *pp-a, pp-p, **pp); pp++; pp++;;++pp;*++pp; printf("%d, %d, %d ", pp-p, *pp-a, **pp); } 96) #include <stdio.h> #include<stdlib.h> #include<ctype.h> main() { int *p, *c, i; i = 5; p = malloc(sizeof(i)); printf("\n%d",*p); *p = 10; printf("\n%d %d",i,*p); c = calloc(2,i); printf("\n%d\n",*c); } 97) #include <stdio.h> main() { char input[] = "SSSWILTECH1\1\1"; int i, c; for ( i=2; (c=input[i])!='\0'; i++) { switch(c) { case 'a': putchar ('i'); continue; case '1': break; case 1: while (( c = input[++i]) != '\1' && c!= '\0'); case 9: putchar('S'); case 'E': case 'L': continue; default: putchar(c);continue; } putchar(' '); } putchar('\n'); } 98) #include <stdio.h> main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] = (k%16 > 9) ? (k%16 - 10 + 'a') : (k%16 - '0' ); } while(k /= 16); for(i=0;i<10;i++) printf("%c", trans[i]); } 99) #include <stdio.h> main() { unsigned int k = 987 , i = 0; char trans[10]; do { trans[i++] = (k%16 > 9 ? k%16 - 10 + 'a' : k%16 - '0' ); printf("%d %d\n",k,k%16); } while(k /= 16); printf("%s\n", trans); } 100) #include <stdio.h> main() { char *pk; const char* p; const char c = 'a'; char c1='b'; p=&c1; pk = &c; printf("%c %c",*pk,*p); }
type your search
Wednesday, January 18, 2012
C Programming Puzzles 4
Labels:
C language
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment