Posts

11.c++ program to multiply two numbers

Image
  // C++ program to multiply two numbers INPUT: #include<iostream> using namespace std; int main() {     float a,b,c;     cout<<"\n Enter a first value  : ";     cin>>a;     cout<<"\n Enter a second value : ";     cin>>b;     c = a * b;     cout<<"\n"<<" Product = "<<c<<endl;     return 0; } OUTPUT:

12.c++ program to print numbers from 1 to 10 using for loop

Image
//C++ program to print numbers from 1 to 10 INPUT: #include<iostream> using namespace std; int main() {     int i;     for(i=1;i<=10;i++)         {             cout<<i<<endl;         }     return 0; } OUTPUT:  

10.c++ program to check if a leap year or not

Image
// C++ program to check if a year is leap year or not INPUT: #include<iostream> using namespace std; int main() {     int z;     cout<<"Enter a year:";     cin>>z;     if(z%4==0){         if(z%100==0){             if(z%400==0)                 cout<<"\n\t"<<z<<" is a leap year";             else                 cout<<"\n\t"<<z<<" is not a leap year";         }         else             cout<<"\n\t"<<z<<" is a leap year";     }     else         cout<<"\n\t"<<z<<" is not a leap year";     return 0; } OUTPUT:

9.c++ program to print number entered by user

Image
  // C++ program to print number entered by user INPUT: #include<iostream> using namespace std; int main() {     int a;     cout<<"Enter an integer : ";     cin>>a;     cout<<"\n"<<" You Entered "<<a<<endl;     return 0; } OUTPUT:

8.c++ program to check whether the number is even or odd

Image
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:

7.c++ program to swap two numbers using 6 methods

Image
SWAPPING NUMBERS USING 6 METHODS: FIRST METHOD: // C++ program to swap numbers using temporary variable INPUT: #include<iostream> using namespace std; int main() {     int x,y,z;     cout<<"Enter The Value of x : ";     cin>>x;     cout<<"Enter The Value of y : ";     cin>>y;     cout<<"\n\t Before Swapping"<<endl;     cout<<"x = "<<x<<endl;     cout<<"y = "<<y<<endl;     z=x;     x=y;     y=z;     cout<<"\n\t After Swapping"<<endl;     cout<<"x = "<<x<<endl;     cout<<"y = "<<y<<endl;     return 0; } SECOND METHOD: // C++ program to swap numbers without using Temporary variables using addition and subtraction operator INPUT: #include<iostream> using namespace std; int main() {     int x,y;   ...

6.c++ program to get an ASCII value and display the corresponding character

Image
 // C++ program to get an ASCII value and display the corresponding character #include<iostream> using namespace std; int main() {     int a;     char b;     cout<<"\n Enter ASCII code (0 to 255):";     cin>>a;     b=a;     cout<<"\n Equivalent Character:"<<b<<endl; } OUTPUT: