Write a program in c++ to input a number and check if it is armstrong or not

  

Write a program  in c++ to input a number and check if it is  armstrong or not

Armstrong Number : Armstrong number is a number that is equal to the sum of cubes of its digits. For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers

#include <iostream>
using namespace std;
int main()
{
    int numaldigitcube = 0;
    cout << "Enter A Number : ";
    cin >> num;
    a = num;
    while (a != 0)
    {
        ldigit = a % 10;
        cube += ldigit * ldigit * ldigit;
        a /= 10;
    }
    if (cube == num)
        cout << num << " is armstrong number ";
    else
        cout << num << " is not a armstrong number";
    return 0;
}


OUTPUT

1. 
     Enter A Number : 371
     371 is armstrong number 

2. 
     Enter A Number : 476
     476 is not a armstrong number



Share:

Write a program in c++ to input a number and check for odd or even

 

Write a program in c++ to input a number and check for odd or even


#include <iostream>
using namespace std;
int main()
{
  int num;
  cout << "Enter A Number To check for EVEN or ODD : ";
  cin >> num;
  if (num % 2 == 0)
    cout << num << " is even";
  else
    cout << num << " is odd";
  return 0;
}


OUTPUT


Enter A Number To check for EVEN or ODD : 56
56 is even













Share:

Write a program in c++ to input three number and find the largest

 

Write a program in c++ to input three number and find the largest

#include <iostream>
using namespace std;
int main()
{
    int abc;
    cout << "Enter Three Number : ";
    cin >> a >> b >> c;
    if (a > b && a > c)
        cout << a << " is Largest Number ";
    else if (b > c)
        cout << b << " is Largest Number ";
    else
        cout << c << " is Largest Number ";
}


OUTPUT OF PROGRAM

Enter Three Number : 45
67
32

67 is Largest Number 


Share:

Write a program in c++ to print all the prime number between 1 to 100

 Write a program in c++ to print all the prime number between 1 to 100 


#include <iostream>
using namespace std;
int main()
{
    cout << "\nPrime Number less than 100 :";
    int test = 0;
    for (int k = 2k <= 100k++)
    {
        for (int j = 2j <= k - 1j++)
        {
            if (k % j == 0)
            {
                test = 0;
                break;
            }
            else
            {
                test = 1;
            }
        }
        if (k == 2)
        {
            cout << "\n"
                 << k << endl;
        }

        if (test == 1)
        {
            cout << k << endl;
        }
    }
}


OUTPUT


Prime Number less than 100 :
2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
73
79
83
89
97













Share:

Write a program in c++ to print the sum and product of digits of an integer

 Write a program in c++ to print the sum and product of digits of an integer.

#include <iostream>
using namespace std;
int main()
{
    int nnumldigitsumproduct = 1;
    cout << "Enter A Number : ";
    cin >> num;
    n = num;
    while (num != 0)
    {
        ldigit = num % 10;
        sum = sum + ldigit;
        product = product * ldigit;
        num = num / 10;
    }

    cout << "Sum of digit of " << n << " = " << sum;
    cout << "\nProduct of digit of " << n << "= " << product;
    return 0;
}


OUTPUT OF PROGRAM

Enter A Number : 4976
Sum of digit of 4976 = 26     
Product of digit of 4976= 1512



Share:

Pageviews