- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在我第一次输入后,Codeblocks 要求我提供额外的输入,它提示我输入另一个输入,但没有为每个输入提示打印的打印语句。
#include <stdio.h>
//Computing marks and average of students using 2D arrays
void main()
{
int i,j,sum,marks[3][5];
float avg;
printf("Program to compute average marks of 3 students.\n");
for(i=0;i<3;i++)
{ for(j=0;j<5;j++)
{
printf("Enter marks for student %d in subject %d:\t",i+1,j+1);
scanf("%d ",&marks[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<5;j++)
{
sum=sum+marks[i][j];
}
avg= sum/5.0;
printf("The average marks of student %d is %f:\n",i+1,avg);
}
getch();
}
最佳答案
代码问题:您的格式字符串,如 scanf("%d ",&marks[i][j]);
在输入后需要空格,这会导致异常。
更正代码:
#include <stdio.h>
//Computing marks and average of students using 2D arrays
int main()
{
int i,j,sum = 0,marks[3][5];
float avg;
printf("Program to compute average marks of 3 students.\n");
for(i=0;i<3;i++)
{
for(j=0;j<5;j++)
{
printf("Enter marks for student %d in subject %d:\t",i+1,j+1);
scanf("%d",&marks[i][j]);
}
}
for(i=0;i<3;i++)
{
for(j=0;j<5;j++)
{
sum=sum+marks[i][j];
}
avg= sum/5.0;
printf("The average marks of student %d is %f:\n",i+1,avg);
}
return 0;
}
如规范所述
Number,order and type of conversion specifications must match the number,order and type of parameters in the list
.否则,结果将不可预测,并可能终止输入/输出功能。
关于C程序设计语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33916595/
如何有效地设计一个C++模块化程序?如何学习? 最佳答案 对于初学者,您可能希望采取“暴力”过程: 1. 在一个文件中写一个简单的main函数。 2. 增加一些功能,先编译再测试。 3.重构(在谷歌中
前言 有人说现在记事类app这么多,市场这么卷,为什么还想做一个笔记类App? 一来,去年小孩刚出生,需要一个可以记录喂奶时间的app,发现市面上没有一款app能够在两步内简单记录一个时间,可能i
我正处于 Web 应用程序的设计阶段,该应用程序允许用户创建工作请求,并且工作人员可以针对这些请求投入时间。该应用程序还将为主管提供报告功能,以获取每日总计、报告,并说明花费的时间、“成本分配”。 我
前言:很多刚刚接触编程的人都不知道怎么下手编写程序,特别是学习了新的知识点,不知道有什么用,那么本文将以简单的存储结构及简单的运算,条件语句,分支语句,循环语句结合,带来一个双人对战版五子棋,这是一
我正在尝试通过 C++ 多线程解决网络流量问题。 给定一个网络(所有节点都由弧连接,每个弧连接2个且只有2个结束节点,一个是输入节点,另一个是输出节点,每个节点可以有多个输入弧和输出弧),每个节点需要
我有一个关于编程和文件的问题。 while(current!=NULL) { if(current->Id_Doctor!='\0') { current=current->next;
下面的‘C’语句执行什么操作? star = star ^ 0b00100100; (A) 切换变星的第 2 位和第 5 位。 (B) 清除变量星的第 2 位和第 5 位以外的所有位。 (C) 设置除
我写了下面的代码: #include int main() { int a, b; printf("Enter values of a and b\n"); scanf(" %d%d "
我正在将 C 代码编程到 PIC 板上。我的问题是如何让我的程序计算按下按钮(RB0)的时间。然后它会显示所花费的时间并将其显示在液晶显示屏上。以毫秒为单位计算。下面是到目前为止我的代码。 /
我是一名优秀的程序员,十分优秀!