소프트웨어/C
[2004년 중간 2번] 합계산 - do-while 반복문
카켈
2007. 2. 7. 05:24
1. 목적
- do-while 반복문을 쓸줄 안다.
2. 문제 (점수 : 10점)
- 50 부터 150 까지의 합을 계산하는 프로그램을 만든다.
- 반드시 do-while 구문을 사용할 것
- 실행 화면
50부터 150까지의 합 : 10100
Press any key to continue
Press any key to continue
3. 이해
- do-while 문의 구조와 실행 방식을 이해 했는가?
4. 코드
#include <stdio.h>
int main()
{
int i, total;
i = 50;
total = 0;
do
{
total += i;
i++;
}while(i <= 150);
printf("50부터 150까지의 합 : %d\n",total);
return 0;
}
5. 해설
- do 안의 문장을 수행하고 while 안의 조건이 될때 까지 반복하는 구문입니다. 마지막에 세미콜론
을 주의 하시기 바랍니다.
- 그것 외에 다른 제어문의 차이점은 없습니다.
6. 참고
- http://iid.kongju.ac.kr/~clee/lecture/04-2/prog1/study/chapter06/ch06_04.html :
do-while 예문
- 기존 문제 : do-while 검색