You are on page 1of 3

1.

Write a C program to find area and perimeter of a rectangle


[Hint: area = length * breadth, Perimeter = 2(length + breadth)]

Solution :

// Program to find area and perimeter

#include<stdio.h>
void main()
{
float length,breadth,area,perimeter;
printf("enter the value of length\n");
scanf("%f",&length);
printf("enter the value of breadth\n");
scanf("%f",&breadth);
area=length*breadth;
perimeter = 2*(length+breadth);
printf("\narea = %f\n",area);
printf("\nperimeter = %f\n",perimeter);
getch();
}
2. Write a C program to calculate simple interest
Solution:
//C Program for Calculate Simple Interest

#include<stdio.h>
void main()
{
float p,r,n,si;
printf("\nEnter the profit, rate of interest and no of yr\n");
scanf("%f%f%f",&p,&r,&n);
si=(p*r*n)/100;
printf("\nSimple Interest=%f",si);
getch();
}

3. Write a C program to swap two integers

Solution:
//program to swap two numbers

#include <stdio.h>
void main()
{
int x, y, temp;
printf("Enter the value of x and y\n");
scanf("%d%d", &x, &y);
printf("Before Swapping\nx = %d\ny = %d\n",x,y);
temp = x;
x = y;
y = temp;
printf("After Swapping\nx = %d\ny = %d\n",x,y);
getch();

4. Write a C program to accept 5 fraction numbers (floating point numbers)


and find sum and average of the numbers

Solution :

//program to accept 5 fraction numbers and find sum and average


#include<stdio.h>
void main()
{
float m1,m2,m3,m4,m5,sum,average;
printf("enter the 5 floating numbers");
scanf("%f%f%f%f%f", &m1, &m2, &m3,&m4,&m5);
sum=m1+m2+m3+m4+m5;
average = sum/5;
printf("sum of 5 floating numbers= %f\n", sum);
printf("\naverage of 5 floating numbers = %f", average);
getch();
}

5. Program to convert temperature from degree centigrade to Fahrenheit

Solution:

//program to convert centigrade to fahrenheit


#include<stdio.h>
void main()
{
float celsius,fahrenheit;
printf("Enter temp in Celsius : ");
scanf("%f",&celsius);
fahrenheit = (1.8 * celsius) + 32;
printf("\nTemperature in Fahrenheit : %f ",fahrenheit);
getch();
}

You might also like