Pages

Saturday, November 12, 2011

Program to calculate area,perimeter of rectangle and circumference ,area of circle (Ref:Let us c-chapter1)

This program calculates the area and perimeter of a rectangle and circumference and area of a circle.

The length and breadth of a rectangle and radius of a circle are input through the keyboard.Write a program to calculate the area and perimeter of the rectangle,and the area and circumference of the circle.

#include<stdio.h>


void main()
{

float length,breadth,radius,rec_area,circle_area,perimeter,circumference;

clrscr();

printf("Enter length and breath for rectangle:");
scanf("%f%f",&length,&breadth);

printf("Enter radius for circle:");
scanf("%f",&radius);

rec_area=length*breadth;
perimeter=2*(length+breadth);

circle_area=3.14*radius*radius;
circumference= 2*3.14*radius;

printf("\n\nArea of rectancle is : %f",rec_area);
printf("\n\nPerimeter of rectangle is : %f",perimeter);

printf("\n\nArea of circle is : %f",circle_area);
printf("\n\nCircumference of circle is : %f",circumference);

getch();

}

Program to convert Farenhite temperature into Celcius temperature and vice-versa (Ref:Let us c-chapter1)

This program convert entered Farenhite temperature into centigrade temperature or vice-versa.


Temperature of a city in Farenhite degrees is input through the keyboard.Write a program to convert this temperature into centigrade degrees.


Note:To convert Fahrenheit to Celsius, subtract 32 degrees  and divide by 1.8.
while for converting Celsius to Fahrenheit, multiply by 1.8 and add 32 degrees


#include<stdio.h>


void main()


{


float temp_f,temp_c;


clrscr();


printf("Enter the value of temperature in Celcius:");


scanf("%f",&temp_c);


temp_f=(1.8*temp_c)+32;


printf("The value of temperature in Fahrenheit is :%f",temp_f);


getch();


}

Monday, November 07, 2011

Program for aggregate marks and percentage calculation
(Ref: Let us c-chapter1)


This program calculates the total and percentage marks.


If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.




#include<stdio.h>


void main()
{
int m1,m2,m3,m4,m5,total;
float prcnt;
clrscr();
printf("Enter marks for first subject:");
scanf("%d",&m1);
printf("Enter marks for second subject:");
scanf("%d",&m2);
printf("Enter marks for third subject:");
scanf("%d",&m3);
printf("Enter marks for fourth subject:");
scanf("%d",&m4);
printf("Enter marks for fifth subject:");
scanf("%d",&m5);
total=m1+m2+m3+m4+m5;
prcnt=total/5;
printf("Total marks obtained by the student is :%d",total);
printf("\nPercentage is:%f ",prcnt);


getch();


}