📄 l12.1b
字号:
#printThe function getnum actually returns -1 when itencounters end of file. (The source is in getnum.cif you're interested.)Write, compile and run a program thatreads numbers one per line with getnumand, for each, prints:small if the number is >0 and <=100big if the number is >100 and <=1000huge if the number is >1000.Type "ready" when you're done.#once cp %s/getnum.o .#once cp %s/getnum.c .#once #create Ref100110009991011001#once #create Ref1hugebigbigbigsmallsmall#usera.out <Ref >test#cmp Ref1 test#succeed/* One way:*/main() { int n; while ((n = getnum()) >= 0) if (n > 0 && n <= 100) printf("small\n"); else if (n > 100 && n <= 1000) printf("big\n"); else if (n > 1000) printf("huge\n");}/* Notice that in principle n could be negative, so we need the last case to say else if (n > 1000) instead of just falling into it with a bare else Also it's a good idea to indent the else-if's exactly the way they are here; otherwise you'll lose track of what's going on.**/#log#next13.1a 10
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -