1 / 5
Oct 2012

#include<stdio.h>
#include<conio.h>
#include<math.h>
void primegen(int*, int*) ;
int main()
{
     int t,i=0,c=0;
     int store[10][10];
     printf("No. of cases");
     scanf("%d",&t);
    if(t==0)
      { printf("enter valid data set");
        }
     if(t>=11)
     {
              printf("only 10 sets allowed");
     }
    if((t!=0)&&(t<11)) 
    {
     while(i<t)
         {
               printf("enter %d th dataset ", i);
               scanf("%d %d", &store[i][0],&store[i][1]);                            //store input
               i++ ;              
          }
       while(c<t)
          {
          primegen(&store[c][0],&store[c][1]);
          c++;
             }
       }  
	  getch();
	  }
    
 void primegen(int *p,int *q)
 {     int i,j,k,c=0,cc;
          int count;
               printf("the data set elements are %d %d\n", *p, *q); 
               k=*p;
               k++;
               printf("initial k value %d\n",k);
               printf("comparing\n");
               printf("\n");
                      for(i=k;i<*q;i++)
                        {  // printf("comparing element %d \n", i);
                           for(j=2;j<i;j++)
                             {
                                if((i%j)==0)
                                {
                                  }
                                else
                                { c++;
                                 }        
                             }
                           cc=(i-2);
                           if(c==cc)
                           {
                               printf("%d is prime\n", i);
                               }
                           c=0; 
                         }
                         printf("\n");
     }

Ihave executed this code in Dev Cpp compiler 4.9 version. No compilation errors are shown, and the results obtained are also correct. But when I am submitting this same code here in spoj, compilation error is notified. Can't locate what compilation error is left. Please help me locate them.

  • created

    Oct '12
  • last reply

    Oct '12
  • 4

    replies

  • 163

    views

  • 3

    users

Conio.h is not in the standard c library. SPOJ uses the gcc compiler. If you ever receive a compiler error from SPOJ you can click on it to get the actual error.

15 days later

What is giving me Runtime Error ???
can anyone help !!!

include

include

include

define SZ 31630

int arr[SZ];
void sieve()
{
int i,j;
arr[0] = arr[1] = 1;
for(i=4; i arr[i] = 1;
for(i=3; i if(arr[i] == 0)
for(j=i*i; j arr[j] = 1;
}

int main()
{
sieve();
int i,j,n,m,t,test;
scanf("%d",&test);
for(t=0; t {
scanf("%d %d",&n,&m);
for(i=n; i<=m; i++)
if(arr[i] == 0)
{
printf("%d\n",i);
for(j=i*i; j<=m; j+=i+i)
arr[j] = 1;
}
if(t printf("\n");
}
return 0;
}

Please use code tags when posting code.

What is the value at arr[50000]?

Suggested Topics

Topic Category Replies Views Activity
C and C++ 0 17 11d

Want to read more? Browse other topics in C and C++ or view latest topics.