wap in c to find the total number of divisors of a given number.
#include<stdio.h>
#include<conio.h>
#include<math.h>
int arr[100000];
int prime(m,n)
{
int count;
long int i,j,t=1,a=1;
while(t--)
{
if(m==1||m==2)
arr[0]=2;
if(m%2==0)
m=m+1;
for(i=m;i<=n;i=i+2)
{
count=0;
for(j=3;j<=sqrt(i);j=j+2)
if(i%j==0)
{count++;break;}
if(count==0&&i!=1)
{arr[a]=i;
a++;}
}
}
return(0);
}
main()
{
int divisors=1,count=0,n,i=0,j;
printf("enter the number\n");
scanf("%d",&n);
prime(1,n);
while(n>1)
{
{for(j=0;;j++)
if(n%arr[i]==0)
{n=n/arr[i];
count++;}
else
{i++;break;}
}
divisors=divisors*(count+1);
count=0;
}
printf("\nthe no of divisors is %d",divisors);
getch();
}
output
#include<conio.h>
#include<math.h>
int arr[100000];
int prime(m,n)
{
int count;
long int i,j,t=1,a=1;
while(t--)
{
if(m==1||m==2)
arr[0]=2;
if(m%2==0)
m=m+1;
for(i=m;i<=n;i=i+2)
{
count=0;
for(j=3;j<=sqrt(i);j=j+2)
if(i%j==0)
{count++;break;}
if(count==0&&i!=1)
{arr[a]=i;
a++;}
}
}
return(0);
}
main()
{
int divisors=1,count=0,n,i=0,j;
printf("enter the number\n");
scanf("%d",&n);
prime(1,n);
while(n>1)
{
{for(j=0;;j++)
if(n%arr[i]==0)
{n=n/arr[i];
count++;}
else
{i++;break;}
}
divisors=divisors*(count+1);
count=0;
}
printf("\nthe no of divisors is %d",divisors);
getch();
output
Subscribe to:
Posts (Atom)
Implemet Stack in python
class Stack : def __init__ ( self , data ): self . stack = [] if ( data ): self . stack . append ( da...
-
The modem is a contraction of the term modulator and demodulator.as the name suggests a modem performs functions of both modulator and demo...
-
class Stack : def __init__ ( self , data ): self . stack = [] if ( data ): self . stack . append ( da...
-
When light of sufficiently small wavelength is incident on a metal surface,electrons are ejected from the metal,this phenomena is called pho...