Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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

C++ code snippets for various mathematical operations and decision making tasks. The programs include determining if a number is positive or negative, finding the largest and smallest numbers among three given numbers, calculating the perfect weight for males and females based on height, and performing complex mathematical calculations. These programs can be used as study or reference materials for students and professionals learning C++ programming.

What you will learn

  • How does the second C++ program determine the largest and smallest numbers among three given numbers?
  • What is the purpose of the first C++ program in the document?

Typology: Study notes

2021/2022

Uploaded on 09/27/2022

picoo
picoo 🇮🇳

4.5

(13)

235 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
//Q1
#include <iostream>
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;
}
pf3
pf4
pf5

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: