TO FIND THE AREA AND CIRCUMFERENCE OF THE CIRCLE
#include<stdio.h>
main()
{
float rad,area,circum;
clrscr();
printf("\nEnter the radius of the circle:");
scanf("%f",&rad);
area=3.14*rad*rad;
circum=2*3.14*rad;
printf("\nArea=%f",area);
printf("\nCircumference=%f",circum);
getch();
}
// Sample output:
Enter the radius of the circle
5
Area=78.500000
Circumference=31.400000
TO FIND THE FACTORIAL OF THE GIVEN NUMBER
#include<stdio.h>
main()
{
int fact=1,i,num;
clrscr();
printf("Enter the number:");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
fact=fact*i;
}
printf("The factorial of %d is %d",num,fact);
getch();
}
// Sample output:
Enter the number 5
The factorial of 5 is 120
TO FIND THE LARGEST OF THE THREE NUMBERS
#include<stdio.h>
main()
{
int a,b,c,big;
clrscr();
printf("Enter the three numbers:");
scanf("%d %d %d",&a,&b,&c);
big=a;
if(big<b)
big=b;
if(big<c)
big=c;
printf("The biggest of three number is %d",big);
getch();
}
// Sample output:
Enter the three numbers 93 43 23
The biggest of three number is 93
PROGRAM TO FIND THE SUM AND REVERSE OF THE GIVEN NUMBER
#include<stdio.h>
main()
{
unsigned long int a,num,sum=0,rnum=0,rem;
clrscr();
printf("\nEnter the number...");
scanf("%ld",&num);
a=num;
while(num!=0)
{
rem=num%10;
sum=sum+rem;
rnum=rnum*10+rem;
num=num/10;
}
printf("\nThe sum of the digits of %ld is %ld\n",a,sum);
printf("\nThe reverse number of the %ld is %ld",a,rnum);
if(a==rnum)
printf("\nThe given number is a palindrome");
else
printf("\nThe given number is not a palindrome");
getch();
}
//Sample output:
Enter the number...12321
The sum of the digits of 12321 is 9
The reverse number of the 12321 is 12321
The given number is a palindrome
#include<stdio.h>
main()
{
int num[100],no,i,j,a;
clrscr();
printf("Enter Upper Limit...");
scanf("%d",&no);
printf("Enter the numbers");
for(i=0;i<no;i++)
scanf("%d",&num[i]);
for(i=0;i<no-1;i++)
{
for(j=i+1;j<no;j++)
{
if(num[i]<num[j])
{
a=num[i];
num[i]=num[j];
num[j]=a;
}
}
}
printf("\nThe ascending order of the given numbers");
for(i=0;i<no;i++)
printf("\n%d",num[i]);
printf("\n The descending number of the given numbers");
for(j=no-1;j>=0;j--)
printf("\n%d",num[j]);
getch();
}
//Sample output:
Enter the number how many number you want to sort
5
Enter the numbers
10 30 50 6020
The ascending order of the given numbers
1020 30 50 60
The descending number of the given numbers
6050302010
MENU DRIVEN PROGRAM
#include<stdio.h>
#include<conio.h>
main()
{
int num,o,i;
long int fact;
clrscr();
while(1)
{
printf("\nEnter the number ");
scanf("%d",&num);
printf("\nchoose one of the options given below");
printf("\n 1.Factorial of the given number \n 2.Prime number or not\n 3. Odd or Even \n 4. Exit");
scanf("%d",&o);
switch(o)
{
case 1:
fact=1;
for(i=1;i<=num;i++)
fact=fact*i;
printf("The factorial of %d is %ld",num,fact);
break;
case 3:
if(num%2==0)
printf("The given number is Even number");
else
printf("The given number is Odd number");
break;
case 2:
i=2;
while(i<=num-1)
{
if(num%i==0)
{
printf("The given number is not a prime number");
break;
}
i++;
}
if(i==num)
printf("The given number is a prime");
break;
default:
exit(0);
}
}
getch();
}
//Sample output:
Enter the number .. 5
Choose one of the options given below
1. Factorial of the given number
2. Prime number or not
3. Odd or Even
4. Exit
1
The factorial of 5 is 120
Enter the number..5
Choose one of the options given below
1.Factorial of the given number
2.Prime number or not
3.Odd or Even
4.Exit
2
The given number is a prime
Enter the number...5
Choose one of the options given below
1.Factorial of the given number
2.Prime number or not
3.Odd or Even
4.Exit
4
STUDENT RECORD USING POINTER AND STRUCT
#include<stdio.h>
#include<conio.h>
main()
{
struct student
{
char name[25];
char regno[25];
int avg;
char grade;
} stud[50],*pt;
int i,no;
clrscr();
printf("Enter the number of the students...");
scanf("%d",&no);
for(i=0;i<no;i++)
{
printf("\n student[%d] information:\n",i+1);
printf("Enter the name");
scanf("%s",stud[i].name);
printf("\nEnter the roll no of the student");
scanf("%s",stud[i].regno);
printf("\nEnter the average value of the student");
scanf("%d",&stud[i].avg);
}
pt=stud;
for(pt=stud;pt<stud+no;pt++)
{
if(pt->avg<30)
pt->grade='D';
else if(pt->avg<50)
pt->grade='C';
else if(pt->avg<70)
pt->grade='B';
else
pt->grade='A';
}
printf("\n");
printf("NAME REGISTER-NO AVERAGE GRADE\n");
for(pt=stud;pt<stud+no;pt++)
{
printf("%-20s%-10s",pt->name,pt->regno);
printf("%10d \t %c\n",pt->avg,pt->grade);
}
getch();
}
//Sample output:
Enter the number of the students
3
student[1] information:
Enter the name MUNI
Enter the roll no of the student 100
Enter the average value of the student 95
student[2] information:
Enter the name LAK
Enter the roll no of the student 200
Enter the average value of the student 55
student[3] information:
Enter the name RAJA
Enter the roll no of the student 300
Enter the average value of the student 25
NAMEREGISTER-NOAVERAGEGRADE
MUNI10095A
LKA20055B
RAJA30025D
EMPLOYEE DETAILS USING UNION
#include<stdio.h>
#include<conio.h>
union uemf
{
char name[10];
int number;
float sal;
};
main()
{union uemf u1;
clrscr();
printf("Enter the employee name...");
scanf("%s",u1.name);
printf("%s",u1.name);
printf("\nEnter the employee number...");
scanf("%d",&u1.number);
printf("%d",u1.number);
printf("\nEnter the salary...");
scanf("%f",&u1.sal);
printf("\%f",u1.sal);
getch();
}
//Sample output:
Enter the Employee name: Manish
Manish
Enter the Employee number: 1111
1111
Enter the Salary: 34555
34555