C++ - Exercise...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Exercise 4 #include "stdafx.h" #include <iostream> using namespace std; int main () { int a, b, c, sum; cout << "Enter in a number. " ; cin>> a; cout << "Please enter another number. " ; cin>> b; cout << "Enter one more number. " ; cin>> c; sum = a + b + c; cout<< "The sum of the number is..." << sum; return 0; } Exercise 5 // cin & cout #include "stdafx.h" #include <iostream> using namespace std; int main () { int a, b, c, x, y; a=4; b=3; c=2; cin>>x; y=a*x*x+b*x+c; cout<<y; return 0; } Exercise 6 #include "stdafx.h" #include <iostream> using namespace std; int main () { int a, x, y; a=5; cin>>x; y=a*x*x*x+7; cout<<y; return 0; } Exercise 7 #include "stdafx.h" #include <iostream> using namespace std; int main () { int a,b,c; cin>>a; b=a*a; c=a*a*a; cout<<b<< "\n" ; cout<<c; return 0; } Exercise 8 #include "stdafx.h" #include <iostream> using namespace std; int main () { int a, b, c; cout<< "\nEnter a number..." ; cin>> a; cout << "\nEnter another number..." ; cin>>b; if (a>b) cout<< "\n" <<a<< "is larger\n" ; else cout<< "\n" <<b<< "is larger\n" ; return 0; } Exercise 9 #include "stdafx.h" #include <iostream> using namespace std; int main () { int a,b,c,d,e,s; cin>>a; cin>>b; cin>>c; cin>>d; cin>>e; if (a>b) s=a; else s=b; if (s>c) s=s; else s=c; if (s>d) s=s; else s=d; if (s>e) s=s; else s=e; cout<<s<< "is the largest\n" ; return 0; } Exercise 10 #include "stdafx.h" #include <iostream> using namespace std; int main () { int b, i, j, l; char ba; float ia; double ja; int la; l= sizeof (la); cout<< "The size of an integer is..." <<l<< '\n' ; b= sizeof (ba); cout<< "The size of a character is..." <<b<< '\n' ; i= sizeof (ia); cout<< "The size of a floating point is..." <<i<< '\n' ; j= sizeof (ja); cout<< "The size of a double precision floating point is..." <<j<< '\n' ; cout<< "Void is not a data type.\n" ; return 0; } Exercise 11 #include "stdafx.h" #include <iostream> using namespace std; int main () { int r, d, c, a; cout<< "What is the radius?\n" ; cin>>r; d=2*r; cout<< "The diameter is" <<d<< "\n" ; const float pi=3.14159; c=pi*d; cout<< "The circumference is" <<c<< "\n" ; a=pi*r*r; cout<< "The area is" <<a<< "\n" ; return 0; } Exercise 12 #include "stdafx.h" #include <iostream> using namespace std; int main () { int a, b; cout<< "Enter a number.." ; cin>>a; b=a%2; if (b==0) cout<< "The number is even.\n" ; else cout<< "The number is odd.\n" ; return 0; } Exercise 13 #include "stdafx.h" #include <iostream> using namespace std; int main () { int me, luv, him; cout<< "The first number is.." ; cin>>me; cout<< "The second number is.." ; cin>>luv; him=me%luv; if (him!=0) cout << "The first number is not multiple of the second number.\n" ; else cout << "The first number is a multiple of the second number.\n" ; return 0; } Exercise 14 #include "stdafx.h" #include <iostream> using namespace std; int main () { int n; char x; n= sizeof (x); cout<<n<< '\n' ; cin>>x; cout<< '\n' <<x<< '\n' ; cout<< static_cast < int >(x)<< '\n' ; //convert integer to Boolean number obtains the ASCII code...
View Full Document

Page1 / 19

C++ - Exercise...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online