Question:C program to find sum of prime numbers within a range. 

Answer 
#include<stdio.h>

int main(){

    int num,i,count,min,max,sum=0;

     printf("Enter min range: ");
     scanf("%d",&min);

    printf("Enter max range: ");
    scanf("%d",&max);

    for(num = min;num<=max;num++){

         count = 0;

         for(i=2;i<=num/2;i++){
             if(num%i==0){
                 count++;
                 break;
             }
        }
        
         if(count==0 && num!= 1)
             sum = sum + num;
    }

    printf("Sum of prime numbers is: %d ",sum);
  
   return 0;
}
Sample output: Enter min range: 50 Enter max range: 100 Sum of prime numbers is: 732 

+ Report
Total Preview: 854
C program to find sum of prime numbers within a range.
Copyright © 2024. Powered by Intellect Software Ltd