Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Ma Linn Latt Sandar Myint

Roll no-1801

Section A(Second semester)

Assignment2-C++

1. #include <iostream>

using namespace std;

int main(){

int var1,var2;

cout<<"Enter two integer variables : "<<endl;

cin>>var1>>var2;

if(var1>var2){

cout<<var1<<" is greater than "<<var2;

}else{

cout<<var1<<" is smaller than "<<var2;

cout<<"\nSum ="<<var1+var2<<endl;

cout<<"Difference ="<<var1-var2<<endl;

cout<<"Product ="<<var1*var2<<endl;

cout<<"Ratio ="<<(var1*1.0F)/var2<<endl;

return 0;

2. #include <iostream>

#include<iomanip>

using namespace std;

int main(){

int n;

cout<<"Check whether a number is positive ,negative or zero "<<endl;

cout<<setfill('-')<<setw(50)<<'-'<<endl;
cout<<"Input a number : "<<endl;

cin>>n;

if(n>0){

cout<<"The entered number is positive ! "<<endl;

}else if(n<0){

cout<<"The entered number is Negative ! "<<endl;

}else{

cout<<"The entered number is zero ! "<<endl;

return 0;

3.

#include <iostream>

using namespace std;

int main(){

int n1,n2,n3;

cout<<"Enter three integers : "<<endl;

cin>>n1>>n2>>n3;

if(n2>n1 && n2<n3){

cout<<n1<<n2<<n3;

}else if(n1==n3 && n2>n1){

cout<<n1<<n3<<n2;

}else if(n1==n2 && n3>n1){

cout<<n1<<n2<<n3;

}else if(n2==n3 && n1>n3){

cout<<n2<<n3<<n1;

}else if(n1>n2 && n1<n3){

cout<<n2<<n1<<n3;
}else if(n3>n1 && n3<n2){

cout<<n1<<n3<<n2;

}else if(n1>n3 && n1<n2){

cout<<n3<<n1<<n2;

}else if(n3>n2 && n3<n1){

cout<<n2<<n3<<n1;

}else{

cout<<n3<<n2<<n1;

return 0;

4. #include <iostream>

using namespace std;

int main(){

int n;

cout<<"Enter a number : "<<endl;

cin>>n;

if(n%2==0){

cout<<n<<" is even integer ! "<<endl;

}else{

cout<<n<<" is odd integer ! "<<endl;

system("pause");

system("cls");

return 0;

5. #include <iostream>

using namespace std;

int main(){
int amount,yr;

float rate,total;

cout<<"Enter initial amount: "<<endl;

cin>>amount;

cout<<"Enter the numbers of years : "<<endl;

cin>>yr;

cout<<"Enter annual interest rate : "<<endl;

cin>>rate;

rate=rate/100;

total=amount;

for(int i=0;i<yr;i++){

total=total+(total*rate);

cout<<"At the end of the "<<yr<<" years "<<"you will have "<<total<<" dollars . "<<endl;

return 0;

3.

You might also like