Example to find all factors of an integer (entered by the user) using for loop and if statement.
To understand this example, you should have the knowledge of following C programming topics:
# if -else ststement,for loop.
this code id given blow
#include<stdio.h>
int main() {
int num i;
printf("Enter the number: ");
scanf("%d",& num);
for(i=1;i<num;++i) {
if(num%i==0) {
printf("\n%d",i);
}
}
return 0;
}
code block pic
Factors of 120 are: 1 2 3 4 5 6 8 10 12 15 20 24 30 40 60
Comments
Post a Comment