The problem comes from the Pat platform, which is a no-brainer. The title requires the output of the number of characters in a given interval and sums them up. The specific idea is to use the cycle to determine the prime number, the results passed to the control variables, the control variables to determine whether to perform the increase and sum. Of course, it must be noted that 1 is neither prime nor composite.
Here's the code:
Copy Code code as follows:
#include <stdio.h>
int main ()
{
int a=0,b=0;
int n=0,sum=0;
int x=0,i=0;
scanf ("%d%d", &a,&b);
int check=1; Suppose to be prime
for (x=a;x<=b;x++) {
check=1;
for (i=2;i<x;i++) {
if (x%i==0) {
check=0;
Break
//The loop is used to determine if it is a prime number, to iterate over the numbers less than X, and to assign a value of 0 to a variable that is divisible by x, and jump out of the loop directly
}
if (check!= 0 && x!=1) {
n++;
Sum+=x;
//The If is used to determine the check value that was passed before, and to add whether X is 1
}
printf ("%d%d", n,sum);
return 0;
}