pages

Friday, 9 April 2021

program to calculate the all factor of the natural number in c-programming?

Q.no program to calculate the all factors of the natural number in c-programming?

Now we will be look for to calculate the all factor of the natural number by entering the value of n by the user.

Given a number n, write efficient program to print all factor of n.

for example, if the input is 18 then the output is "1,2,3,6,9,18"   And if the input is 60, then the output is "1,2,3,4,5,6,10,12,15,20,30,60".

#include<Stdio.h>
#include<conio.h>
void main()
{
    int n,i;
    printf("enter the number");
    scanf("%d",&n);
    printf("the  factors  of the number are");
    for(i=1;i<=n;i++)
        if(n%i==0)
        printf(" %d",i);
    getch();
}

output:- enter the number =80

   factor of the number is 1,2,4,5,8,16,20,40,80


For more c-programming :-

1.program to print all prime number form 1 to n natural number













No comments:

Post a Comment