This C++ program display factors of a
number using for loop and if statement. First you have to enter a number using
keyboard and factors of that numbers will display on the screen.
Factors of a number are the numbers
that can completely divide that number.
C++ Program to Display Factors of a
Number
#include <iostream>
using namespace std;
int main()
{
int i, num;
cout << "Enter
a Number: ";
cin >> num;
cout << "Factors
of " << num<<": ";
for(i = 1; i <= num;
i++)
{
if(num%i ==
0)
{
cout << i << " ";
}
}
return 0;
}
OUTPUT:
Enter a Number: 100
Factors of 100: 1 2 4
5 10 20 25 50 100
See also:
0 comments:
Post a Comment