weixin_43542397 2022-06-10 11:00 采纳率: 0%
浏览 31

如何控制循环体中的某一个语句仅仅在第一次执行循环时执行一次呢?

如何控制循环体中的某一条语句在多次循环中只执行一次呢?
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define SIZE 10
#define PAR 72
int main(void)
{
int index, score[SIZE];
int sum = 0;
float average;

printf("Enter %d golf scores:\n", SIZE);
for (index = 0; index < SIZE; index++) {
    scanf("%d", &score[index]);
    printf("%5d\n", score[index]);
    sum += score[index];
}
    
average = (float)sum / SIZE;
printf("Sum of scores=%d,average=%.2f\n", sum, average);
printf("That's a handicap of %.0f.\n", average - PAR);

return 0;

}
例如我想在for循环中控制printf("The scores read in are as follows:\n")这条语句仅仅在第一次执行循环时打印。

  • 写回答

3条回答 默认 最新

  • foreverliuyin 2022-06-10 11:10
    关注
    if(index==0) printf("The scores read in are as follows:\n")
    
    评论

报告相同问题?

问题事件

  • 创建了问题 6月10日

悬赏问题

  • ¥20 limma多组间分析最终p值只有一个
  • ¥15 nopCommerce开发问题
  • ¥15 torch.multiprocessing.spawn.ProcessExitedException: process 1 terminated with signal SIGKILL
  • ¥15 QuartusⅡ15.0编译项目后,output_files中的.jdi、.sld、.sof不更新怎么解决
  • ¥15 pycharm输出和导师的一样,但是标红
  • ¥15 想问问富文本拿到的html怎么转成docx的
  • ¥15 我看了您的文章,遇到了个问题。
  • ¥15 GitHubssh虚拟机连接不上
  • ¥15 装完kali之后下载Google输入法 重启电脑后出现以下状况 且退不出去 桌面消失 反复重启没用
  • ¥15 ESP-IDP-BLE配网连接wifi