0% found this document useful (0 votes)
9 views4 pages

Lab Exercise

Uploaded by

cudarun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

Lab Exercise

Uploaded by

cudarun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

LAB EXERCISE

1. Write a program which calculates the sum and product of two numbers if the first number is greater
than the second one. Use if statement.
2. Write a program which calculate a function F where F is equal to
x+y if n>0
x+y if n<=0 where x,y and n are inputs. Use if else
3. Write a program that display with the following mood (Use SWITCH)
D or d for drama
R or r for romantic
S or s for suspense
A or a for adventure
4. Write a program that count down from the given input number n upto zero (while loop)
5. Write a program that sum the numbers you entered until you enter zero (do while)
6. Write a program that evaluate the sum of first n th odd number(For loop)

LAB EXERCISE
1. Write a program which calculates the sum and product of two numbers if the first number is greater
than the second one. Use if statement.
2. Write a program which calculate a function F where F is equal to
x+y if n>0
x+y if n<=0 where x,y and n are inputs. Use if else
3. Write a program that display with the following mood (Use SWITCH)
D or d for drama
R or r for romantic
S or s for suspense
A or a for adventure
4. Write a program that count down from the given input number n upto zero (while loop)
5. Write a program that sum the numbers you entered until you enter zero (do while)
6. Write a program that evaluate the sum of first n th odd number(For loop)
LAB EXERCISE
1. Write a program which calculates the sum and product of two numbers if the first number is
greater than the second one. Use if statement.
#include <iostream>
using namespace std;
int main() {
int n1,n2,n3;
cout << "Enter two numbers: ";
cin >> n1>>n2;
if (n1>n2)
{
n3= n1+n2;
cout << "The sum of two numbers is "<< n3 << endl;
n3= n1*n2;
cout << "The Product of two numbers is "<< n3 << endl;

}
return 0;
}
2. Write a program which calculate a function F where F is equal to
x+y if n>0
x+y if n<=0 where x,y and n are inputs. Use if else
#include <iostream>
using namespace std;
int main() {
int x,y,n,f;
cout << "Enter x,y,n: ";
cin >> x>>y>>n;
if (n<=0)
{
f= x-y;
cout << "The value of f is "<< f << endl;
}
else{
f= x+y;
cout << "The value of f is "<< f << endl;
}

return 0;
}
3. Write a program that display with the following mood (Use SWITCH)
D or d for drama
R or r for romantic
S or s for suspense
A or a for adventure
#include <iostream>
using namespace std;
int main() {
char n;
cout<<"Enter D,R,S,A"<<endl;
cin>>n;
switch(n)
{
case'd':case'D':cout<<"Drama";break;
case'r':case'R':cout<<"Romance";break;
case's':case'S':cout<<"Suspense";break;
case'a':case'A':cout<<"Action";break;
default:cout<<"invalid letter";
}
return 0;
}
4. Write a program that count down from the given input number n upto zero (while loop)
#include <iostream>
using namespace std;
int main() {
int n;
cout<<"Enter a number"<<endl;
cin>>n;
while(n>=0)
{
cout<<n<<endl;
n--;
}
return 0;
}
5. Write a program that sum the numbers you entered until you enter zero (do while)
#include <iostream>
using namespace std;
int main() {
float n,sum=0.0;
do{
cout<<"Enter a number"<<endl;
cin>>n;
sum+=n;
}
while(n>0);//while(n!=0.0)
cout<<"total sum is"<<sum;
return 0;
}
6. Write a program that evaluate the sum of first n th odd number(For loop)
#include <iostream>
using namespace std;
int main() {
int n,sum =0;
cout<<"enter the number"<<endl;
cin>>n;
for(int i=1;i<=n;i=i+2)
{
sum +=i;//sum = sum+i
}
cout<<"Total sum is "<<sum;
return 0;
}

You might also like