Sum of prime numbers between two intervals using command line arguments:


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(int argc,char *argv[])
{
int a,b,i,j,s=0,c,l,u;
a=atoi(argv[1]);
l=a+1;
b=atoi(argv[2]);
u=b;
    for(i=l;i<u;i++)
    {
        c=1;
        for(j=2;j<=i/2;j++)
        {
            if(i%j==0)
            {
                c=0;
            }
        }
        if(c==1)
        {
            s=s+i;
        }
    }  printf("%d",s);
return 0;
}

Comments

Popular Posts