C Program
C Program
DATE:
OBJECTIVE: Write a program to find a area of triangle using hero’s formula.
SOFTWARE USED: Turbo C
PROCEDURE:
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
clrscr();
float e,a,b,c,d,s;
printf("Enter sides of triangle :\n");
printf("Side a = ");scanf("%f",&a);
printf("Side b = ");scanf("%f",&b);
printf("Side c = ");scanf("%f",&c);
s=(a+b+c)/2;
d=s*(s-a)*(s-b)*(s-c);
e=sqrt(d);
printf("\nArea of triangle is %f",e);
getch();
OUTPUT:
CONCLUSION:
The program shows the area of triangle by using arithmetic operators and functions use in maths like
sqrt etc., defined in math.h.
SIGNATURE:
EXPERIMENT 2
DATE:
OBJECTIVE: Write a program to check number is prime or not.
SOFTWARE USED: Turbo C
PROCEDURE:
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int a,i,j,k=0;
printf("\nEnter a number to check whether it is prime or composite : ");
scanf("%d",&a);
j=a-1;
for (i=2;i<=j;i++)
{
if(a%i==0)
{
k=1;
}
}
if(k==1)
{
printf("The number is composite");
}
else
{
printf("The number is prime");
}
getch();
}
OUTPUT:
CONCLUSIONS:
The program shows whether the number is prime or not. For loop has been used.
SIGNATURE:
EXPERIMENT 3
DATE:
OBJECTIVE: Write a program to compute Armstrong Number (When Sum of Cubes of Digits Of
Number Equal to Same Given Number then the number is called as Armstrong Number)
temp = num;
while (num != 0)
{
rem = num % 10;
sum = sum + (rem*rem*rem);
num = num / 10;
}
if(temp == sum)
printf("n%d is Amstrong Number",temp);
else
printf("n%d is Amstrong Number",temp);
return(0);
}
OUTPUT:
Enter Number For Checking Armstrong : 153
153 is Amstrong Number
{
153 = [1*1*1] + [5*5*5] + [3*3*3]
= 1 + 125 + 27
= 153
}
CONCLUSION:
The program computes sum of the array elements using pointers
SIGNATURE:
EXPERIMENT 4
DATE:
CONCLUSION:
The program finds prime no.
SIGNATURE:
EXPERIMENT 5
DATE:
OBJECTIVE: Write a program to Swap two no’s without using third variable
void main()
{
int a,b;
clrscr();
a=a+b;
b=a-b;
a=a-b;
getch();
}
OUTPUT:
Enter value for num1 & num2 : 10 20
CONCLUSION:
The program finds factorial using recursion
SIGNATURE:
EXPERIMENT 6
DATE:
OBJECTIVE: Write a program to print first 10 natural no.s
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
while(i<=10)
{
printf("%d",i);
i++;
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
do{
printf("%d",i);
i++;
}while(i<=10);
getch();
}
OUTPUT:
The first 10 natural no.s are displayed
CONCLUSION:
The program finds factorial using recursion
SIGNATURE:
EXPERIMENT 7
DATE:
OBJECTIVE: Write a program to find Length of the String using Pointer
OUTPUT:
Enter the String : apaar
CONCLUSION:
The program finds length of string
SIGNATURE:
EXPERIMENT 8
DATE:
OBJECTIVE: Write a program to Add Two Numbers Using Pointer
printf("Sum = %d",num);
return(0);
}
OUTPUT:
Enter two numbers : 2 3
Sum = 5
SIGNATURE:
EXPERIMENT 9
DATE:
OUTPUT:
Enter the number : 5
Factorial of 5 is 120
CONCLUSION:
The program finds factorial using recursion
SIGNATURE:
EXPERIMENT 10
DATE:
OBJECTIVE: Write a program to compute sum of the array elements using pointers
printf("Enter 10 elements:n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
ptr = a; /* a=&a[0] */
for(i=0;i<10;i++)
{
sum = sum + *ptr; //*p=content pointed by 'ptr'
ptr++;
}
Enter 10 elements : 11 12 13 14 15 16 17 18 19 20
CONCLUSION:
The program computes sum of the array elements using pointers
SIGNATURE:
EXPERIMENT 11
DATE:
void main()
{
int a,b,c;
clrscr();
if((a>b)&&(a>c))
printf("na is greatest");
if((b>c)&&(b>a))
printf("nb is greatest");
if((c>a)&&(c>b))
printf("nc is greatest");
getch();
}
OUTPUT:
Enter value for a,b & c : 15 17 21
c is greatest
CONCLUSION:
The program computes greatest of 3 numbers
SIGNATURE
EXPERIMENT 12
DATE:
OBJECTIVE: Write a program to reverse a given number
void main()
{
int num,rem,rev=0;
clrscr();
while(num>=1)
{
rem = num % 10;
rev = rev * 10 + rem;
num = num / 10;
}
OUTPUT:
Enter any no to be reversed : 123
Reversed Number : 321
CONCLUSION:
The program reverses a given no.
SIGNATURE:
EXPERIMENT 13
DATE:
OBJECTIVE: Write a program to calculate sum of 5 subjects and find percentage
SOFTWARE USED: Turbo C
PROCEDURE:
#include<stdio.h>
#include<conio.h>
void main()
{
int s1,s2,s3,s4,s5,sum,total=500;
float per;
clrscr();
sum = s1 + s2 + s3 + s4 + s5;
printf("nSum : %d",sum);
printf("nPercentage : %f",per);
getch();
}
OUTPUT:
Enter 10 elements : 11 12 13 14 15 16 17 18 19 20
PROCEDURE:
#include<stdio.h>
#include<conio.h>
void main()
{
int s1,s2,s3,s4,s5,sum,total=500;
float per;
clrscr();
sum = s1 + s2 + s3 + s4 + s5;
printf("nSum : %d",sum);
printf("nPercentage : %f",per);
getch();
}
OUTPUT:
Enter marks of 5 subjects : 80 70 90 80 80
Sum : 400
Percentage : 80.00
CONCLUSION:
The program calculates sum of 5 subjects and find percentage
SIGNATURE
EXPERIMENT 15
DATE:
OBJECTIVE: Write a program to find factorial using recursion
OUTPUT:
OUTPUT
CONCLUSION:
The program shows the factorial of a number and also by defining its arithmetic operation in another
or user define function.
SIGNATURE:
EXPERIMENT 17
DATE:
OBJECTIVE: Write a program to display elements of array
SOFTWARE USED: Turbo C
PROCEDURE:
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,num[2][2];
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("Enter a value for %d%d place ",i,j);
scanf("%d",&num[i][j]);
}
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("You entered %d for %d%d place.\n",num[i][j],i,j);
}
}
getch();
}
OUTPUT:
CONCLUSION:
The program displays the elements of array ussing the function of array and for loop.
SIGNATURE:
EXPERIMENT 18
DATE:
OBJECTIVE: Write a program to calculate area of circle
SOFTWARE USED: Turbo C
PROCEDURE:
#include<stdio.h>
#include<conio.h>
void main()
float radius,area;
scanf("%d",&radius);
getch();
OUTPUT:
Enter the radius of Circle : 2.0
CONCLUSION:
The program calculates the area of a circle
SIGNATURE:
EXPERIMENT 19
DATE:
OBJECTIVE: Write a program to calculate area of rectangle
SOFTWARE USED: Turbo C
PROCEDURE:
#include<stdio.h>
#include<conio.h>
void main()
int length,breadth,side;
scanf("%d",&length);
scanf("%d",&breadth);
getch();
OUTPUT:
Enter the Length of Rectangle : 5
Area of Rectangle : 20
CONCLUSION:
The program calculates the area of a rectangle
SIGNATURE:
EXPERIMENT 20
DATE:
OBJECTIVE: Write a program to calculate area of square
SOFTWARE USED: Turbo C
PROCEDURE:
#include<stdio.h>
#include<conio.h>
void main()
int side,area;
scanf("%d",&side);
getch();
OUTPUT:
Enter the Length of Side : 5
Area of Square : 25
CONCLUSION:
The program calculates the area of a square
SIGNATURE: