c-프로그램
본 자료는 2페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
해당 자료는 2페이지 까지만 미리보기를 제공합니다.
2페이지 이후부터 다운로드 후 확인할 수 있습니다.

목차

본문내용

로그램은 다르게 작동할 것이다. while 루프의 몸체를 다시 작성하여 이전 결과와 같은 결과가 나오도록 하여라.
(sol)
for대신 while loop로 바꾸면...
#include
#include
int main(void)
{
int i, n;
printf("\n%s\n%s",
"Some randomly distributed integers will be printed.",
"How many do you want to see? ");
scanf("%d", &n);
i = 0; /* initialize */
while( i++ < n){
if ((i-1) % 8 == 0)
putchar('\n');
printf("%7d", rand());
}
printf("\n\n");
return 0;
}
++i로 바꾼 후...
#include
#include
int main(void)
{
int i, n;
printf("\n%s\n%s",
"Some randomly distributed integers will be printed.",
"How many do you want to see? ");
scanf("%d", &n);
i = 0; /* initialize */
while( ++i < n){
if ((i-1) % 8 == 0)
putchar('\n');
printf("%7d", rand());
}
printf("\n\n");
return 0;
}
n에다 8을 입력하면 하나가 줄어서 7개의 랜덤 숫자가 나온다. 정상적으로 나오기 위하여 while의 조건 부분, while( ++i < n)을 while( ++i <= n)으로 변경시켜준다.
이전 결과가 나오기 위하여...
#include
#include
int main(void)
{
int i, n;
printf("\n%s\n%s",
"Some randomly distributed integers will be printed.",
"How many do you want to see? ");
scanf("%d", &n);
i = 0; /* initialize */
while( ++i <= n){
if ((i-1) % 8 == 0)
putchar('\n');
printf("%7d", rand());
}
printf("\n\n");
return 0;
}
20. 컴파일러를 호출하면, 시스템은 먼저 전처리기를 호출한다. 이 연습 문제에서는 어떤 일이 일어나는지 알아보기 위해 일부러 전처리 오류가 발생하도록 하였다. 다음 프로그램을 실행하여 보아라.
(sol)
invalid preprocessor command 'inc1'과 같은 에러가 나왔다. inc1과 같은 전처리기 명령어가 없기 때문이다. 그래서 이번에는 inc1을 include로 변경을 하자, 다음과 같은 에러 메시지가 나왔다.
Cannot open include file: 'stdixx.h': No such file or directory
stdixx.h와 같은 파일이 헤더파일이 있는 곳에 없기에 에러가 났다. 그래서 이번에는 printf에 대한 정보가 있는 stdio.h라는 헤더파일로 변경하였더니, 에러 없이 잘 수행을 하였다. include<...>는 전처리기 명령어로서 <...>안의 파일의 내용을 이곳에 포함하는 일을 한다. 그리고 stdio.h는 printf(...)나 scanf(...)와 같은 함수에 대한 정보를 포함하고 있다.(사실은 이러한 함수의 원형이 있다.)

키워드

  • 가격1,300
  • 페이지수8페이지
  • 등록일2002.09.22
  • 저작시기2002.09
  • 파일형식한글(hwp)
  • 자료번호#203920
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니