Docsity

C++ Programs for Mathematical Operations and Decision Making, Study notes of C programming

Partial preview of the text

Download C++ Programs for Mathematical Operations and Decision Making and more Study notes C programming in PDF only on Docsity!

#include using namespace std; int main() { int num; cout <<"num = "; cin>>num; if (num >0) {if(num%2==0) cout << "the number is positive and even" ; else cout << "the number is positive and odd" ; } else {if(num%2==0) cout << "the number is negative and even" ; else cout << "the number is negative and odd" ; } return 0;

#include using namespace std; int main() { int n1, n2, n3, smallest, largest; cout << " Enter n1="; cin >> n1 ; cout << " Enter n2="; cin >> n2 ; cout << " Enter n3="; cin >> n3 ; if((n1 >= n2) && (n1 >= n3)) cout << "Largest number: " << n1<<endl; else if ((n2 >= n1) && (n2 >= n3)) cout << "Largest number: " << n2<<endl; else cout << "Largest number: " << n3<<endl; if((n1 <= n2) && (n1 <= n3)) cout << "Smallest number: " << n1<<endl; else if ((n2 <= n1) && (n2 <= n3)) cout << "Smallest number: " << n2<<endl; else cout << "Smallest number: " << n3<<endl; return 0;

#include #include <math.h> using namespace std; int main() { int X,Y; float W; cout <<"X = "; cin>>X; cout <<"Y = "; cin>>Y; if (X>0 && Y<0) { W=(X+Y); cout << "W= "<< W ; } else if (X==0 && Y>0) { W=(pow(X,2)pow(Y,3))+5X; cout << "W= "<< W ; } else if (X<0 && Y==0) { W=(2X/3Y)+4*X; cout << "W= "<< W ;

else cout << "Wrong entry" ; return 0; } //Q #include #include <math.h> using namespace std; int main() { float x,y; cout <<"x = "; cin>>x; switch (x>10) { case 1: { y=pow((pow(x,3)/2),4)-4; cout << "y= "<< y ; break; } default: { switch(x==10) { case 1: