Practice Set 1
Practice Set 1
1. #include<stdio.h>
int main()
{
printf("%x", -1<<1);
getchar();
return 0;
}
2. # include <stdio.h>
# define scanf "%sI love programming"
main()
{
printf(scanf, scanf);
getchar();
return 0;
}
3. #include <stdlib.h>
#include <stdio.h>
enum {false, true};
int main()
{
int i = 1;
do
{
printf("%d\n", i);
i++;
if (i < 15)
continue;
} while (false);
getchar();
return 0;
}
4. #include<stdio.h>
int main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);
}
}
P ag e |1 Dr. Shilpa
Pandey
PRACTICE SET 1
5. #include <stdlib.h>
#include <stdio.h>
enum {false, true};
int main()
{
int i = 1;
do
{
printf("%d\n", i);
i++;
if (i < 15)
break;
} while (true);
getchar();
return 0;
}
6. #include<stdio.h>
int main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
7. # include <stdio.h>
int main()
{
int i=0;
for(i=0; i<20; i++)
{
switch(i)
{
case 0:
i+=5;
case 1:
i+=2;
case 5:
i+=5;
default:
i+=4;
break;
}
printf("%d ", i);
}
return 0;
}
P ag e |2 Dr. Shilpa
Pandey
PRACTICE SET 1
8. # include <stdio.h>
int main()
{
char c;
printf(“Enter a character”);
scanf(“%c”,&c);
switch (c)
{
case 'a':
case 'e':
case 'i' :
case 'o':
case 'u':
printf(" Vowel character");
break;
default :
printf("Not a Vowel character");
break;
}
return 0;
}
9. #include <stdio.h>
int main()
{
printf("%p", main);
return 0;
}
getchar();
return 0;
}
11. #include <stdio.h>
int main()
{
int i;
i = 1, 2, 3;
printf("i = %d\n", i);
return 0;
}
P ag e |3 Dr. Shilpa
Pandey
PRACTICE SET 1
16. #include<stdio.h>
int main()
{
typedef int i;
i a = 0;
printf("%d", a);
return 0;
}
P ag e |4 Dr. Shilpa
Pandey
PRACTICE SET 1
17. #include<stdio.h>
void main()
{
int i = 10;
static int x = i;
if (x == i)
printf("equal");
else if (x < i)))
printf("less than");
else
printf("greater than");
}
18. #include<stdio.h>
void main()
{
int colour = 2;
switch (colour) {
case 0:
printf("Black");
case 1:
printf("Red");
case 2:
printf("Aqua");
case 3:
printf("Green");
default:
printf("Other");
}
}
19. #include<stdio.h>
void main()
{
if (printf("cisgood"))
printf("i know c");
else
printf("i know c++");
}
P ag e |5 Dr. Shilpa
Pandey
PRACTICE SET 1
25. #include<stdio.h>
int main()
{
enum week day;
day = Wed;
printf("%d",day);
return 0;
}
P ag e |6 Dr. Shilpa
Pandey
PRACTICE SET 1
int main()
{
enum day d = thursday;
printf("The day number stored in d is %d", d);
return 0;
}
28. #include <stdio.h>
int main()
{
printf("Hello World! %d \n", x);
return 0;
}
29. #include <stdio.h>
int main()
{
int y = 10000;
int y = 34;
printf("Hello World! %d\n", y);
return 0;
}
30. #include <stdio.h>
int main()
{
int main = 3;
printf("%d", main);
return 0;
}
P ag e |7 Dr. Shilpa
Pandey
PRACTICE SET 1
31 #include <stdio.h>
int main()
{
signed char chr;
chr = 128;
printf("%d\n", chr);
return 0;
}
32 #include <stdio.h>
int main()
{
float f1 = 0.1;
if (f1 == 0.1)
printf("equal\n");
else
printf("not equal\n");
}
33 #include <stdio.h>
int main()
{
float f1 = 0.1;
if (f1 == 0.1f)
printf("equal\n");
else
printf("not equal\n");
}
34 #include <stdio.h>
int main()
{
float x = 'a';
printf("%f", x);
return 0;
}
35 #include <stdio.h>
int main()
{
enum {ORANGE = 5, MANGO, BANANA = 4, PEACH};
printf("PEACH = %d\n", PEACH);
}
36 #include <stdio.h>
int main()
{
printf("C programming %s", "Class by\n%s Sanfoundry", "WOW");
}
37 #include <stdio.h>
int main()
{
j = 10;
printf("%d\n", j++);
return 0;
}
38 #include <stdio.h>
void main()
{
int k = 4;
float k = 4;
printf("%d", k)
}
P ag e |8 Dr. Shilpa
Pandey
PRACTICE SET 1
39 #include <stdio.h>
int main()
{
int i = -3;
int k = i % 2;
printf("%d\n", k);
}
40 #include <stdio.h>
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
printf("%d %d\n", l, k);
return 0;
}
41 #include <stdio.h>
int main()
{
int i = 5;
i = i / 3;
printf("%d\n", i);
return 0;
}
42 #include <stdio.h>
int main()
{
int i = -5;
i = i / 3;
printf("%d\n", i);
return 0;
}
43 #include <stdio.h>
void main()
{
int x = 5 * 9 / 3 + 9;
}
45 #include <stdio.h>
void main()
{
int x = 5.3 % 2;
printf("Value of x is %d", x);
}
46 #include <stdio.h>
void main()
{
int y = 3;
int x = 5 % 2 * 3 / 2;
printf("Value of x is %d", x);
}
47 #include <stdio.h>
void main()
{
int a = 3;
int b = ++a + a++ + --a;
printf("Value of b is %d", b);
}
48 #include <stdio.h>
P ag e |9 Dr. Shilpa
Pandey
PRACTICE SET 1
int main()
{
int a = 10;
double b = 5.6;
int c;
c = a + b;
printf("%d", c);
}
49 #include <stdio.h>
void main()
{
int x = 1, y = 0, z = 5;
int a = x && y || z++;
printf("%d", z);
}
50 #include <stdio.h>
void main()
{
int x = 1, y = 0, z = 5;
int a = x && y && z++;
printf("%d", z);
}
51 #include <stdio.h>
int main()
{
int x = 1, y = 0, z = 3;
x > y ? printf("%d", z) : return z;
}
52 #include <stdio.h>
void main()
{
int x = 1, z = 3;
int y = x << 3;
printf(" %d\n", y);
}
53 #include <stdio.h>
void main()
{
int x = 0, y = 2, z = 3;
int a = x & y | z;
printf("%d", a);
}
54 #include <stdio.h>
int main()
{
int i = 1;
if (i++ && (i == 1))
printf("Yes\n");
else
printf("No\n");
}
55 #include <stdio.h>
int main()
{
int a = 10, b = 5, c = 3;
b != !a;
c = !!a;
printf("%d\t%d", b, c);
P a g e | 10 Dr. Shilpa
Pandey
PRACTICE SET 1
}
56 #include <stdio.h>
int main()
{
int a = 10;
if (a == a--)
printf("TRUE 1\t");
a = 10;
if (a == --a)
printf("TRUE 2\t");
}
57 #include <stdio.h>
void main()
{
float x = 0.1;
if (x == 0.1)
printf("Sanfoundry");
else
printf("Advanced C Classes");
}
58 #include <stdio.h>
void main()
{
float x = 0.1;
printf("%d, ", x);
printf("%f", x);
}
59 #include <stdio.h>
void main()
{
float x;
int y;
printf("enter two numbers \n");
scanf("%f %f", &x, &y);
printf("%f, %d", x, y);
}
60 #include <stdio.h>
int main()
{
short int i = 20;
char c = 97;
printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i));
return 0;
}
Write a program to
1. C Program to Find ASCII Value of a Character
2. C Program to Find the Size of int, float, double and char
3. Check whether input year is leap year or not
4. Check whether input character is an alphabet , digit or a special symbol
5. Print number of days in the input month number
6. Accept a coordinate point in an XY coordinate system and determine in which quadrant the
Coordinate point lies
7 Write a C program to find maximum between two numbers using conditional operator
8 C Program to find smallest among three numbers using Conditional operator
9 Read the age of a candidate and determine whether he is eligible to cast his/her own vote
10 calculate the root of a quadratic equation
P a g e | 11 Dr. Shilpa
Pandey
PRACTICE SET 1
11 check whether a triangle can be formed with the given values for the angles
12 check whether an input alphabet is a vowel or a consonant
13 read any day number in integer and display the day name in word format
14 Compute the area of various geometrical shapes using a menu-driven approach
15 C Program to Reverse a Number
16 C Program to Count Number of Digits in an Integer
17 C Program to Check Whether a Number is Palindrome or Not
18 C Program to Display Prime Numbers Between Two Intervals
19 C Program to Check Armstrong Number
20 C Program to Display Armstrong Number Between Two Intervals
21 C Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers
P a g e | 12 Dr. Shilpa
Pandey