#include stdiohmainint in;float h;counst b=13;fori=1;i46;i++;scanff&h;fori=1;i46;i++;ifhbprintffh;n++;printfdn;代码审计
该代码存在多处语法和逻辑错误,以下是修正后的代码:
#include <stdio.h>
int main(){ int i,n=0; //修正:n需初始化为0 float h; const float b=1.3; //修正:常量需用const声明,并修正拼写错误 for(i=1; i<=45; i++){ //修正:将分号改为大括号,循环范围改为1-45 scanf("%f",&h); if(h<b){ printf("%f",h); //修正:添加换行符 n++; } } printf("%d\n",n); //修正:添加换行符 return 0; //修正:添加返回值 }
修正后的代码功能为:从标准输入读入45个浮点数,若小于1.3则输出并统计个数,最后输出个数。
原文地址: http://www.cveoy.top/t/topic/eDx1 著作权归作者所有。请勿转载和采集!