Pages

Tuesday, 15 March 2016

Calculate Totient number from given number



Q : Write a program to get Totient number from given number?


[     Totient number = All prime number(M)<given prime number(N)
      l.e. N=10
     M={1,3,5,7}=4
]

Answer : 


/*   ::: Girfa :::
http://girfahelp.blogspot.in/p/c-language.html
program : get all prime number less than given number   */
#include<stdio.h>
#include<conio.h>
void main()
{
int n,p,c,k=0;
clrscr();
printf("Enter number in range>> ");
scanf("%d",&n);
for(p=1;p<=n;p++)
{
for(c=2;c<p;c++)
{
if(p%c==0)
break;
}
if(c==p)
k++;
}
printf("\nTotal Totient is %d",k);
getch();
}


Next Question

No comments:

Post a Comment