This program calculates sum of five digit number enterd through keyboard
If a five-digit number is input through the keyboard,write a program to calculate the sum of its digits
#include<stdio.h>
void main()
{
int num,next_num,last_num,total;
clrscr();
printf("Enter the number : ");
scanf("%d",&num);
last_num=num%10;
total=last_num;
next_num=(num/10)%10;
total=total+next_num;
next_num=(num/100)%10;
total=total+next_num;
next_num=(num/1000)%10;
total=total+next_num;
next_num=(num/10000)%10;
total=total+next_num;
printf("\nThe sum of entered 5 digit number is : %d",total);
getch();
}
Friday, December 16, 2011
Program to interchange two values
This program interchanges two values input through keyboard
Two numbers are input through the keyboard into two locations C and D.Write a program to interchange the contents of C and D
#include<stdio.h>
void main()
{
int C,D,temp;
clrscr();
printf("Enter value of C and D :");
scanf("%d %d",&C,&D);
temp=C;
C=D;
D=temp;
printf("\nThe interchanged value of C and D are %d %d",C,D);
getch();
}
Two numbers are input through the keyboard into two locations C and D.Write a program to interchange the contents of C and D
#include<stdio.h>
void main()
{
int C,D,temp;
clrscr();
printf("Enter value of C and D :");
scanf("%d %d",&C,&D);
temp=C;
C=D;
D=temp;
printf("\nThe interchanged value of C and D are %d %d",C,D);
getch();
}
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();
}
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();
}
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();
}
(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();
}
Monday, June 27, 2011
Distance Converter Program(Ref: Let us c-chapter1)
This program converts the entered value into meters,feet,inches and centimeters
The distance between two cities (in km) is input through the keyboard. Write a program to convert and print this distance in meters,feet,inches and centimeters.
#include<stdio.h>
/*
1 kilometer=39370 inches
1 kilometer=3281 Feet
1 kilometer=100000 centimeters
1 kilometer=1000 meters
*/
void main()
{
float km,meter,feet,inches,centimeter;
clrscr();
printf("Enter the distance between two cities:");
scanf("%f",&km);
meter=1000*km;
centimeter=100000*km;
inches=39370*km;
feet=3281*km;
printf("\nThe Entered distance between two cities in meter is:%f",meter);
printf("\nThe Entered distance between two cities in centimeter is:%f",centimeter);
printf("\nThe Entered distance between two cities in inches is:%f",inches);
printf("\nThe Entered distance between two cities in feet is:%f",feet);
getch();
}
This program converts the entered value into meters,feet,inches and centimeters
The distance between two cities (in km) is input through the keyboard. Write a program to convert and print this distance in meters,feet,inches and centimeters.
#include<stdio.h>
/*
1 kilometer=39370 inches
1 kilometer=3281 Feet
1 kilometer=100000 centimeters
1 kilometer=1000 meters
*/
void main()
{
float km,meter,feet,inches,centimeter;
clrscr();
printf("Enter the distance between two cities:");
scanf("%f",&km);
meter=1000*km;
centimeter=100000*km;
inches=39370*km;
feet=3281*km;
printf("\nThe Entered distance between two cities in meter is:%f",meter);
printf("\nThe Entered distance between two cities in centimeter is:%f",centimeter);
printf("\nThe Entered distance between two cities in inches is:%f",inches);
printf("\nThe Entered distance between two cities in feet is:%f",feet);
getch();
}
Gross Salary Program(Ref: Let us c-chapter1)
This program calculate gross salary of an employee if his basic slaray is input thru keyboard.
Ramesh's basic salary is input throught the keyboard.His dearness allowance is 40% of basic salary,and house rent allowance is 20% of basic salary.Write a program to calclate gross salary.
#include<stdio.h>
void main()
{
float bs,gs,hra,da;
clrscr();
printf("Enter basic salary:");
scanf("%f",&bs);
hra=bs*20/100;
da=bs*40/100;
gs=bs+hra+da;
printf("Gross salary= %f",gs);
getch();
}
This program calculate gross salary of an employee if his basic slaray is input thru keyboard.
Ramesh's basic salary is input throught the keyboard.His dearness allowance is 40% of basic salary,and house rent allowance is 20% of basic salary.Write a program to calclate gross salary.
#include<stdio.h>
void main()
{
float bs,gs,hra,da;
clrscr();
printf("Enter basic salary:");
scanf("%f",&bs);
hra=bs*20/100;
da=bs*40/100;
gs=bs+hra+da;
printf("Gross salary= %f",gs);
getch();
}
Subscribe to:
Posts (Atom)