Here is a c program for accepting the ranges & printing the prime numbers and their sum, here goes the program perfectly working in Devc++ 5.11:
#include<stdio.h>
int main(){
int a,i,j,flag,b,sum=0;
printf("Enter starting point:");
scanf("%d",&a);
i=a;
printf("Enter ending point:");
scanf("%d",&b);
printf("Prime Numbers are:\n");
while(i<b){
flag=1;
j=2;
while(j<i){
if(i%j==0)
flag=0;
j++;
}
if(flag==1){
printf("%d\n",i);
sum=sum+i;
}
i++;
}
printf("Total of prime number b/w range from %d to %d is %d",a,b,sum);
}
Program C file
Program Application File
#include<stdio.h>
int main(){
int a,i,j,flag,b,sum=0;
printf("Enter starting point:");
scanf("%d",&a);
i=a;
printf("Enter ending point:");
scanf("%d",&b);
printf("Prime Numbers are:\n");
while(i<b){
flag=1;
j=2;
while(j<i){
if(i%j==0)
flag=0;
j++;
}
if(flag==1){
printf("%d\n",i);
sum=sum+i;
}
i++;
}
printf("Total of prime number b/w range from %d to %d is %d",a,b,sum);
}
Program C file
Program Application File
No comments:
Post a Comment