You are on page 1of 10

Subject: Computer Programming

Branch: Mech
Assignment 1

Q1. Write a C++ program that inputs a student marks in three subjects (out of
100) and prints the percentage marks.

#include <iostream>
using namespace std;
int main()
{int m1,m2,m3,sum;float per;cout<<"Enter marks in 3 subjects out off
100"<<endl;
cin>>m1>>m2>>m3;
sum=m1+m2+m3;
per=(float)sum/3;
cout<<"percentage ="<<"   "<<per;
return 0;
}
Output:

Q.2 Write a C++ program that accepts a character between a to j and prints next 4
characters.

#include <iostream>
using namespace std;
int main()
{char ch,ch1,ch2,ch3,ch4;
cout<<"enter a letter between a to j"<<" ";
cin>>ch;
if(ch<='j')
{
ch1=ch+1;ch2=ch+2;ch3=ch+3;ch4=ch+4;
cout<<ch1<<" "<<endl<<ch2<<" "<<endl<<ch3<<" "<<endl<<ch4;}
else cout<<"Invalid Character";return 0;}
Output:
Q.3 Write a C++ program to convert a given number of days into years, weeks and
days.

#include <iostream>
using namespace std;
int main()
{int d,wk,yr,wd,yd;
cout<<"Enter no. of days"<<" ";
cin>>d;
wk=d/7;
yr=d/365;
wd=d%7;
yd=d%365;
cout<<"Weeks="<<" "<<wk<<" "<<"days"<<" "<<wd<<endl<<"Years="<<" "<<yr<<"
"<<"days"<<" "<<yd;
return 0;}
Output:
Q.4 Write a program to read two numbers and print their quotient and remainder.

#include <iostream>
using namespace std;
int main(){int x,y,rem;float qt;
cout<<"Enter any two integers no."<<" ";
cin>>x>>y;
qt=(float)x/y;
rem=x%y;
cout<<"Quotient="<<" "<<qt<<endl<<"Remainder="<<" "<<rem;
}

Output:
Q5. Write a program to find whether a given number is even or odd.

#include <iostream>
using namespace std;
int main() {int n;
    cout<<"enter a no."<<" ";
    cin>>n;
    if(n%2==0)
    cout<<"given no. is even";
    else cout<<"given no. is odd";
}
Output:
Q6. Write a program to find area of triangle. Take base and height from user.

#include <iostream>
using namespace std;
int main() {float b,h,at;
cout<<"Enter base and height of triangle"<<" ";
cin>>b>>h;
at=b*h*1/2;
cout<<"Area of triangle is="<<" "<<at;
return 0;
}

Output:
Q7. Write a program that asks for your height in centimeters and then
converts your height to feet and inches.(1 foot = 12 inches , 1 inch = 2.54 cm)

#include <iostream>
using namespace std;
int main()
{ float inch,cm,feet;
cout<<"Enter your height in cm"<<" ";
cin>>cm;
inch=cm/2.54;feet=inch/12;
cout<<"Height in feet is"<<" "<<feet<<endl<<"Height in inches is"<<"
"<<inch;
 return 0;
}

Output:

Q8. Write a program to convert given inches into its equivalent yards and feet.
(1 yard = 36 inches , 1 foot = 12 inches)
#include <iostream>
using namespace std;
int main(){float yrd,ft,l;
cout<<"Enter the no. of inches"<<" ";
cin>>l;
ft=l/12;yrd=l/36;
cout<<"Equivalent no. of yards="<<" "<<yrd<<endl<<"Equivalent no. of
feet is="<<" "<<ft;
return 0;
}
Output:
Q9. Write a C++ program that reads temperature in Celsius and displays it in
fahrenheit.

Hint . Fahrenheit = (1.8*Celsius)+32and celsius = (Fahrenheit -32)/1.8

#include <iostream>
using namespace std;
int main() {float c,f;
cout<<" enter temperature in degree celsius is ="<<" ";
cin>>c;
f=1.8*c+32;
cout<<"Temperature in degree farenhite is ="<<" "<<f;
  return 0;
}

Output:
Q10. Assuming that there are 7.418 gallons in a cubic foot, write a program
that asks the user to enter the number of gallons, and then display the
equivalent in cubic feet.
#include <iostream>
using namespace std;
int main() {float gall,cubft;
cout<<"Enter no. of gallons="<<" ";
cin>>gall;
cubft=gall/7.481;
cout<<"Equivalent cubic feet="<<" "<<cubft;
return 0;}
Output:

You might also like