c-program to find all the factor of n natural number
The numbers that are completely divisible by the given value (it means the remainder should be 0) called factors of a given number in c. lets us see how to write a program in c-program
In this program ,we will calculate the factor of a number by taking value by the user and display the factor of the number .
Alogrithm
1. input number from the user . store it in variable 'n'.
2. run a loop form 1 to n , increment 1 in each iteration. for(i=1;i<=-n;i++);
3. for each iteration ,it check the condition i,e if(n%i==0) then i is a factor of n.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
printf("%d ",i);
}
getch();
}
output:- n=36
1,2,3,4,6,9.12,18,36
For more c-programming example:-
.c-program to calculate the sum of the two numbers
No comments:
Post a Comment