Bangalore University
CA-C4P: Problem Solving Lab using C
1. program to read radius ofa circle and to find area and circumference
#include
#include
Hdefine PI 3.142
void main() Peet ens
{
uke firea of a circle = 78.55
double area,circum;
clrser():
printf("\n Enter radius of a circle :")
seant("%d",&r);
area=PI*r*1;
*PItr,
\n Area ofa circle =%0.21,area);
printf("\n Circumference ofa circle = %0.2If" circum);
getch():
2. Program to read three numbers and find biggest of three
# include
# include
# define MAX(a,b) (a>b ? a: b) en eee ee
void main()
a Oe
int a.b.c,.L1,L2:
clrscr()
printf("\n Enter three numbers(a,b,c)
"):scanf("%od %d %d" Sa, &b,&c);
LI=MAX(ab);
L2-MAX(.LI);
printi(’\n Biggest number = %d",L2):
getchQ;3. Program to check whether the number is prime or not
#include
#include
void main() re)
{ ere
int num,count=0.1;
clrser();
printf("\n Enter a number : ")
scanf("%ed" &num),
for(i=1:i<-num.i++)
if(aum%i-=0)
count++;
printf("\n Yd is a Prime number" mum):
else
printf("\n %d is not a Prime number” num);
getch();
}
4. C program to read a number, find the sum of the digits
reverse the number and check it for palindrome
# include
if include
void main()
{ Se eee Ce
int num.orgnum:
int sum=0,rev
clrscr();
printi("\n Enter a number
scanf("%d",&num):
orgnum=num;
while(num>0)
t
Tee)
rem: cea
rem=num%10;
su
um+rem,;
eee hoerev=rev* 10+rem: a a "| pe J
num=num/10; reece Tre
}
printi("\n Sum of digits = %d",sum);
printi(’\n Reversed number = %d" rev);
if(orgnum==rev)
printf("\n Number is a Palindrome");
else
printf("\n Number is not a Palindrome");
geich():
J
5. Program to read numbers from keyboard continuously till the user presses
999 and find the sum of only positive numbers
# include
# inchude
ater a mimber
void main() one
int num,sum=0; Tec ,
ener ene ts
do “Tr
{ wearers
printi("\n Enter a number : "); eer)
scant("%d" &enum): Se ara)
if(num > 0 && num!=999) eC)
sum er)
um + num;
printi("\n Sum = %d" sum);
}while(num!=999);
printf("\n You have pressed 999 : STOP");
getch();
;
}6. Program to read percentage of marks and to display appropriate message
Demonstration of (else-if) ladder
Percentage Grade
> 90% Exemplary
180% -90% Outstanding
170% -79% First Division with Distinction
11 60% -69% First Division
150% -59% Second Division
138% -49% Pass class
1<35% Fails : Re-appear
# include
# include
void main0)
£
float per;
clrser();
printf(’\n Enter Percentage : ");
scanf("%f" per); ¥
if(per > 90.0) 7 ra
pninti("\n Grade = EXEMPLARY");
else if(per >=80.0 && per < 90.0)
printi("\n Grade = OUTSTANDING")
else iff(per>=70.0 && per < 80.0)
printi("\n Grade = FIRST DIVISION WITH DISTINCTION");
else if(per >=60.0 && per <70.0)
printi("\n Grade = FIRST DIVISION");
else if(per >=50.0 && per < 60.0)
printf(’\n Grade = SECOND DIVISION")
else iffper >=35.0 && per < 50.0)
printi("\n Grade = PASS CLASS");
else
ptinti("\n Grade = FAILS : RE-APPEAR");
getchQ;7. Program to find roots of quadratic equation using Switch-Case
# include
# include
# include