C Programming Puzzles 4


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);
}

1 comment:

  1. 76)
    1 1

    77)
    Error Message:
    "In function `main':
    undefined reference to `i'
    ld returned 1 exit status"

    78)
    No
    Yes

    79)
    One,

    80)
    10

    81)
    %s DE Shaw DE Shaw

    82)
    a ab bc c

    83)
    21,-1079833692

    84)
    Never eve

    85)
    The first print statement prints "DESIS" but since str cannot be assigned "DESIS" thus error occurs.

    86)
    13 11 13

    87)
    Segmentation fault

    88)
    str is DESHAW

    89)
    k is zero
    Hello

    90)

    3 3

    91)
    enter an integer (x)
    i and j are x x
    i is:x
    j is:x+1

    92)
    100
    4
    2

    93)

    01234[if input is a character] else it is 0

    94)
    12

    95)
    0, 0, 0 4, 4, 4

    96)


    0
    5 10
    0

    97)
    SWITCH S

    98)
    bdÓ‚‹¿X‚‹¿

    99)
    987 11
    61 13
    3 3
    bdÓrƒ¿Øqƒ¿

    100)
    a b

    ReplyDelete