Source Code Output includeiostream using namespace std int main int a b c d

Source code output includeiostream using namespace

This preview shows page 6 - 11 out of 40 pages.

Source Code Output #include<iostream> using namespace std; int main () { int a, b, c, d; cout<<"Enter 1st value: "; cin>>a; cout<<"Enter 2nd value: "; cin>>b; c=b; d=a; cout<<"Values before exchange is "<<a<<" and "<<b<<endl; cout<<"Values after exchange is "<<c<<" and "<<d; } Question No. 9 Write a program that inputs that inputs radius from the user and calculates the area and circumference of cube using formula Area = 𝝅? ? and Circumference = ? ? 𝝅? ? . Source Code Output #include<iostream> using namespace std; int main () { int A, r, circum; cout<<"Enter the radius: "; cin>>r; A=3.14*r*r;
Image of page 6
circum=1.333*(3.14*r*r*r); cout<<"Area of cube is "<<A<<endl; cout<<"Circumference of cube is "<<circum; } Question No. 10 Write a program that inputs a number from the user and displays it in reverse order. For example, if the user enters 123, it displays 321. Source Code Output #include<iostream> using namespace std; int main () { int n; cout<<"Enter a number: "; cin>>n; int num = n; while (n! = 0) { int r; r=n%10; cout<<r; n=n/10; } } Question No. 11 Write a program that inputs miles from the user and converts miles into kilometers. One mile is equal to 1.609km. Source Code Output #include<iostream> using namespace std; int main () { int dis;
Image of page 7
float km; cout<<"Enter the distance in mile: "; cin>>dis; km=dis/1.609; cout<<"The distance in kilometers is "<<km<<"km"; } Question No. 12 Write a program that finds area of triangle when three sides a, b, and c of the triangle are given. It inputs value of a, b, and c. Formula for the area of triangle is Area = √?(? − ?)(? − ?)(? − ?) . Source Code Output #include<iostream> #include<math.h> using namespace std; int main () { int a, b, c; float s; cout<<"Enter the three sides: "; cin>>a>>b>>c; s= (a+ b+ c)/2; cout<<"Area of triangle="<<sqrt (s*(s-a) *(s-b) *(s-c)); } Question No. 13 Write a program that inputs temperature in Fahrenheit and convert it into Celsius. Source Code Output #include<iostream> using namespace std; int main () {
Image of page 8
int tmp; float celsus; cout<<"Enter a temperature in Fahrenheit: "; cin>>tmp; celsus=0.56*tmp-32; cout<<"The temperature in Celsius is "<<celsus; } Question No. 14 Write a program that inputs number and find whether it is even or odd using if-else structure. Source Code Output #include<iostream> using namespace std; int main () { int x; cout<<"Enter a number: "; cin>>x; if(x%2==0) cout<<x<<" is even"; else cout<<x<<" is odd"; } Question No. 15 Write a program that inputs salary and grade. It adds 50% if grade is greater than 15. It adds 25% if grade is 15 or less then displays the salary. Source Code Output #include<iostream> using namespace std; int main () { int salary, gr;
Image of page 9
cout<<"Enter your salary: "; cin>>salary; cout<<"Enter your grade: "; cin>>gr; if(gr>15) { salary=salary+ salary*0.50; cout<<"Your salary is "<<salary; } else { salary=salary+ salary*0.25; cout<<"Your salary is "<<salary; } } Question No. 16 Write a program that inputs salary. If salary is 20000 or more. It deducts 7% of salary. If salary is 10000 or more or less than 20000, it deducts 1000. If salary is less than 10000, it deducts nothing and then displays net salary.
Image of page 10
Image of page 11

You've reached the end of your free preview.

Want to read all 40 pages?

  • Spring '16

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture