정말 마지막 질문입니다 ㅠㅠ
일진누나
2023.04.01
질문 제목 : 다른 것은 오류없는데 엉뚱한 결과값이 1개 더 추가됩니다질문 내용 :
#include stdio.h
#include stdlib.h
int main(int argc, char *argv[])
{
int a,b,c,d;
a=b=c=d=0;
int sum;
int number;
number=0;
for(d=0;d=10;d++)
{
sum=a+b+c+d;
if(d==10){
d=0;
c=c+1;
}
if(c==10){
c=0;
b=b+1;}
if(b==10){
b=0;
a=a+1;}
if(a==10){
break;}
if(sum==10)
{
printf(%d, %d, %d, %d \n, a, b, c, d);
number+=1;
}
}
printf(경우의 수 : %d \n, number);
system(pause);
return 0;
}
이 소스에서 a+b+c+d=10이 되는 a,b,c,d만 나와야 하는데
0, 0,1, 0 이라는 값도출력되네요 왜그렇죠?
-
세실
앗.. 그렇군요 이제야 알겠네요 ㅠㅠ
-
부루
본인이 로직 짜놓고 남한테 고쳐달라면 되나요 -_-
0,0,0,10일 때 for문 처음부터 어떻게 돌아갈 지를 생각해 보세요.