C Programming - Lab-A
C Programming - Lab-A
Murugan K
GFGC, K R Puram
Lab Manual
Part - A
1. Program to read radius of a circle and to find area and circumference.
Program:
/* Program to find area and circumference of the circle */
#include<stdio.h>
#include<conio.h>
void main()
{
int r;
float area, cir;
clrscr();
printf("\n Enter the radius of Circle : ");
scanf("%d", &r);
area = 3.14 * r * r;
cir=2 * 3.14 * r;
printf("\n Area of Circle : %.2f", area);
printf("\n Circumference of Circle : %.2f", cir);
getch();
}
Output:
Trace
Enter the radius of Circle: 5
4. Program to read a number, find the sum of the digits, reverse the number and check it
for palindrome.
Program:
/* Program to find sum of the digits, reverse the number and
check it for palindrome */
#include<stdio.h>
#include<conio.h>
void main()
{
long int n,r,x,rnum=0,sum=0;
clrscr();
printf("\n Enter a Number: ");
scanf("%ld",&n);
x=n;
while(n>0)
{
r=n%10;
sum=sum+r;
rnum=rnum*10+r;
n=n/10;
}
printf("\n Sum of digits of %ld is %ld",x,sum);
printf("\n Reverse Number of %ld is %ld",x, rnum);
if(x==rnum)
printf("\n %ld is Palindrome",x);
else
printf("\n %ld is Not a Palindrome",x);
Dr. Murugan K
GFGC, K R Puram
getch();
}
Output:
Trace 1
Enter a Number: 343
A+ Grade