Prime frequency

Analysis of Prime frequency(Problem 10789)

#include
#include
#include
int p[2003]; //global array of storing prime number
int crossout(int p[],int n, int i) //function definition to cross out the multipl of i(i=1..n)
{
int k;
for(k=i+1;k<=n;k++)
{
if(p[k]%i==0)//if we find any multiple of i just change the value of that position by 1.
p[k]=1;
}
}

main()
{
int i,j,n,temp,length;
for(i=1;i<=2001;i++) //store 1 to 2001 in a global array
{
p[i]=i;
}
for(i=2;i<=sqrt(2001);i++) // apply sieve method to find out prime numbers
{
//if we find 1 in array position p[i] we do not need to cross-out.(that means it is already crossed out.
if(p[i]!=1)
crossout(p,2001,i);
}
scanf(“%d”,&n);
int Testcase=0;
while(n–)
{
int count=0,primecount=0;
char a[2001]={‘\0’},b[65]; //initialise NULL to each position of the array.
int c[125]={0}; //initialise 0 to each position of the array.
scanf(“%s”,a);
length=strlen(a); //measure the length of the string
for(i=0;i=b[j+1])
{
temp=b[j+1];
b[j+1]=b[j];
b[j]=temp;
}
}
}
printf(“Case %d: “,++Testcase); //print the case no.
for(i=1;i<=count;i++)
{
j=c[b[i]];
// just print the character which one is entered prime number times from b array
if(p[j]!=1)
{
printf(“%c”,b[i]);
primecount++;
}
}
//if there r no character which one is entered primenumber times from b array just print empty
if(primecount==0)
{
printf(“empty”);
}
printf(“\n”);
primecount=0;
}

}

Share

4 thoughts on “Prime frequency

  1. You can purchase an Irish beer bucket online and have it sent to their home or you can make your own beer bucket with different types of Irish beers and maybe some drinking accessories like bottle openers and
    pint glasses. Inside an architectural photographer’s
    van you will find a computer, extension cords, halogen lights, gobos, gaffer tape, light
    stands, halogen bulbs and a digital camera.
    Every professional photographer who works weddings will have
    a portfolio that you can view.

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Lean Blog by Crimson Themes.