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();
}


Write a program to convert a Fahrenheit to Celsius

Fahrenheit to Celsius(Celsius=(F-32)*5/9)

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

void main()
{
int f;
float cel;
clrscr();
printf("Enter the Fahrenheit value");
scanf("%d",&f);
cel=(f-32)*(float)5/9 ;
printf("The celsius:%.2f",&cel);
getch();
}

Write a program to convert a given number of days to a measure of time given in years weeks, and days. For example 375 days equals 1 year, 1week, and 3 days.

#include<stdio.h>
#include<conio.h>
void main()
{
int year=0,week=0;
long int day;
 clrscr();
 printf("Enter the number of days:");
 scanf("%ld",&day);
 year=day/365;
 day=day%365;
 week=day/7;
 day=day%7;
 printf("\nYear=%d   week=%d   day=%ld",year,week,day);
 getch();
}

This entry was posted in , . Bookmark the permalink.

Leave a reply