Question #300974

A company is offering a special discount to its customers based on an algorithm two range values are fed to the algorithm and in return it will calculate the discount to offer to the customers the discount is calculated as the sum of all.the prime numbers

Expert's answer



#include<stdio.h>
#include<math.h>


int isPrime(int regNumber){
	if (regNumber < 2){
		return 0;
	}
	if (regNumber == 2 || regNumber == 3){
		return 1;
	}
	for (int i = 2; i <= sqrt(regNumber * 1.0); i++){
		if (regNumber % i == 0){
			return 0;
		}
	}
	return 1;
}
int main(){
	int number1;
	int number2;
	int i;
	int sum=0;
	printf("Input number 1: ");
	scanf("%d",&number1);
	printf("Input number 2: ");
	scanf("%d",&number2);
	for(i=number1;i<=number2;i++){
		if(isPrime(i)){
			sum+=i;
		}
	}
	printf("Discount: %d\n\n",sum);
	scanf("%d",&sum);
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS