KEMBAR78
C Programs 50 | PDF | Area | Numbers
0% found this document useful (0 votes)
14 views32 pages

C Programs 50

The document outlines a series of programming tasks and examples primarily focused on C programming, including basic input/output operations, data types, arithmetic operations, conditional statements, loops, and functions. It provides specific programming exercises such as calculating areas, handling user input, and performing mathematical operations. Each task is accompanied by a sample program and expected output, serving as a guide for students in the Department of Artificial Intelligence and Data Science.

Uploaded by

mathsforlife969
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views32 pages

C Programs 50

The document outlines a series of programming tasks and examples primarily focused on C programming, including basic input/output operations, data types, arithmetic operations, conditional statements, loops, and functions. It provides specific programming exercises such as calculating areas, handling user input, and performing mathematical operations. Each task is accompanied by a sample program and expected output, serving as a guide for students in the Department of Artificial Intelligence and Data Science.

Uploaded by

mathsforlife969
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Department of Artificial Intelligence and Data Science

NAME : REG.NO ::

Sl.No TOPIC SIGN


Printf
1 Print (Hello world!)
2 Print the student name
Datatypes and Format Specifiers
3 Get a Float value from user and print it as output
4 Get 3 integer numbers from user and display
5 Get a character from user and print it as output
6 Get a name(char array) from user and print it as output
7 Get a double value from user and print it as output
8 Get a long value from user and print it as output
9 Get a signed value from user and print it as output
10 Get a unsigned short int value from user and print it as output
11 Get a unsigned long int value from user and print it as output
Variables and Scanf, Printf,Assignment statement
12 Write a program to find area and perimeter of square, rectangle and triangle
13 Write a program to find area, circumference of a circle.
14 Write a program to accept three numbers from users and perform addition,
product and average of three numbers.
15 Write a program to read roll number , name , 5 subject marks of a student and
print total and average.
16 Write a program to calculate (a+b)2 and (a-b)2
17 Write a program to convert centigrade to Fahrenheit and vice - versa
18 Write a program to swap 2 numbers using third variable
19 Write a program to swap 2 numbers without using third variable
20 Write a program to calculate simple and compound interest.
21 Write a program to input employee number, employee name, basic salary ,DA,TA
and deduct 15 % IT from basic salary and compute gross pay and net pay.`
22 Write a program to accept a 4 digit number [1234] and display the number
separately as 1, 2,3,4.
Operators
23 Program with Unary operator ++ post increment, pre increment
24 Program with Unary operator -- , post decrement , pre decrement
25 Program with Binary Operators(Addition, Subtraction, Multiplication, Division,
Modulus)
26 Write a program to find greatest and smallest among three numbers using
conditional operator
27 Write a program to accept a number and perform bitwise left shift and right shift
operation.
Write a C program to swap two numbers using bitwise operators in c
28 Write a program to convert float value to integer with implicit type conversion
29 Write a program to convert float value to integer with explicit type conversion
30 Write a program to convert float value to char with explicit type conversion
Conditional Statements
31 Write a program to get age from user and check the age value is eligible to vote
32 Write a program to check whether a number is even or odd using if- else
33 Write a program to check whether Two numbers are equal (Relational Operator)
34 Write a program to check the largest among two numbers (if –else)
35 Write a program to check the largest among three numbers (if and logical
operators)
36 Write a program to check the largest among three numbers (nested if )
37 To get an age and check whether is he/she eligible to vote
38 To check whether a year is leap or not(if else ladder)
39 Write a program to assign Grade using else if or ladder if
40 Write a program to assign Grade using switch case.
41 Calculator program using else if or ladder if
42 Calculator program using switch
43 To check whether a character is vowel or not(switch case)
44 Write a program to withdraw a certain amount from user account.
Loops
45 Printing from 1 to 100 using for, while, do-while
46 Print the even numbers in a specific range N using for, while, do-while
47 Write a program to Print sum of odd numbers of range N using for, while, do-
while
48 Write a program to print Sum of numbers within a specific range N using for,
while, do-while
49 Write a program to print Sum of squares within a specific range N using for,
while, do-while
50 Write a program in C to display the sum of cube within a specific range N using
for, while, do-while
Programs
51 Write a program to find factorial of a number N
52 Write a program to generate N Fibonacci series
53 Write a program to generate prime numbers within a range N
54 Write a program to check a number is composite or prime number.
55 Write a program to check a number is Armstrong number or not
56 Write a C Program check whether a given number is perfect number or not.
57 Write a program to accept a 5 digit number from user and perform Sum of 5 digits
58 Write a program to Reverse a Number
59 HCF and LCM of two numbers
60 Square root of a number
61 Count the number of digits in a number
62 Write a program to convert binary number to decimal
63 Write a program to convert decimal number to binary
64 Write a program to find the roots of a quadratic equation using if-else
65 Write a C program to display the following patterns
S.NO PROGRAMS
1 Print Hello World!
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Hello world!");
return 0;
}
OUTPUT:
Hello world!

2 Print the student name


PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Rakshitha");
return 0;
}
OUTPUT:
Rakshitha

3 Get a float value from user and print it as output


PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
float a;
printf("Enter a float value:");
scanf("%f",&a);
printf("%f",a);
}
OUTPUT
Enter a float value:6.5532
6.553200
4 Get three integer numbers from user and display
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c;
printf("Enter any three integers:");
scanf("%d %d %d",&a,&b,&c);
printf("%d %d %d",a,b,c);
}
OUTPUT:
Enter any three integers:5 7 3
573

5 Get a character from user and print it as output


PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char a;
printf("Enter a character:");
scanf("%c",&a);
printf("%c",a);
}
OUTPUT:
Enter a character:#
#

6 Get a name(char array) from user and print it as output


PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char name[20];
printf("Enter a name:");
scanf("%s",name);
printf("%s",name);
}
OUTPUT:
Enter a name:Rakshitha
Rakshitha
7 Get a double value from user and print it as output
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
double a;
printf("Enter a double value:");
scanf("%lf",&a);
printf("%lf",a);
}
OUTPUT:
Enter a double value:5675.456754
5675.456754
8 Get a long value from user and print it as output
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
long a;
printf("Enter a value ");
scanf("%ld",&a);
printf("%ld",a);
}
OUTPUT:
Enter a value 23456432
23456432
9 Get a signed value from user and print it as output
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
signed int a;
printf("Enter a number:");
scanf("%d",&a);
printf("%d",a);
}
OUTPUT:
Enter a number:-654
-654
10 Get a unsigned short int value from user and print it as output
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned short int a;
printf("Enter a number:");
scanf("%u",&a);
printf("%u",a);
}
OUTPUT:
Enter a number:675
675
11 Get a unsigned long int value from user and print it as output
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned long int a;
printf("Enter a value:");
scanf("%lu",&a);
printf("%lu",a);
}
OUTPUT:
Enter a value:5467898
5467898
12 Write a program to find area and perimeter of square, rectangle and triangle
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int a,b,h,perimeter;
float circum,area;
printf("Enter the side of a square:");
scanf("%d",&a);

perimeter=4*a;
area=a*a;
printf("Perimeter of a square:%d\n",perimeter);
printf("Area of a square:%f\n",area);

printf("Enter the length and breadth of a rectangle:");


scanf("%d %d",&a,&b);
perimeter=2*(a+b);
area=a*b;
printf("Perimeter of a rectangle:%d\n",perimeter);
printf("Area of a rectangle:%f\n",area);

printf("Enter base and height of triangle:");


scanf("%d %d",&a,&h);
area=0.5*a*h;
printf("Area of a triangle:%f\n",area);
}
OUTPUT:
Enter the side of a square:4
Perimeter of a square:16
Area of a square:16.000000
Enter the length and breadth of a rectangle:6 4
Perimeter of a rectangle:20
Area of a rectangle:24.000000
Enter base and height of triangle:3 2
Area of a triangle:3.000000
13 Write a program to find area, circumference of a circle.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int r; float area,circum;
printf("Enter the radius:");
scanf("%d",&r);
area=3.14*r*r;
circum=2*3.14*r;
printf("Area of circle:%f \n",area);
printf("Circumference of the circle:%f",circum);
}
OUTPUT:
Enter the radius:7
Area of circle:153.860001
Circumference of the circle:43.959999
14 Write a program to accept three numbers from users and perform addition, product and average of three
numbers.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c,total,product;
float avg;
printf("Enter the three numbers:");
scanf("%d %d %d",&a,&b,&c);
total=a+b+c;
product=a*b*c;
avg=(a+b+c)/3;
printf("Sum is:%d \n",total);
printf("Product is:%d\n",product);
printf("Average of three numbers is:%f",avg);
return 0;

}
OUTPUT:
Enter the three numbers:29 23 31
Sum is:83
Product is:20677
Average of three numbers is:27.000000
15 Write a program to read roll number , name , 5 subject marks of a student and print total and average.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int rno,s1,s2,s3,s4,s5,total;float average;
char name[20];
printf("enter rno and name");
scanf("%d",&rno);
scanf("%s",name);
printf("enter 5 subject marks:");
scanf("%d %d %d %d %d",&s1,&s2,&s3,&s4,&s5);
total=s1+s2+s3+s4+s5;
average=(s1+s2+s3+s4+s5)/5;
printf("Total marks:%d \n",total);
printf("average:%f",average);
}
OUTPUT:
enter rno and name 42 Rakshitha
enter 5 subject marks:94 90 83 86 79
Total marks:432
average:86.000000

16 Write a program to calculate (a+b)2 and (a-b)2


PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c;
printf("Enter two values:");
scanf("%d %d",&a,&b);
c=(a*a)+2*a*b+(b*b);
printf("(a+b)^2 is:%d\n",c);
c=(a*a)-2*a*b+(b*b);
printf("(a-b)^2 is:%d",c);
}
OUTPUT:
Enter two values:8 5
(a+b)^2 is:169
(a-b)^2 is:9

17 Write a program to convert centigrade to Fahrenheit and vice – versa


PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
float c,f;
printf("Enter the temperature in centigrade:");
scanf("%f",&c);
f=(c*1.8)+32;
printf("The temperature in fahrenheit:%f\n",f);
printf("Enter the temperature in fahrenheit:");
scanf("%f",&f);
c=(f-32)/1.8;
printf("The temperature in centigrade:%f",c);

}
OUTPUT:
Enter the temperature in centigrade:23
The temperature in fahrenheit:73.400002
Enter the temperature in fahrenheit:73
The temperature in centigrade:22.777779
18 Write a program to swap 2 numbers using third variable
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=10,b=5,c;
c=a;
a=b;
b=c;
printf("a=%d\n",a);
printf("b=%d",b);
}
OUTPUT:
a=5
b=10
19 Write a program to swap 2 numbers without using third variable
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=420,b=410;
b=a+b;
a=b-a;
b=b-a;
printf("a=%d\n",a);
printf("b=%d",b);

}
OUTp

20 Write a program to calculate simple and compound interest.


PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int p,n,r,t;
float a,ci,pw;
printf("Enter the principal amount,no of years and rate of interest:");
scanf("%d %d %d",&p,&t,&r);
a=(p*t*r)/100;
printf("Simple interest:%f\n",a);
printf("Enter the principal amount,no of years,rate of interest and frequency:");
scanf("%d %d %d %d",&p,&t,&r,&n);
ci=1+(r/n);
pw=n*t;
a=p*pow(ci,pw)-p;
printf("Compound interest:%f",a);

}
OUTPUT:
Enter the principal amount,no of years and rate of interest:1000 2 6
Simple interest:120.000000
Enter the principal amount,no of years,rate of interest and frequency:1000 2 6 2
Compound interest:255000.000000
21 Write a program to input employee number, employee name, basic salary ,DA,TA and deduct 15 % IT from
basic salary and compute gross pay and net pay.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int no,bs,da,ta,hra,gross,net;float it;
char name[20];
printf("Enter employee name and number:");
scanf("%s %d",name,&no);
printf("Enter basic salary:");
scanf("%d",&bs);
printf("Enter DA:");
scanf("%d",&da);
printf("Enter TA:");
scanf("%d",&ta);
printf("Enter HRA:");
scanf("%d",&hra);
it=0.15*bs;
bs=bs-it;
printf("Basic salary after reduction of IT is:%d\n",bs);
gross=bs+da+ta+hra+it;
printf("Gross salary:%d\n",gross);
net=bs+da+ta+hra;
printf("Net salary:%d",net);
}
OUTPUT:
Enter employee name and number: Rak 43
Enter basic salary:70000
Enter DA:1000
Enter TA:5000
Enter HRA:4500
Basic salary after reduction of IT is:59500
Gross salary:80500
Net salary:70000

22 Write a program to accept a 4 digit number [1234] and display the number separately as 1, 2,3,4
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int a=1234,b,c,d,e,f,g,h;
printf("%d\n",a);
b=a%10;
printf("%d\,",b);
c=a/10;
d=c%10;
printf("%d\,",d);
e=c/10;
f=e%10;
printf("%d\,",f);
g=e/10;
h=g%10;
printf("%d",h);

}
OUTPUT:
1234
1,2,3,4
23 Program with Unary operator ++ post increment, pre increment
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int a,b;
printf("Enter a number:");
scanf("%d",&a);
b=a++;
printf("post increment:%d\n",b);
printf("a=%d\n",a);
b=++a;
printf("pre increment:%d",b);
}
OUTPUT:
Enter a number:10
post increment:10
a=11
pre increment:12
24 Program with Unary operator -- , post decrement , pre decrement
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int a,b;
printf("Enter a value:");
scanf("%d",&a);
b=--a;
printf("pre decrement:%d\n",b);
printf("a=%d\n",a);
b=a--;
printf("post decrement:%d",b);
}
OUTPUT:
Enter a value:10
pre decrement:9
a=9
post decrement:9
25 Program with Binary Operators(Addition, Subtraction, Multiplication, Division, Modulus)
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int a,b,c;
printf("Enter the two numbers:");
scanf("%d %d",&a,&b);
c=a+b;
printf("Sum is:%d\n",c);
c=a-b;
printf("Difference is:%d\n",c);
c=a*b;
printf("Product is:%d\n",c);
c=a/b;
printf("Quotient is:%d\n",c);
c=a%b;
printf("Remainder is:%d",c);
}
OUTPUT:
Enter the two numbers:10 5
Sum is:15
Difference is:5
Product is:50
Quotient is:2
Remainder is:0
26 Write a program to find greatest and smallest among three numbers using conditional operator
PROGRAM:
#include <stdio.h>
int main()
{
int a,b,c, max,min;
printf("Enter three numbers");
scanf("%d %d %d",&a,&b,&c);
max =a>b?(a>c?a:c):(b>c?b:c);
min=a<b?(a<c?a:c):(b<c?b:c);
printf("The greatest number is %d\n", max);
printf("The smallest number is %d\n", min);
}
OUTPUT:
Enter three numbers 56 65 43
The greatest number is 65
The smallest number is 43
27 Write a program to accept a number and perform bitwise left shift and right shift operation
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int a;
printf("Enter a number:");
scanf("%d",&a);
printf("The value of a<<2 is:%d\n",a<<2);
printf("The value of a<<2 is:%d",a>>2);
}
OUTPUT:
Enter a number:4
The value of a<<2 is:16
The value of a<<2 is:1
Write a C program to swap two numbers using bitwise operators in c
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int a,b;
printf("Enter the two numbers:");
scanf("%d %d",&a,&b);
printf("a=%d\n",a);
printf("b=%d\n",b);
a=a^b;
b=a^b;
a=a^b;
printf("The two numbers after swapping\n");
printf("a=%d\n",a);
printf("b=%d\n",b);

}
OUTPUT:
Enter the two numbers:16 13
a=16
b=13
The two numbers after swapping
a=13
b=16
28 Write a program to convert float value to integer with implicit type conversion
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a=10,b;
b=a+10.2;
printf("%d",b);
}
OUTPUT:
20
29 Write a program to convert float value to integer with explicit type conversion
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int a;
printf("Enter a float value:");
scanf("%d",&a);
a=(int)(a);
printf("%d",a);
}
OUTPUT:
Enter a float value:12.56
12
30 Write a program to convert float value to char with explicit type conversion
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
char a;
printf("Enter a float value:");
scanf("%c",&a);
a=(char)(a);
printf("%c",a);
}
OUTPUT:
Enter a float value:12.77
1
31 Write a program to get age from user and check the age value is eligible to vote
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int age;
printf("Enter the age:");
scanf("%d",&age);
if(age>=18)
printf("Eligible to vote");
else
printf("Not eligible to vote");

}
OUTPUT:
Enter the age:28
Eligible to vote
32 Write a program to check whether a number is even or odd using if- else
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int a;
printf("enter a number");
scanf("%d",&a);
if(a%2==0)
{
printf("Even number");
}
else
{
printf("odd number");
}
}
OUTPUT:
enter a number 37
odd number
33 Write a program to check whether Two numbers are equal (Relational Operator)
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int a,b;
printf("Enter any two numbers:");
scanf("%d %d",&a,&b);
if(a==b)
printf("The two numbers are equal");
}
OUTPUT:
Enter any two numbers:34 34
The two numbers are equal
34 Write a program to check the largest among two numbers (if –else)
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b;
printf("Enter two numbers");
scanf("%d %d",&a,&b);
if(a>b)
{
printf("a is the greater");
}
else
{
printf("b is greater");

}
}
OUTPUT:
Enter two numbers 45 54
b is greater
35 Write a program to check the largest among three numbers (if and logical operators)
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int a,b,c;
printf("Enter the three numbers");
scanf("%d %d %d",&a,&b,&c);
if(a>b&&a>c)
{
printf("A is the greatest of three numbers");

}
else if(b>a&&b>c)
{
printf("B is the greatest of three numbers");
}
else
{
printf("C is the greatest of three numbers");
}

}
OUTPUT:
Enter the three numbers 4 8 10
C is the greatest of three numbers
36 Write a program to check the largest among three numbers (nested if )
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c;
printf("Enter the three numbers:");
scanf("%d %d %d",&a,&b,&c);
if(a>b)
{
if(a>c)
printf("A is the greatest");
}
else if(b>c)
{
printf("B is the greatest");
}
else
{
printf("C is the greatest");
}
}
OUTPUT:
Enter the three numbers:45 53 15
B is the greatest
37 To check whether a year is leap or not(if else ladder)
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int a;
printf("Enter a year:");
scanf("%d",&a);
if(a%4==0)
{
printf("leap year");
}
else if(a%4<=3)
{
printf("not leap year");
}
else
{
printf("Invalid");
}
}
OUTPUT:
Enter a year:2024
leap year
38 Write a program to assign Grade using else if or ladder if
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int grade;
printf("Enter student mark ");
scanf("%d",&grade);
if(grade>90)
{
printf("A grade");
}
else if(grade>75&&grade<=90)
{
printf("B grade");
}
else if(grade>60&&grade<=75)
{
printf("C grade");
}
else if(grade>50&&grade<=60)
{
printf("D grade");
}

else
{
printf("Fail");
}
}
OUTPUT:
Enter student mark 78
B grade
39 Write a program to assign Grade using switch case
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int grade;
printf("Enter a mark:");
scanf("%d",&grade);
switch(grade/10)
{
case 10:
case 9:
{
printf("A grade");
break;
}
case 8:
{
printf("B grade");
break;
}
case 7:
{
printf("C grade");
break;
}
case 6:
{
printf("D grade");
break;
}
case 5:
{
printf("E grade");
break;
}
default:
{
printf("Fail");
}
}
}
OUTPUT:
Enter a mark:80
B grade
40 Calculator program using else if or ladder if
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
char op;
int a,b,c;
printf("Enter the operation");
scanf("%c",&op);
if(op=='+')
{
printf("Enter the two numbers");
scanf("%d %d",&a,&b);
c=a+b;
printf("%d",c);
}
else if(op=='-')
{
printf("Enter the two numbers");
scanf("%d %d",&a,&b);
c=a-b;
printf("%d",c);
}
else if(op=='*')
{
printf("Enter the two numbers");
scanf("%d %d",&a,&b);
c=a*b;
printf("%d",c);
}
else if(op=='/')
{
printf("Enter the two numbers");
scanf("%d %d",&a,&b);
c=a/b;
printf("%d",c);
}
else if(op=='%')
{
printf("Enter the two numbers");
scanf("%d %d",&a,&b);
c=a%b;
printf("%d",c);
}
else
{
printf("Invalid");
}
}
OUTPUT:
Enter the operation *
Enter the two numbers 5 3
15
41 Calculator program using switch
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
char op;
int a,b,c;
printf("Enter the operation ");
scanf("%c",&op);
switch(op)
{
case '+':
{
printf("enter the two values");
scanf("%d %d",&a,&b);
c=a+b;
printf("%d",c);
break;
}
case '-':
{
printf("Enter the two values");
scanf("%d %d",&a,&b);
c=a-b;
printf("%d",c);
break;
}
case '*':
{
printf("Enter the two numbers");
scanf("%d %d",&a,&b);
c=a*b;
printf("%d",c);
break;
}
case '/':
{
printf("Enter the two numbers");
scanf("%d %d",&a,&b);
c=a/b;
printf("%d",c);
break;
}
case '%':
{
printf("Enter the two numbers");
scanf("%d %d",&a,&b);
c=a%b;
printf("%d",c);
break;
}
default:
{
printf("Invalid");
break;
}
}
}
OUTPUT:
Enter the operation -
Enter the two numbers 64 43
21
42 To check whether a character is vowel or not(switch case)
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
char a;
printf("Enter an alphabet:");
scanf("%c",&a);
switch(a)
{
case 'a':
{
printf("It is a vowel");
break;
}
case 'e':
{
printf("It is a vowel");
break;
}
case 'i':
{
printf("It is a vowel");
break;
}
case 'o':
{
printf("It is a vowel");
break;
}
case 'u':
{
printf("It is a vowel");
break;
}
case 'A':
{
printf("It is a vowel");
break;
}
case 'E':
{
printf("It is a vowel");
break;
}
case 'I':
{
printf("It is a vowel");
break;
}
case 'O':
{
printf("It is a vowel");
break;
}
case 'U':
{
printf("It is a vowel");
break;
}
default:
{
printf("It is a consonant");
break;
}

}
}
OUTPUT:
Enter an alphabet:U
It is a vowel
43 Write a program to withdraw a certain amount from user account.
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int a,bal;
printf("Enter an amount:");
scanf("%d",&a);
bal=5000;
if(a<=bal)
{
printf("Money can be withdrawn");
}
else
{
printf("Money cannot be withdrawn");
}
}
OUTPUT:
Enter an amount:1000
Money can be withdrawn
44 Printing from 1 to 100 using for, while, do-while
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
for(i=1;i<=100;i++)
{
printf("%d\t",i);
}
}
OUTPUT:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
97 98 99 100

PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i;
i=1;
while(i<=100)
{
printf("%d\t",i);
i++;
}
}
OUTPUT:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
97 98 99 100

PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i;
i=1;
do
{
printf("%d\t",i);
i++;
}
while(i<=100);
}
OUTPUT:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
97 98 99 100
45 Print the even numbers in a specific range N using for, while, do-while
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,n;
printf("Enter the value of N:");
scanf("%d",&n);
for(i=2;i<=n;i=i+2)
{
printf("%d\n",i);
}
}
OUTPUT:
Enter the value of N:10
2
4
6
8
10
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,n;
printf("Enter the value of n:");
scanf("%d",&n);
i=2;
while(i<=n)
{
printf("%d\n",i);
i=i+2;
}
}
OUTPUT:
Enter the value of n:10
2
4
6
8
10
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,n;
printf("Enter the value of n:");
scanf("%d",&n);
i=2;
do
{
printf("%d\n",i);
i=i+2;
}
while(i<=n);
}
OUTPUT:
Enter the value of n:10
2
4
6
8
10
46 Write a program to Print sum of odd numbers of range N using for, while, do-while
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,sum=0,n;
printf("Enter the value of n:");
scanf("%d",&n);
for(i=1;i<=n;i=i+2)
{
sum=sum+i;
printf("%d\n",i);
}
printf("Sum is:%d",sum);
}
OUTPUT:
Enter the value of n:10
1
3
5
7
9
Sum is:25
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,n,sum=0;
printf("Enter the value of n:");
scanf("%d",&n);
i=1;
while(i<=n)
{
printf("%d\n",i);
sum=sum+i;
i=i+2;
}
printf("Sum is:%d",sum);
}
OUTPUT:
Enter the value of n:10
1
3
5
7
9
Sum is:25
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,n,sum=0;
printf("Enter the value of n:");
scanf("%d",&n);
i=1;
do
{
printf("%d\n",i);
sum=sum+i;
i=i+2;
}
while(i<=n);
printf("sum is:%d",sum);
}
OUTPUT:
Enter the value of n:10
1
3
5
7
9
sum is:25
47 Write a program to print Sum of numbers within a specific range N using for, while, do-while
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,sum=0,n;
printf("Enter n value:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+i;
printf("%d\n",i);
}
printf("Sum is:%d\n",sum);
printf("End");

}
OUTPUT:
Enter n value:10
1
2
3
4
5
6
7
8
9
10
Sum is:55
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,n,sum=0;
printf("Enter the value of n");
scanf("%d",&n);
i=1;
while(i<=n)
{
printf("%d\n",i);
sum=sum+i;
i++;
}
printf("Sum is:%d",sum);

}
OUTPUT:
Enter the value of n 10
1
2
3
4
5
6
7
8
9
10
Sum is:55
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,n,sum=0;
printf("Enter the value of n");
scanf("%d",&n);
i=1;
do
{
printf("%d\n",i);
sum=sum+i;
i++;
}
while(i<=n);
printf("Sum is:%d",sum);

}
OUTPUT:
Enter the value of n 10
1
2
3
4
5
6
7
8
9
10
Sum is:55
48 Write a program to print Sum of squares within a specific range N using for, while, do-while
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,n,sum=0;
printf("Enter the value of n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%d\n",i);
sum=sum+(i*i);
}
printf("Sum of squares:%d",sum);

}
OUTPUT:
Enter the value of n:4
1
2
3
4
Sum of squares:30
PROGRAM:
#include <stdio.h>
#include <stdlib.h>

int main()
{
int i,n,sum=0;
printf("Enter the n value:");
scanf("%d",&n);
i=1;
while(i<=n)
{
printf("%d\n",i);
sum=sum+(i*i);
i++;
}
printf("Sum is:%d",sum);
}
OUTPUT:
Enter the n value:4
1
2
3
4
Sum is:30
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,n,sum=0;
printf("Enter the value of n:");
scanf("%d",&n);
i=1;
do
{
printf("%d\n",i);
sum=sum+(i*i);
i++;
}
while(i<=n);
printf("Sum is:%d",sum);
}
OUTPUT:
Enter the value of n:4
1
2
3
4
Sum is:30
49 Write a program in C to display the sum of cube within a specific range N using for, while, do-while
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
int i,n,sum=0,a;
printf("Enter the value of n:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("%d\n",i);
a=pow(i,3);
sum=sum+a;
}
printf("Sum is:%d",sum);
}
OUTPUT:
Enter the value of n:4
1
2
3
4
Sum is:100
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
int i,n,a,sum=0;
printf("Enter the value of n:");
scanf("%d",&n);
i=1;
while(i<=n)
{
printf("%d\n",i);
a=pow(i,3);
sum=sum+a;
i++;
}
printf("Sum is:%d",sum);
}
OUTPUT:
Enter the value of n:4
1
2
3
4
Sum is:100
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
int i,n,a,sum=0;
printf("Enter the value of n:");
scanf("%d",&n);
i=1;
do
{
printf("%d\n",i);
a=pow(i,3);
sum=sum+a;
i++;
}
while(i<=n);
printf("Sum is:%d",sum);
}
OUTPUT:
Enter the value of n:4
1
2
3
4
Sum is:100

You might also like