Professional Documents
Culture Documents
Week 2&3 Lab Solution
Week 2&3 Lab Solution
Solution :
#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();
}
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();
Solution :
Solution: