yyz0526 @ 2024-02-24 09:04:55
#include <stdio.h>
using namespace std;
int main()
{
int n,a[110],q,b,s,g,sum;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(int i=0;i<n;i++){
q=a[i]/1000;
b=(a[i]/100)%10;
s=(a[i]/10)%10;
g=a[i]%10;
if(g-q-b-s>0){
sum++;
}
}
printf("%d",sum);
return 0;
}
求助!
by zrzforrest @ 2024-02-24 09:09:47
sum没有初始化为0
by yyz0526 @ 2024-02-24 09:13:56
谢谢~(已关)
by QuQ_ @ 2024-02-24 09:14:19
@yyz0526 下次定义的时候放在主函数前面定义,这样自动初始化:
#include <stdio.h>
using namespace std;
int n,a[110],q,b,s,g,sum;
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
for(int i=0;i<n;i++){
q=a[i]/1000;
b=(a[i]/100)%10;
s=(a[i]/10)%10;
g=a[i]%10;
if(g-q-b-s>0){
sum++;
}
}
printf("%d",sum);
return 0;
}
像这样
by yyz0526 @ 2024-02-24 09:15:11
@QuQ_ 好的