Lab Manual4,5
Lab Manual4,5
Lab Manual4,5
PROGRAM:
#include<stdio.h>
#include<conio.h>
void 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:
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
float ft , ct; // ft stands for fahrenheit temprature.
// ct stands for celsius temprature.
clrscr();
printf("Enter the temprature in fahrenheit/n");
scanf("%f" , &ft);
ct=(ft-32)/18; // Formula of Celsius
printf("Fahrenheit temprature = %f/n" , ft);
printf("Celsius temprature = %f/n" ,ct);
getch()
}
SAMPLE OUTPUT:
Enter the temperature in Fahrenheit
64
Fahrenheit temperature = 64
Celsius temperature = 1.777
4.c) SWAPPING OF 2 NOS USING TEMPORARY VARIABLES
PROGRAM:
#include<stdio.h>
#include<conio.h>
int main()
{
int a, b, temp;
clrscr();
printf("En ter the value of a and b: \n");
scanf("%d %d",&a,&b);
printf("Be fore swapping a=%d, b=%d \n", a, b);
/*Swapping logic */
temp = a;
a = b;
b = temp;
printf("After swapping a=%d, b=%d", a, b);
getch();
return 0;
}
SAMPLE OUTPUT:
Enter the values of a and b: 2 3
Before swapping a=2, b=3
After swapping a=3, b=2
4.d) SWAPPING OF 2 NOS WITHOUT USING TEMPORARY VARIABLES
PROGRAM:
#include<stdio.h>
#include<conio.h>
int main()
{
int a, b;
clrscr();
printf("En ter values of a and b: \n");
scanf("%d%d",&a,&b);
printf("Before swapping a=%d, b=%d\n", a,b);
/*Swapping logic */
a = a + b;
b = a - b;
a = a - b;
printf("The values After swapping are a=%d b=%d\n", a, b);
getch();
return 0;
}
SAMPLE OUTPUT:
PROGRAM:
SAMPLE OUTPUT:
Enter a,b,c: 3 5 8
c is Greater than a and b
EXERCISE – 5
PROGRAM
OUTPUT:-
SAMPLE OUTPUT
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int no,i;
float x, a, sum,b;
clrscr();
printf("Enter the numbers");
scanf("%f %d",&x,&no);
b=x;
x=x*3.141/180;
a=x;
sum=x;
for(i=1;i<no+1;i++)
{
a= (a*pow((double)(-1),(double)(2*i-1))*x*x)/(2*i*(2*i+1));
sum=sum+a;
}
printf("Sine(%f) value is %f",b,sum);
getch();
}
OUTPUT:
PROGRAM:
#include<stdio.h>
#include<conio.h>
main()
{
int i,j,l,m,n;
clrscr();
printf("How many rows?\n");
scanf("%d",&n);
printf("\n\t\t\t\t Pascal’s Triangle\n");
m=1;
for(l=0;l<n;l++)
{
for(i=40-3*l;i>0;i--)
printf(" ");
for(j=0;j<=l;j++)
{
if((j==0)||(l==0))
m=1;
else
m=(m*(l-j+1))/j;
printf("%6d",m);
}
printf("\n");
}
getch();
}
OUTPUT:-
How many rows?
5 Pascal’s Triangle
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
AMSTRONG NUMBER
#include <stdio.h>
#include<conio.h>
int main()
{
int n, n1, rem, num=0;
printf("Enter a positive integer: ");
scanf("%d", &n);
n1=n;
while(n1!=0)
{
rem=n1%10;
num+=rem*rem*rem;
n1/=10;
}
if(num==n)
printf("%d is an Armstrong number.",n);
else
printf("%d is not an Armstrong number.",n);
getch();
return 0;
}
SAMPLE OUTPUT:
PROGRAM
#include <stdio.h>
int main()
{
int year;
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0) /* Checking for a century year */
{
if ( year%400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
}
else
printf("%d is a leap year.", year );
}
else
printf("%d is not a leap year.", year);
return 0;
}
SAMPLE OUTPUT
PROGRAM
# include <stdio.h>
int main()
{
char operator;
float num1,num2;
printf("Enter operator either + or - or * or divide :
scanf("%c",&operator);
printf("Enter two operands: ");
scanf("%f%f",&num1,&num2);
switch(operator)
{
case '+':
printf("num1+num2=%.2f",num1+num2);
break;
case '-':
printf("num1-num2=%.2f",num1-num2);
break;
case '*':
printf("num1*num2=%.2f",num1*num2);
break;
case '/':
printf("num2/num1 = %.2f",num1/num2);
break;
default: /* If operator is other than +, -, * or /, error message is shown */
printf("Error! operator is not correct");
break;
}
getch();
return 0;
}
SAMPLE OUTPUT