C Programs Answers
C Programs Answers
C Programs Answers
10. Write a program to input three integers and find maximum from these
integers.
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
void main()
{
int a,b,c;
cout<<"enter 1st integer:";
cin>>a;
cout<<"enter 2nd integer:";
cin>>b;
cout<<"enter 3rd integer:";
cin>>c;
if((a>=b)&(a>=c))
{
cout<<a<<"is greater than"<<b<<"and"<<c<<endl;
}
else
if((b>=a)&(b>=c))
{
cout<<b<<"is greater than"<<a<<"and"<<c<<endl;
}
else
if((c>=a)&(c>=b))
{
cout<<c<<"is greater than"<<a<<"and"<<b<<endl;
}
else{}
getch();
}
11. Write a program to input three integers and find minimum from these
integers.
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
void main()
{
int a,b,c;
cout<<"enter 1st integer:";
cin>>a;
cout<<"enter 2nd integer:";
cin>>b;
Total:
425
Answer
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a, b, c, d, e, f, g;
cout<<"Results"<<endl<<"========Quiz========"<<endl;
cout<<"Enter the score of the first quiz:";
cin>>a;
cout<<"Enter the score of the secind quiz:";
cin>>b;
cout<<"Enter tne score of the third quiz:";
cin>>c;
cout<<"========Mid-Term========"<<endl;
cout<<"Enter the score of mid-term:";
cin>>d;
cout<<"========Final========"<<endl;
cout<<"Enter the score of the final:";
cin>>e;
f=a+b+c;
cout<<"Quiz Total: "<<f<<endl<<"Mid-Term: "<<d<<endl<<"Final:
"<<e<<endl;
g=d+e+d;
cout<<"............................"<<endl<<"Total:
"<<g<<endl;
getch();
}
14. Write a C++ program that prompts the user to input three integer
values and find the greatest value of the three values.
Example:
Enter 3 integer vales separated by space: 10 15 20
The greatest value is: 20
Answer
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"Enter 1st integer:";
cin>>a;
cout<<"Enter the 2nd integer:";
cin>>b;
cout<<"Enter the 3rd integer:";
cin>>c;
cout<<"Enter interger seperated by space: "<<a<<" "<<b<<" "<<c<<endl;
if ((a>=b)&(a>=c))
{
cout<<"The greatest value is "<<a<<endl;
}
else if ((b>=a)&(b>=c))
{
cout<<"The greatest value is "<<b<<endl;
}
else if ((c>=b)&(c>=a))
{
cout<<"The greatest value is "<<c<<endl;
}
else{}
getch();
}
15. Write a program that determines a students grade. The program will
read three types of scores (quiz, mid-term, and final scores) and
determine the grade based on the following rules:
-if the average score =90% =>grade=A
-if the average score >= 70% and <90% => grade=B
-if the average score>=50% and <70% =>grade=C
-if the average score<50% =>grade=F
Answer
#include<iostream.h>
#include<conio.h>
void main()
{
float x=0;
float y=0;
float z=0;
float avg=0;
cout<<"Enter 3 score(quiz, mid-term and final) vales seperaed
by space:";
cin>>x>>y>>z;
avg=(x+y+z)/3;
if (avg>=90)
{
cout<<"GRADE=A";
}
else if ((avg<90)&(avg>=70))
{
cout<<"GRADE=B";
}
else if ((avg<70)&(avg>=50))
{
cout<<"GRADE=C";
}
else if (avg<50)
{
cout<<"GRADE=F";
}
getch();
}