/* Find the maximum of n real calues. */
#include <stdio.h>
int main(void)
{
int cnt = 0, n;
float max, x;
printf(\"The maximim value will be computed.\\n\");
printf(\"How many numbers do you wish to enter?\");
scanf(\"%d\", &n);
while( n <= 0 ) {
printf(\"\\nERROR: Positive integer required.\\n\\n\");
printf(\"How many numbers do you wish to enter?\");
scanf(\"%d\", &n);
}
printf(\"\\nEnter %d real numbers: \", n);
scanf(\"%f\", &x);
max = x;
while (++cnt < n) {
scanf(\"%f\", &x) ;
if (max < x)
max = x;
}
printf(\"\\nMaximum value: %g\\n\", max);
return 0;
}
while (++cnt < n) {
scanf(\"%f\", &x) ;
if (max < x)
max = x 에서 while 다음에 scanf를 한번 더 해줘야 하는 이유가 뭘까??
없애고 해보니깐 맥시멈값이 걍 처음 숫자값으로 나오던데...
#include <stdio.h>
int main(void)
{
int cnt = 0, n;
float max, x;
printf(\"The maximim value will be computed.\\n\");
printf(\"How many numbers do you wish to enter?\");
scanf(\"%d\", &n);
while( n <= 0 ) {
printf(\"\\nERROR: Positive integer required.\\n\\n\");
printf(\"How many numbers do you wish to enter?\");
scanf(\"%d\", &n);
}
printf(\"\\nEnter %d real numbers: \", n);
scanf(\"%f\", &x);
max = x;
while (++cnt < n) {
scanf(\"%f\", &x) ;
if (max < x)
max = x;
}
printf(\"\\nMaximum value: %g\\n\", max);
return 0;
}
while (++cnt < n) {
scanf(\"%f\", &x) ;
if (max < x)
max = x 에서 while 다음에 scanf를 한번 더 해줘야 하는 이유가 뭘까??
없애고 해보니깐 맥시멈값이 걍 처음 숫자값으로 나오던데...
저거 코드 직접이해해봐 그럼 답이나와
프로그래밍공부하면서 연필이랑 공책은 필수
직접 적으면서 돌려봐
다이네스트놈 하이