Showing posts with label Area of Circle. Show all posts

Exercise and solved in C language

Write a program to swap two numbers.

        Answer:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("Enter the value for a: ");
scanf("%d",&a);
printf("Enter the value for b: ");
scanf("%d",&b);
temp=a;
a=b;
b=temp;
printf("\n Swaping of two numbers a=%d \t b=%d",a,b);
getch();
} 





Write a program to find area of circle (radius is input by the keyboard)

#include<stdio.h>
#include<conio.h>
#define PI 3.14
void main()
{
int r;
float area;
clrscr();
printf("Enter the radius of the circle");
scanf("%d",&r);
area=PI * r * r;
printf("The Area of the circle is %f",area);
getch();
}



Write a program to find area of triangle and rectangle. 

#include<stdio.h>
#include<conio.h>

void main()
{
int tri_hight,tri_breadth,rect_hight,rect_breadth;
float area_tri,area_rect;
clrscr();
printf("Enter the Hight and Breadth of Rectangle: ");
scanf("%d%d",&tri_hight,&tri_breadth); 
printf("Enter the Hight and Breadth of the triangle: ");
scanf("%d%d",&rect_hight,&rect_breadth);
area_tri=0.5 * tri_hight * tri_breadth;
area_rect=rect_hight * rect_breadth;
printf("\nThe Area of the Triangle: %.2f",area_tri);
printf("\nThe Area of the Rectangle: %.2f",area_rect);
getch();
}


Write a program to find Total marks & percentage of the 6 subjects marks.

#include<stdio.h>
#include<conio.h>

void main()
{
int s1,s2,s3,s4,s5,s6,total;
float avg;
clrscr();
printf("Enter the 6 subjects marks: " );
scanf("%d%d%d%d%d%d",&s1,&s2,&s3,&s4,&s5,&s6);
total=s1+s2+s3+s4+s5+s6;
avg=(float)total/6;
printf("\nTotal marks of the 6 subjects: %d",total);
printf("\nAverage marks of the 6 subjects: %.2f",avg);
getch();
}

Posted in , | Leave a comment