0
4.3kviews
Write a algorithm and program to generate a factor of given no.
1 Answer
written 8.3 years ago by |
Outputs: A number n, which will be the largest number of the list.
Problem: Given a positive number, return its factors.
Inputs: A positive number.
Algorithm:
Accept a number num.Use a for loop from 1 to num. Find the MOD(%) of num with i within the for loop. If mod is equal to 0, display i else continue.
#include <stdio.h>
#include <conio.h>
void main()
{
int n,i;
printf("Enter a positive integer: ");
scanf("%d",&n); printf("Factors of %d are: ", n);
for(i=1;i<=n;++i)
{
if(n%i==0)
printf("%d ",i);
}
getche();
}