[go: up one dir, main page]

0% found this document useful (0 votes)
36 views19 pages

EXP1

C programming and Data Structures lab

Uploaded by

Anuja S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views19 pages

EXP1

C programming and Data Structures lab

Uploaded by

Anuja S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

EX.

NO - 1(A)
DATE : AREA OF CIRCLE

AIM :
To write a C program to calculate the area of circle .

ALGORITHM :

STEP 1: Start the program.

STEP 2: Enter the radius value.

STEP 3: Compute the Area & perimeter values.

STEP 4: Print the value.

STEP 5: Stop the program.


PROGRAM :

#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 :

Enter the Radius 5


Area of the Circle is 78.500000
Perimeter of the Circle is 31.40000

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 :

To write a C program to find whether the given number is even or odd .

ALGORITHM :

STEP 1: Start the program.

STEP 2: Get n value.

STEP 3: Check the given condition.

STEP 4: Print the value is whether even or odd number.

STEP 5: Stop the program.


PROGRAM :

#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 1: Start the program.

STEP 2: Get a, b and c values.

STEP 3: Compare all the values using if else condition and identify which is big.

STEP 4: Print the Biggest value.

STEP 5: Stop the program.


PROGRAM :

#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 :

Enter Three Numbers 5 8 6


B is Biggest Number

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 1: Start the program.

STEP 2: Get a, b, c, d, root1 & root2 values.

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

STEP 5: Stop the program.


PROGRAM :

#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 :

Enter the values of a, b, c


123
Roots are imaginary
Root1 = -1.000 + i
Root2 = -1.000 – i

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 1: Start the program.

STEP 2: Get n, i values.

STEP 3: Loop the i values using for loop till the condition i<=n gets satisfied and go to
step 5.

STEP 4: calculate fact = fact * i and step 3 is repeated..

STEP 5: Print fact value.

STEP 6: Stop the program.


PROGRAM :

#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 :

Enter the Number


7
The Factorial of 7 is 5040

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 1: Start the program.

STEP 2: Assign fib=0 , a=0 , b=1

STEP 3: Loop the i value using for loop , fill the condition i<num gets satisfied and go
to step 5

STEP 4: calculate fib=fib+a


a=b
b=fib

STEP 5: Print the value.

STEP 6: Stop the program


PROGRAM :
#include<stdio.h>
void main()
{
int num,fib=0,a=0,b=1,i;
printf("Enter the number");
scanf("%d",&num);
printf("\n FIBBONACI SERIES\n");
if(num==0)
printf("0");
else
{
for(i=0;i<num;i++)
{
fib=fib+a;
a=b;
b=fib;
printf("%d\t",fib);
}}}

OUTPUT :

Enter the number 5

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 :

STEP 1 : Start the program.

STEP 2 : Declare number , remainder , sum=0.

STEP 3 : check number>0 using while loop and calculate remainder=number%10 ,


sum=sum+remainder , number=number/10

STEP 4 : Repeat step 3 fill the condition fails.

STEP 5 : Print the sum of the digits.

STEP 6 : Stop the program.


PROGRAM :

#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 :

STEP 1: Start the program.

STEP 2: Get f and c value.

STEP 3: Assign f = ((c*a)(5) + 32) and compute it.

STEP 4: Print the temperature value.

STEP 5: Stop the program.


PROGRAM :

#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 :

Enter temperature in Celsius = 24


Temperature in Fahrenheit = 75.199997

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 :

STEP 1: Start the program.

STEP 2: Assign a=21 and b=10 & get value.

STEP 3: calculate a and b value using arithmetic operators (+, -, *, /, %).

STEP 4: Print the Calculated values.

STEP 5: Stop the program.


PROGRAM :

#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 .

You might also like