EXP1
EXP1
NO - 1(A)
DATE : AREA OF CIRCLE
AIM :
To write a C program to calculate the area of circle .
ALGORITHM :
#include<stdio.h>
#include<conio.h>
# define pi 3.14
void main()
{
float radius,Area,Perimeter;
clrscr();
printf("Enter the Radius ");
scanf("%f",&radius);
Area=pi*radius*radius;
Perimeter=2*pi*radius;
printf("\n Area of the Circle is %f",Area); printf("\
n Perimeter of the Circle is %f",Perimeter);
getch();
}
OUTPUT :
RESULT :
Thus the C program to calculate the area of a circle has been executed successfully .
EX. NO - 1(B)
DATE : EVEN OR ODD NUMBER
AIM :
ALGORITHM :
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter The Number \n");
scanf("%d",&n);
if(n%2==0)
{
printf("The Given Number is %d is Even",n);
}
else
{
printf("The Given Number is %d is Odd" ,n);
}
getch();
}
OUTPUT :
Enter The
Number 5
The Given Number is 5 is Odd
RESULT :
Thus the C program to check the value is even or odd has been executed successfully .
EX. NO - 1(C)
DATE : BIGGEST OF THREE NUMBER
AIM :
To write a C program to find the biggest among three numbers .
ALGORITHM :
STEP 3: Compare all the values using if else condition and identify which is big.
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c;
clrscr();
printf("Enter Three Numbers\
n"); scanf("%d%d
%d",&a,&b,&c); if(a>b)
{
if(a>c)
printf(" A is Biggest Number");
else
printf("C is Biggest Number");
}
else
{
if(c>b)
printf( "C is Biggest Number");
else
printf("B is Biggest Number");
}
getch();
}
OUTPUT :
RESULT :
Thus the C program to find biggest of three numbers has been executed successfully .
EX. NO - 1(D)
DATE: QUADRATIC EQUATION
AIM :
To write a C program to find the roots of a quadratic equation.
ALGORITHM :
STEP 3: Calculate the values d=b2-4ac . According to the value of d calculate the roots .
STEP 4: Print the root value which can be either real & distinct or imaginary or real & equal
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a, b, c, d, root1, root2;
clrscr();
printf("Enter the values of a, b, c\n");
scanf("%f%f%f", &a, &b, &c);
if(a == 0 || b == 0 || c == 0)
{
printf("Error: Roots can't be determined");
}
else
{
d = (b * b) - (4.0 * a * c);
if(d > 0.00)
{
printf("Roots are real and distinct \n");
root1 = -b + sqrt(d) / (2.0 * a);
root2 = -b - sqrt(d) / (2.0 * a);
printf("Root1 = %f \nRoot2 = %f", root1, root2);
}
else if (d < 0.00)
{
printf("Roots are
imaginary"); root1 = -b / (2.0
* a) ;
root2 = sqrt(abs(d)) / (2.0 * a);
printf("Root1 = %f +i %f\n", root1, root2);
printf("Root2 = %f -i %f\n", root1, root2);
}
else if (d == 0.00)
{
printf("Roots are real and equal\n");
root1 = -b / (2.0 * a);
root2 = root1;
printf("Root1 = %f\n", root1);
printf("Root2 = %f\n", root2);
} }
getch();
}
OUTPUT :
RESULT :
Thus the C program to find the roots of a quadratic equation has been executed
Successfully .
EX. NO - 1(E)
DATE : FACTORIAL
AIM :
To write a C program to calculate the factorial of a number using recursion
ALGORITHM :
STEP 3: Loop the i values using for loop till the condition i<=n gets satisfied and go to
step 5.
#include<stdio.h>
#include<conio.h>
void main()
{
int fact=1,n,i;
clrscr();
printf("Enter the Number \n");
scanf("%d",&n); for(i=1;i<=n;i+
+)
{
fact=fact*i;
}
printf("The Factorial of %d is %d ", n,fact);
getch();
}
OUTPUT :
RESULT :
Thus , the C program to calculate factorial of a number has been executed successfully .
EX. NO - 1(F)
DATE : FIBONACCI SERIES
AIM :
To write a C program on Fibonacci series of numbers .
ALGORITHM :
STEP 3: Loop the i value using for loop , fill the condition i<num gets satisfied and go
to step 5
OUTPUT :
0
1
1
2
3
RESULT :
Thus , the C program to print the Fibonacci series has been executed successfully .
EX. NO - 1(G)
DATE : SUM OF DIGITS OF A GIVEN NUMBER
AIM :
To write a C program on sum of digits of a given numbers
ALGORITHM :
#include<stdio.h>
#include<conio.>
void main()
{
int Number, Reminder, Sum=0;
printf("\n Please Enter any number\
n"); scanf("%d", &Number);
while(Number > 0)
{
Reminder = Number % 10;
Sum = Sum+ Reminder;
Number = Number / 10;
}
printf("\n Sum of the digits of Given Number = %d", Sum);
getch();
}
OUTPUT :
Input : n = 687
Output : 21
Input : n = 12
Output : 3
RESULT :
Thus , the C program to calculate sum of digits of a given number has been executed
successfully .
EX. NO - 1(H)
DATE : CELSIUS TO FAHRENHEIT
AIM :
To write a C program to convert Celsius to Fahrenheit .
ALGORITHM :
#include<stdio.h>
void main()
{
float f,c ;
printf("Enter temperature in Celsius = ");
scanf("%f",&c);
f=((c*9) / 5) + 32 ;
printf(" \n Temperature in Fahrenheit = %f" , f );
}
OUTPUT :
RESULT :
Thus , the C program to convert Celsius to Fahrenheit has been executed successfully .
EX. NO - 1(I)
DATE : ARITHMETIC OPERATORS
AIM :
To write a C program to perform arithmetic operations .
ALGORITHM :
#include<stdio.h>
void main() {
int a=21;
int b=10;
int c;
c=a+b;
printf("Line 1 - value of c is %d \n ",c);
c=a-b;
printf("Line 2 – value of c is %d \n",c);
c=a*b;
printf("Line 3 – value of c is %d \n",c);
c=a/b;
printf("Line 4 – value of c is %d /n",c);
c=a%b;
printf("Line 5 – value of c is %d \n",c);
}
OUTPUT :
Line 1 – value of c is 31
Line 2 – value of c is 11
Line 3 – value of c is 210
Line 4 – value of c is 2
Line 5 – value of c is 1
RESULT :
Thus the C program to perform arithmetic operation has been executed
successfully .