type your search

Wednesday, January 18, 2012

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

No comments:

Post a Comment