Home > Back-end >  C language small white, consult bosses
C language small white, consult bosses

Time:09-19

#include
Sushu (int a)
{int b;
For (b=2; B{
If (a % b==0)
break;
The else
return a;
}
}
Int main ()
{int n, I, the sum=0;
Int n=I;
Printf (" please enter a number ");
The scanf (" % d ", & amp; n);
For (I=3; i<=n; I++)
{
I=sushu (n);
The sum +=I * I;
}
Printf (" 3 ~ prime for the sum of the squares of the % d % d ", n, sum);
}
Why when I type of 9, the program for 81 as a result, instead of 83, there is wrong, please!!!!!!!!!!!

CodePudding user response:

Int n redefinition, I an uninitialized, I in use I for as a temporary variable, sushu logic also have problems
Below is change good
 # include & lt; stdio.h> 

Int sushu (int a)
{
int b;
For (b=2; b {
If (a % b==0)
return 0;
}
return a;
}
Int main ()
{
Int sum=0, n, I, TMP.
Printf (" please enter a number ");
Scanf_s (" % d ", & amp; n);
For (I=3; I & lt;=n; I++)
{
TMP=sushu (I);
The sum +=TMP TMP *;
}
Printf (" 3 ~ is % d % d primes the sum of the squares of the \ n ", n, sum);
}

CodePudding user response:

 # include & lt; stdio.h> 

Int sushu (int a)
{
int b;
For (b=2; B{
If (a % b==0)
return 0;
}

return 1;
}
Int main ()
{
Int n, I, the sum=0;
Int ret.
//int n=I;
Printf (" please enter a number ");
The scanf (" % d ", & amp; n);
For (I=3; i<=n; I++)
{
//I=sushu (n);
Ret=sushu (I);
If (ret)
The sum +=I * I;
}
Printf (" 3 ~ prime for the sum of the squares of the % d % d ", n, sum);
}

For your reference ~

CodePudding user response:

reference 2 building self-confidence boy reply:
 # include & lt; stdio.h> 

Int sushu (int a)
{
int b;
For (b=2; B{
If (a % b==0)
return 0;
}

return 1;
}
Int main ()
{
Int n, I, the sum=0;
Int ret.
//int n=I;
Printf (" please enter a number ");
The scanf (" % d ", & amp; n);
For (I=3; i<=n; I++)
{
//I=sushu (n);
Ret=sushu (I);
If (ret)
The sum +=I * I;
}
Printf (" 3 ~ prime for the sum of the squares of the % d % d ", n, sum);
}

For reference ~

Thank you big!

CodePudding user response:

reference 1st floor YZX_GSR response:
int n redefinition, I an uninitialized, I in use I for as a temporary variable, sushu logic also have problems
Below is change good
 # include & lt; stdio.h> 

Int sushu (int a)
{
int b;
For (b=2; b {
If (a % b==0)
return 0;
}
return a;
}
Int main ()
{
Int sum=0, n, I, TMP.
Printf (" please enter a number ");
Scanf_s (" % d ", & amp; n);
For (I=3; I & lt;=n; I++)
{
TMP=sushu (I);
The sum +=TMP TMP *;
}
Printf (" 3 ~ is % d % d primes the sum of the squares of the \ n ", n, sum);
}

Thank you big!
  • Related