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