Problem 17

21 comments on “Problem 17”


  • nagella

    n = int(input())
    l=[]
    for i in range(2,n+1):
    flag =0
    for j in range(2,i):
    if(i%j ==0):
    flag =1
    break
    if(flag == 0):
    l.append(i)
    print(l)
    tot=0
    for i in range(len(l)):
    tot = tot+l[i]
    print(tot)


  • shushank

    l=int(input())
    r=int(input())
    l1=[]
    for i in range(l,r+1):
    a1=i
    c=0
    if a1>1:
    for i in range(2,a1):
    if a1%i==0:
    c=1
    break
    if c==0:
    l1.append(a1)
    print(sum(l1))


  • amit

    #include

    int main()
    {
    int r_1,r_2,k,sum=0;;
    int flag=1;
    scanf(“%d%d”,&r_1,&r_2);
    k=r_1;
    while(k>=r_1 && k<=r_2)
    {
    for(int i=2;i<k;i++)
    {
    if(k%i==0){
    flag=0;
    break;}
    }
    if(flag==1){
    sum=sum+k;}
    k++;
    flag=1;
    }
    if(r_1==1)
    printf("%d",sum-1);
    else
    printf("%d",sum);
    return 0;
    }


  • Gourab

    //sum of prime no in a given range
    #include
    int main(){
    int l,u,i,j;
    scanf(“%d%d”,&l,&u);
    int sum= 0,f=0;
    if(l==1) l=2;
    for(i=l;i<=u;i++){

    for(j=2;j<=i/2;j++){
    if(i%j==0){
    f=1;
    break;
    }

    }
    if(f==0){
    sum += i;
    printf("%d ",i);

    }
    f=0;
    }
    printf("\n%d",sum);
    return 0;
    }


  • Satyam

    #include
    using namespace std;

    int prime (int);

    int prime(int num){
    if(num==1)
    return 0;
    int flag = 1;
    for(int i =2; i>start>>end;
    if(start>=end)
    cout<<"Invalid input";
    else{
    int sum=0, average=0, count =0;
    cout<<"\nprime number in given range are \n";
    for(int i = start; i<=end; i++){
    int Yesprime = 0;
    Yesprime = prime(i);
    if(Yesprime){
    cout<<" "<<i;
    sum = sum + i;
    count++;
    }
    }

    cout<<"\ncount "<<count;
    cout<<"\nsum "<<sum;
    cout<<"\naverage "<<(float)sum/count;
    }
    return 0;
    }


  • Prajwal

    n = int(input())
    sum1 = 2
    for i in range(3,n):
    for j in range(2,i):
    if i%j!=0:
    a = “prime”
    else:
    a = “not prime”
    break
    if a == ‘prime’:
    sum1 += i

    print(sum1)

    Enjoy


  • Raman

    // Online C compiler to run C program online
    #include

    int main() {
    int l,r,i,j;
    int sum=0,temp;

    scanf(“%d”,&l);
    scanf(“%d”,&r);

    for(i=l;i<=r;i++){
    temp=0;
    for(j=2;j<l;j++){
    if(i%j==0 && i!=2){
    temp=1;
    }

    }
    if(temp==0){
    sum=sum+i;
    }
    }

    printf("%d",sum);

    return 0;
    }


  • rohan

    #include
    int main()
    {
    int i,j,k,l,m,n,sum=0;
    printf(“enter values within which we need to find out sum of all prime number\n”);
    scanf(“%d%d”,&k,&l);
    for(i=k;i<=l;++i)
    {
    int count=0;
    for(j=2;j<=(i/2);j++)
    {
    if(i%j==0)
    {
    count++;
    break;
    }
    }
    if(count==0)
    sum=sum+i;

    }
    if(k==1)
    sum=sum-1;
    printf("%d",sum);
    return 0;
    }


  • Sadique Gametor

    #include
    int prime(int n)
    {
    int i,c=0;
    for(i=1;i<=n;i++)
    {
    if(n%i==0)
    c++;
    }
    if(c==2)
    return 1;
    else
    return 0;
    }
    int main()
    {
    int x,i,q,a[100],j,sum=0,l;
    scanf("%d",&l);
    scanf("%d",&x);
    q=0;
    for(i=l;i<=x;i++)
    {
    if(prime(i))
    {
    a[q]=i;
    q++;
    }
    }
    for(i=0;i<q;i++)
    {
    sum=sum+a[i];
    }
    printf("%d",sum);
    return 0;
    }


  • avi gehlot

    #Sum of odd number in given range
    a,b=map(int, input().split(” “))
    sum=0
    for i in range(a,b+1):
    if (i%2!=0):
    sum =sum+ i
    print(“sum of odd number is:”,sum)


  • Mohd Saif

    #python

    n1,n2=map(int,input().split(” “))
    x=0
    for i in range(n1,n2+1):
    if(i%2!=0):
    x=x+i
    print(f”sum of odd number between {n1} and {n2} is:{x}”)


  • PARTHA SARATHI SINHA

    #include
    int main()
    {
    int sum=0,i,max;
    scanf(“%d”,&max);
    for(i=0;i<max;i++)
    {
    if(i%2!=0)
    {
    sum=sum+i;
    }
    }
    printf("%d",sum);
    return 0;

    }