C Programming Puzzles 5


101)
#include <stdio.h>
main()
{
int i=4;
if (i>5) printf("Hi");
else f(i);
}

f(int j)
{
if (j>=4) f(j-1);
else if(j==0)return;
printf("Hi");
return;
}

102)
#include <stdio.h>
int *NEXT(register int i)
{
int *ipt;
ipt = &i;
ipt++;
return ipt;
}

main ()
{
int j;
printf("%d",(NEXT(j)));
}

103)
#include <stdio.h>
#define PRINT(int) printf("int = %d ",int)
main()
{
int x,y,z;
x=03;y=02;z=01;
PRINT(x^x);
z<<=3;PRINT(x);
y>>=3;PRINT(y);
}

104)
#include <stdio.h>
#define PRINT(int) printf( "int = %d ", int)
main()
{
int x=03,y=02,z=01;
PRINT (x | y & ~z);
PRINT (x & y && z);
PRINT (x ^ y & ~z);
}

105)
#include <stdio.h>
main()
{
int p;
for(p = 1; p<=10,--p; p=p+2)
puts("Hello");
}

106)
#include <stdio.h>
int n, R;
main()
{
R = 0;
scanf("%d",&n);
printf("\n %d, %d",fun(n),R);
}

int fun(int n)
{
if (n>3) return R = 5;
R = 6;
return(1);
}

107)
#include <stdio.h>
main()
{
int arr[3][3] = {1,2,3,4,5,6,7,8,9};
int i,j;
for (j=2;j>=0;j--){
for(i=2;i>=0;i--){
printf("\n%d",*(*(arr+i)+j));
printf("\n TATATATA");
}
}
}

108)
#include <stdio.h>
main()
{
int a = 10, b = 5,c = 3,d = 3;

if ((a<b) && (c = d++))
printf(" %d %d %d %d ", a, b, c, d);
else
printf(" %d %d %d %d ", a, b, c, d);

}

109)
#include <stdio.h>
main()
{
struct test
{
char c;
int i;
char m;
} t1;
printf("%d %d\n",sizeof(t1), sizeof(t1.c));
}

110)
#include <stdio.h>
main()
{
int a,b;
scanf("%d %d", &a, &b);
printf("%d\n", a+++b);
printf("%d %d\n",a,b);
}

111)
#include <stdio.h>
int i;
main()
{
char a[] = "Shiva";
printf("%c\n",i[a]);
}

112)
#include <stdio.h>
myread(a,b)
{
printf("%d %d",a,b);
}

main()
{
myread(2,4);
}

113)
#include <stdio.h>
funct(char* str)
{
printf("%s\n",str);
}

main()
{
static int ii = 1;
int jj = 5;
ii+=++jj;
funct(ii+++ "Campus Interview");
}

114)
#include <stdio.h>
funct(str)
{
printf("%s\n",str);
}

main()
{
funct('-'-'-'+"DEShaw");
}

115)
#include <stdio.h>
main()
{
printf(" %d\n",'-'-'-'+'/'/'/');
}

116)
#include <stdio.h>
static int a = 6;
extern int a;

main()
{
printf("%d",a);
}

117)
#include <stdio.h>
main()
{
int i=6,j=4;
printf("NO\n");
switch(i)
{
do{
case 1: printf("yes\n");

case 2:

case 3:

case 4:

case 5:

case 6:
j--;
}while (j);
}
}

118)
#include <stdio.h>
abc(int *i, int *j)
{
*i = *i + *j;
*j = *i - *j;
*i = *i - *j;
}
main()
{
int i = 5, j=10;
abc(&i,&j);
printf("%d..%d",i,j);
}

119)
#include<stdio.h>
int main()
{
char c;
c=255;
printf("%d",c);
return(0);
}

120)
#include<stdio.h>
main()
{
int x=5,p=10;
printf("%*d",x,p);
}

121)
#include<stdio.h>
main()
{
int a[]={2,3,4,5,6};
int i=0;
printf("%d",a[i++]+i[a+1]);
}

122)
#include<stdio.h>
#include<stdlib.h>
main()
{
int *ptr=(int*)malloc(sizeof(int));
*ptr=4;
printf("%d",*ptr++);
}

123)
#include<stdio.h>
main()
{
float x=3.14;
printf("%e, %E, %f",x,x,x);
}

124)
#include<stdio.h>
int main(int k)
{
if(k<10)
printf("%d ",main(k+1));
return k;
}

125)
#include<stdio.h>
main()
{
int i=4;
printf("%d %d %d",++i,i++,i*i);
printf("\n");
printf("%d %d %d",i*i,++i,i++);
}

1 comment:

  1. 101)
    HiHi

    102)
    In function NEXT: error: address of register variable i requested

    103)
    int = 0 int = 3 int = 0

    104)
    int = 3 int = 1 int = 1

    105)

    106)
    prints 5 if input n>3 else prints that number

    107)

    9
    TATATATA
    6
    TATATATA
    3
    TATATATA
    8
    TATATATA
    5
    TATATATA
    2
    TATATATA
    7
    TATATATA
    4
    TATATATA
    1
    TATATATA

    108)
    10 5 3 3

    109)
    12 1

    110)
    The value of a+++b is = a+b
    The value of a is incremented only after that print statement

    111)
    S

    112)
    2 4

    113)
    Interview

    114)
    DEShaw

    115)
    1

    116)
    6

    117)
    NO
    yes
    yes
    yes

    118)
    10..5

    119)
    -1

    120)
    " 10" [answer is the part inside the quotes.

    121)
    5

    122)
    4

    123)
    3.140000e+00, 3.140000E+00, 3.140000

    124)
    10 9 8 7 6 5 4 3 2

    125)
    6 4 16
    64 8 6

    ReplyDelete