FIRST METHOD: // C++ program to check whether the number is even or odd using if else INPUT: #include<iostream> using namespace std; int main() { int z; cout<<"\n Enter an integer:"; cin>>z; if(z%2==0) cout<<"\n\t"<<z<<" is Even "<<endl; else cout<<"\n\t"<<z<<" is Odd "<<endl; return 0; } SECOND METHOD: // C++ program to check whether the number is even or odd using ternary operators INPUT: #include<iostream> using namespace std; int main() { int z; cout<<"Enter an integer : "; cin>>z; (z%2==0) ? cout<<"\n\t"<<z<<" is Even "<<endl : cout<<"\n\t"<<z<<" is Odd "<<endl; return 0; } OUTPUT:
// C++ program to find the total marks and average of three subjects INPUT: #include<iostream> using namespace std; int main() { int a,b,c,sum,avg; cout<<"\n Enter Mark 1:"; cin>>a; cout<<"\n Enter Mark 2:"; cin>>b; cout<<"\n Enter Mark 3:"; cin>>c; sum = a + b + c; avg = sum / 3; cout<<"\n The sum = "<<sum; cout<<"\n The average = "<<avg<<"%"; } OUTPUT:
Comments
Post a Comment