메뉴 바로가기

서브메뉴 바로가기

본문 바로가기

logo

묻고 답하기
조회 수 4,944 추천 수 0 댓글 1
?

단축키

Prev이전 문서

Next다음 문서

위로 아래로 댓글로 가기 인쇄 쓰기 목록
?

단축키

Prev이전 문서

Next다음 문서

위로 아래로 댓글로 가기 인쇄 쓰기 목록
?
  • WhiteAT 2013.04.20 08:51

    수정된 코드 입니다.~     



         int i,j,total=0,sum=0;  // sum  초기화

     

               for(i=1;i<=10;i++)  // i= 1부터

               {

     

                         printf("(");

                         sum = 0;  // 1+2+3+4 등을 더하는 변수이기 때문에 더하기 전에 초기화

                         for(j=1;j<=i;j++)

                         {

                                    sum=sum+j;

     

     

                                    //         total=total+sum;  // 여기서 안한다. + - 출력할 때 해준다.

     

                                    printf("%d",j);

                                    if(j==i)

                                              break;

                                    printf("+",j);

     

                         }

                         printf(")");

     

                         if (j%2==0)

                         {

     

                                    if (j <9) printf("+");

                                    total=total-sum;  // 여기서 total 계산

                         }else

                         {

     

                                    printf("-");

                                    total=total+sum; // 여기서 total 계산

                         }

     

     

               }

     

               printf("\ntotal=%d",total); // sum 이 아닌 total 을 출력

     

     

     

    결과

     

    (1)-(1+2)+(1+2+3)-(1+2+3+4)+(1+2+3+4+5)-(1+2+3+4+5+6)+(1+2+3+4+5+6+7)-(1+2+3+4+5
    +6+7+8)+(1+2+3+4+5+6+7+8+9)-(1+2+3+4+5+6+7+8+9+10)
    total=-30계속하려면 아무 키나 누르십시오 . . .

     

     


  1. c# 테트리스 질문입니다.

    Date2013.06.17 Category :프로그래밍 Reply1
    Read More
  2. 더블버퍼링...

    Date2013.06.02 Category :프로그래밍 Reply1
    Read More
  3. C언어 문제가 너무 어려워서 질문드려요

    Date2013.05.24 Category :프로그래밍 Reply1
    Read More
  4. 선생님, 테트리스 관련해서 질문이 있습니다..^^;

    Date2013.05.19 Category :프로그래밍 Reply3
    Read More
  5. C언어 문제좀 풀어주세요~

    Date2013.05.10 Category :프로그래밍 Reply1
    Read More
  6. c언어 초보좀 도와주세요

    Date2013.04.20 Category :프로그래밍 Reply1
    Read More
  7. asd

    Date2013.04.13 Category :프로그래밍
    Read More
  8. c++ 코드좀 봐주세요

    Date2013.03.20 Category :프로그래밍 Reply1
    Read More
  9. 궁금한게 있습니다.

    Date2013.01.19 Category :프로그래밍 Reply1
    Read More
  10. ponyprog 질문좀 드릴게요.

    Date2012.12.09 Category :프로그래밍 Reply3
    Read More
  11. zigbex c# 질문입니다.

    Date2012.11.25 Category :프로그래밍 Reply1
    Read More
  12. 주차장

    Date2012.11.06 Category :프로그래밍 Reply3
    Read More
  13. 선생님 보드 선언에서 의문점과 작동법좀 가르쳐주세요.

    Date2011.11.09 Category :프로그래밍 Reply1
    Read More
  14. 비밀글 입니다.

    Date2011.10.24 Category :프로그래밍 Reply1
    Read More
  15. 비쥬얼 스튜디오 애러 좀 도와주세요

    Date2011.10.18 Category :프로그래밍 Reply1
    Read More
목록
Board Pagination Prev 1 2 3 4 5 Next
/ 5