god_father9 2019-08-05 16:38 采纳率: 33.3%
浏览 307
已采纳

C语言中for循环里面有dowhile怎么算次数

#include

/* User Code Begin(考生可在本行后添加代码,例如结构体的定义、函数原型声明等,行数不限) */
struct stu
{
char name[10], num[10];
int score;
};

void input(struct stu stud, int num);
void output(struct stu *stud, int num);
/
User Code End(考生添加代码结束) */

int main(void)
{

struct stu stud[5];

input(stud, 5);   
printf("\nfailed the exam: ");  
output(stud, 5);

return 0; 

}

/* User Code Begin(考生在此后完成自定义函数的设计,行数不限) */
void input(struct stu *stud, int n)
{
int i, count = 0;

printf("input name number score:\n"); 
for (i = 0; i < n; i++)
{
    do
    {
        count++;
        printf("student %d:", count);
        scanf("%s%s%d", (stud + i)->name, (stud + i)->num, &(stud + i)->score);
        if ((stud + i)->score < 0 || (stud + i)->score > 100)
        {
            printf("           error score! input again!\n"); 
            count--;
        }
    }while ((stud + i)->score < 0 || (stud + i)->score > 100);
}

}

void output(struct stu *stud, int n)
{
int i, flag = 0;

for (i = 0; i < n; i++)
{
    if ((stud + i)->score < 60)
    {
        printf("%s/%s,%d   ", (stud + i)->num, (stud + i)->name, (stud + i)->score);
    }
    flag = 1;
}
if (flag == 0)
{
    printf("Not Find!");
}
putchar('\n');

}图片说明

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-08-05 17:25
    关注

    把 count++;写在while循环里面,得到的就是总循环次数

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真