Posts

Showing posts from July, 2017

Program to check whether the number is 1, 2 or 3 using switch statement - C++ Programming

Program: #include <iostream> using namespace std; int main() {     int n;     cout << "Enter the value of n" << endl;     cin >> n;     switch (n)     {         case 1:         cout << "Number is One" << endl;         break;         case 2:         cout << "Number is Two" << endl;         break;         case 3:         cout << "Number is Three" << endl;         break;     }     return 0; }

Program to check whether the number is 1, 2 or 3 using if-else statement - C++ Programming

Check whether the number is 1, 2 or 3 using if-else statement: Program: #include <iostream> using namespace std; int main() {     int n;     cout << "Enter the value of n" << endl;     cin >> n;     if (n==1)     {         cout << "Number is One" << endl;     }     else if (n==2)     {         cout << "Number is  Two" << endl;     }     else if (n==3)     {         cout << "Number is Three" << endl;     }     else     {         cout << "None of these" << endl;     }     return 0; }

Program to Calculate the Factorial of any Number using for loop - C++ Programming

Calculate the Factorial of any Number: Program: #include <iostream> using namespace std; int main() {    int n;    cout << "Enter the value of n" << endl;    cin >> n;    int fact = 1;    for (int i=1 ; i<=n ; i++)    {        fact = fact*i;     }     cout << "fact = " << fact << endl;     return 0: }