








































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









































Write a program to define two integer variables containing 3 and 5, then calculate their sum and their product and display the result. You must use comments. Inputs: None Outputs: sum, product Formula: sum = first + second Product = first * second Constants: first=3, second = // This program calculates the sum and product of 3 and 5 #include using namespace std; int main() { int first, second, sum, product; //declaring variables first = 3; second = 5; sum = first + second ; //calculaĘng sum product = first * second; //calculaĘng product cout<<āThe sum is ā<< sum<<ā \nā; cout<<āThe product is ā<< product<<ā \nā; return 0 ; }
#include using namespace std; int main() { int No1, No2, Temp; cout<<"Enter two numbers\n"; cin>>No1>>No2; cout<<"Before Swapping\n"; cout<<"1st Number is:"< āArithmeĘc expressionsā
ļ An expression is a valid arrangement of variables, constants, and operators. ļ C++ applies the operators in arithmetic expressions in a precise sequence determined by the following rules of operator precedence, which are generally the same as those in algebra:
( )
#include
2
Inputs: a, b, c Outputs: R1, R Formula: d = pow(b,2) ā 4 * a * c; R1 = (-b + sqrt(d)) / (2 * a); R2 = (-b - sqrt(d)) / (2 * a); Constants: None
#include #include int main() { using namespace std; double a,b,c,d,x1,x2; cout<<"Enter the equaĘon coefficients:"; cin>>a>>b>>c; d=(bb-4ac); if (d<0) cout<<"The two roots are imaginary"; else { d=sqrt(d); x1=(-b+d)/(2a); x2=(-b-d)/(2*a); cout<<"The two roots are"<<"\n"; cout< Making Decisions (selecĘon) - II SWITCH Statement
Switch (variable) { case constant_1: acĘon_1; break; case constant_2: acĘon_2; break; case constant_3: acĘon_3; break; default: acĘon_4; }