Zoho-C-Code Snippets Practice

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Code Snippets Practice:

Q1.

1. #include<stdio.h>
2. int N = 10;
3. int main()
4. {
5. static int x = 1;
6. if (printf("%d ", x) && x++ < N && main())
7. {}
8. return 0;
9. }

Q2.

1. #include<stdio.h>
2. int N = 10;
3. int main()
4. {
5. static int x = 1;
6. if (printf("%d ", x) && x++ < N && main())
7. {}
8. return 0;
9. }

Q3.

1. #include <stdio.h>
2. int main()
3. {
4. int a = 5;
5. int b = 5;
6. int sum = -( -a-b );
7. printf("%d",sum);
8. return 0;
9. }

Q4.

1. #include <stdio.h>
2.
3. int main()
4. {
5. if (!(printf("geeks")))
6. printf(" geeks ");
7. else
8. printf("forgeeks ");
9.
10. return 0;
11. }

Q5.

1. #include<iostream>
2. using namespace std;
3. int main()
4. {
5. int n = 4;
6. n = n >> 2;
7. cout << n;
8. return 0;
9. }

Q6.

1. // C program to find if machine is little


2. // endian or big endian.
3. #include <stdio.h>
4. int main()
5. {
6. unsigned int n = 1;
7. char *c = (char*)&n;
8. if (*c)
9. printf("LITTLE ENDIAN");
10. else
11. printf("BIG ENDIAN");
12. return 0;
13. }

Q7.

1. #include‹stdio.h›
2. int main()
3. {
4. struct site
5. {
6. char name[] = "GeeksforGeeks";
7. int no_of_pages = 200;
8. };
9. struct site *ptr;
10. printf("%d",ptr->no_of_pages);
11. printf("%s",ptr->name);
12. getchar();
13. return 0;
14. }

Q8.

1. int main()
2. {
3. char str[]= "geeks\nforgeeks";
4. char *ptr1, *ptr2;
5. ptr1 = &str[3];
6. ptr2 = str + 5;
7. printf("%c", ++*str - --*ptr1 + *ptr2 + 2);
8. printf("%s", str);
9. getchar();
10. return 0;
11. }

Q9.

1. #include <stdio.h>
2. int fun(int n)
3. {
4. int i, j, sum = 0;
5. for(i = 1;i<=n;i++)
6. for(j=i;j<=i;j++)
7. sum=sum+j;
8. return(sum);
9. }
10.
11. int main()
12. {
13. printf("%d", fun(15));
14. getchar();
15. return 0;
16. }

Q10.

1. #include <stdio.h>
2. int main()
3. {
4. int c = 5, no = 1000;
5. do {
6. no /= c;
7. } while(c--);
8.
9. printf ("%d\n", no);
10. return 0;
11. }

Q11.

1. #include <stdio.h>
2. int main()
3. {
4. int n;
5. for (n = 9; n != 0; n--)
6. printf("%d", n--);
7. }

Q12.

1. #include <stdio.h>
2. int main()
3. {
4. int x = 1;
5. if (x = 0)
6. printf("Geeks");
7. else
8. printf("Geeksforgeeks");
9. }
Q13.

1. #include <stdio.h>
2. int main()
3. {
4. int i = 2, j = 2;
5. while (i + 1 ? --i : j++)
6. printf("%d", i);
7. return 0;
8. }

Q14.

1. #include <stdio.h>
2. #define square(x) (x * x)
3.
4. int main()
5. {
6. int x, y = 1;
7. x = square(y + 1);
8. printf("%d\n", x);
9. return 0;
10. }

Q15.

1. // myprog.c
2. #include <stdio.h>
3. int main(int argc, char* argv[])
4. {
5. int result;
6. result = argv[2] + argv[4] + argv[6];
7. printf("%d", result);
8. return 0;
9. }
Q16.

1.

You might also like