Programming Exercises
Programming Exercises
Q #1: Write a program that read two integers from the keyboard and print their sum and
average.
Sample run:
Sum is 50
Average is 25
CODING
#include<iostream>
#include<conio.h>
int main()
int num1,num2,sum,average;
cin>>num1;
cin>>num2;
sum=num1+num2;
average=(num1+num2)/2;
cout<<"sum is "<<sum<<endl;
cout<<"average is "<<average<<endl;
return 0;
OUTPUT:
Q #1: Write a program that prompts for a person’s height in inches. Convert this height
Now, the value obtained can easily, be translated into feet and inches which are
Sample run:
CODING:
#include<iostream>
#include<conio.h>
int main()
int inch1,inch2,feet;
cin>>inch1;
feet=inch1/12;
inch2=inch1%12;
return 0;
SCREENSHOT:
Q #4: Write a program that calculates the temperature in Fahrenheit. For that it prompts
is Fahrenheit=Celsius (9/5+32). Once if the task done do the vice versa i.e.
Celsius=5/9(Fahrenheit -32)
#include<iostream>
#include<conio.h>
int main()
int farenhite,celcius,Farenhite,Celcius;
cin>>celcius;
farenhite=celcius* (9/5+32);
cout<<"Farenhite temperature is :"<<farenhite<<endl;
cin>>Farenhite;
Celcius=(5/184) *Farenhite;
return 0;
CODING:
OUTPUT:
Q #2: Write a program that prompts for time in seconds and output that time in hours,
minutes, and seconds. Here student will learn the usage of divide and modulus
Sample run:
Minutes in time: 1
CODING:
#include<iostream>
#include<conio.h>
int main()
int seconds,hour,minutes,n,n1;
cin>>n;
n1= n% (24*3600);
hour=n1/3600;
n%=3600;
minutes=n /60;
n%=60;
seconds=n;
return 0;
}
OUTPUT:
Q #3: Write a program that prompts for amount in rupees and show how many 1000’s,
Sample run:
CODING:
#include<iostream>
#include<conio.h>
int main()
int amt,R1000,R500,R100,R50,R10,R5,R2,R1,R20;
cin>>amt;
R1000=amt/1000;
R500=amt/500;
amt=amt%1000;
R100=amt/100;
amt=amt%1000;
R50=amt/50;
amt=amt%50;
R20=amt/20;
amt=amt%20;
R10=amt/10;
amt=amt%10;
R5=amt/5;
amt=amt%5;
R1=amt;
return 0;
OUTPUT:
Q #5: Write a program that inputs a two digit integer value, and output its reverse order.
Sample run:
CODING:
#include <iostream>
using namespace std;
int main() {
cin>>num;
while(num > 0) {
num = num/10;
return 0;
OUTPUT: