Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 27

EXPERIMENT 1

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)

SOFTWARE USED: Turbo C


PROCEDURE:
#include<stdio.h>
int main()
{
int num,temp,sum=0,rem;

printf("nEnter Number For Checking Armstrong : ");


scanf("%d",&num);

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:

OBJECTIVE: Write a program to check Whether Number is Prime or not

SOFTWARE USED: Turbo C


PROCEDURE:
#include<stdio.h>
int main()
{
int num,i,count=0;
printf("nEnter a number:");
scanf("%d",&num);
for(i=2;i<=num/2;i++){
if(num%i==0){
count++;
break;
}
}
if(count==0)
printf("%d is a prime number",num);
else
printf("%d is not a prime number",num);
return 0;
}

CONCLUSION:
The program finds prime no.

SIGNATURE:
EXPERIMENT 5
DATE:
OBJECTIVE: Write a program to Swap two no’s without using third variable

SOFTWARE USED: Turbo C


PROCEDURE:
#include<stdio.h>
#include<conio.h>

void main()
{
int a,b;

clrscr();

printf("nEnter value for num1 & num2 : ");


scanf("%d %d",&a,&b);

a=a+b;
b=a-b;
a=a-b;

printf("nAfter swapping value of a : %d",a);


printf("nAfter swapping value of b : %d",b);

getch();
}

OUTPUT:
Enter value for num1 & num2 : 10 20

After swapping value of a : 20


After swapping value of b : 10

CONCLUSION:
The program finds factorial using recursion

SIGNATURE:
EXPERIMENT 6
DATE:
OBJECTIVE: Write a program to print first 10 natural no.s

SOFTWARE USED: Turbo C


PROCEDURE:
Using For Loop
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
for(i=1;i<=10;i++)
printf("%d",i);
getch();
}
Using While Loop

#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
while(i<=10)
{
printf("%d",i);
i++;
}
getch();
}

Using Do-While Loop

#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

SOFTWARE USED: Turbo C


PROCEDURE:
#include<stdio.h>
#include<conio.h>
int string_ln(char*);
void main()
{
char str[20];
int l;
clrscr();
printf("Enter any string:n");
gets(str);
l=string_ln(str);
printf("The length of the given string %s is : %d",str,l);
getch();
}
int string_ln(char*p) /* p=&str[0] */
{
int count=0;
while(*p!='')
{
count++;
p++;
}
return count;
}

OUTPUT:
Enter the String : apaar

Length of the given string apaar is : 5

CONCLUSION:
The program finds length of string

SIGNATURE:
EXPERIMENT 8
DATE:
OBJECTIVE: Write a program to Add Two Numbers Using Pointer

SOFTWARE USED: Turbo C


PROCEDURE:
#include<stdio.h>
int main()
{
int *ptr1,*ptr2;
int num;

printf("nEnter two numbers : ");


scanf("%d %d",ptr1,ptr2);

num = *ptr1 + *ptr2;

printf("Sum = %d",num);
return(0);
}

OUTPUT:
Enter two numbers : 2 3
Sum = 5

CONCLUSION: The program finds factorial using recursion

SIGNATURE:
EXPERIMENT 9
DATE:

OBJECTIVE: Write a program to Find Factorial of Number Using Recursion

SOFTWARE USED: Turbo C


PROCEDURE:
include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int x,n;
printf("nEnter the value of n :");
scanf("%d",&n);
x=fact(n);
printf("n%d",x);
getch();
}
int fact(int n)
{
if(n==0)
return(1);
return(n*fact(n-1));
}

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

SOFTWARE USED: Turbo C


PROCEDURE:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10];
int i,sum=0;
int *ptr;

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++;
}

printf("The sum of array elements is %d",sum);


}
OUTPUT:

Enter 10 elements : 11 12 13 14 15 16 17 18 19 20

The sum of array elements is 155

CONCLUSION:
The program computes sum of the array elements using pointers

SIGNATURE:
EXPERIMENT 11
DATE:

OBJECTIVE: Write a program to find greatest in 3 numbers


SOFTWARE USED: Turbo C
PROCEDURE:
#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,c;
clrscr();

printf("nEnter value of a, b & c: ");


scanf("%d %d %d",&a,&b,&c);

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

SOFTWARE USED: Turbo C


PROCEDURE:
#include<stdio.h>
#include<conio.h>

void main()
{
int num,rem,rev=0;
clrscr();

printf("nEnter any no to be reversed : ");


scanf("%d",&num);

while(num>=1)
{
rem = num % 10;
rev = rev * 10 + rem;
num = num / 10;
}

printf("nReversed Number : %d",rev);


getch();
}

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();

printf("nEnter marks of 5 subjects : ");


scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);

sum = s1 + s2 + s3 + s4 + s5;

printf("nSum : %d",sum);

per = (sum * 100) / total;

printf("nPercentage : %f",per);
getch();
}

OUTPUT:

Enter 10 elements : 11 12 13 14 15 16 17 18 19 20

The sum of array elements is 155

CONCLUSION:The program computes sum of the array elements using pointers


SIGNATURE:
EXPERIMENT 14
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();

printf("nEnter marks of 5 subjects : ");


scanf("%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5);

sum = s1 + s2 + s3 + s4 + s5;

printf("nSum : %d",sum);

per = (sum * 100) / total;

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

SOFTWARE USED: Turbo C


PROCEDURE:
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int x,n;
printf("nEnter the value of n :");
scanf("%d",&n);
x=fact(n);
printf("n%d",x);
getch();
}
int fact(int n)
{
if(n==0)
return(1);
return(n*fact(n-1));
}

OUTPUT:

CONCLUSION:The program finds factorial using recursion


SIGNATURE:
EXPERIMENT 16
DATE:
OBJECTIVE: Find the factorial of a number using function
SOFTWARE USED: Turbo C
PROCEDURE:
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
void fact();
fact();
getch();
}
void fact()
{
int a,b,c=1;
printf("Enter a number : ");scanf("%d",&a);
for(b=1;b<=a;b++)
{
c=c*b;
}
printf("The factorial of number is: %d",c);
};

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;

clrscr(); // Clear Screen

printf("Enter the radius of Circle : ");

scanf("%d",&radius);

area = 3.14 * radius * radius;

printf("Area of Circle : %f",area);

getch();

OUTPUT:
Enter the radius of Circle : 2.0

Area of Circle : 12.56

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;

clrscr(); // Clear Screen

printf("Enter the Length of Rectangle : ");

scanf("%d",&length);

printf("Enter the Breadth of Rectangle : ");

scanf("%d",&breadth);

area = length * breadth;

printf("Area of Rectangle : %d",area);

getch();

OUTPUT:
Enter the Length of Rectangle : 5

Enter the Breadth of Rectangle : 4

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;

clrscr(); // Clear Screen

printf("nEnter the Length of Side : ");

scanf("%d",&side);

area = side * side ;

printf("nArea of Square : %d",area);

getch();

OUTPUT:
Enter the Length of Side : 5

Area of Square : 25

CONCLUSION:
The program calculates the area of a square

SIGNATURE:

You might also like