同学们点
主题 1: 输入同学的列表. 打印最大的屏幕在课堂上
根据我们可以判断这个分配是在阵列中发现数量最多的问题 (在文章曾指出 发现数量最多).
要做到这一点, 我们首先需要输入的列表点 – 即进口阵列. 想进入阵列我们需要知道数组元素的数量. 然后,找到最大元素结束. 但是每个人的注意力是一个实数, 因此,我们使用的类型 浮动.
/*
* Input list of socre of students. Out put max score of list
*/
#include <stdio.h>
int main() {
int n; // number student - size of array
printf("Enter number student: ");
scanf("%d", &n);
float s[n], max; // array socre
int i;
// input array score
for(i = 0; i < n; i++)
{
printf("Enter socre of student %d : ", (i + 1) );
scanf("%f", &s[i]);
}
// find max
max = s[0];
for(i = 1; i < n; i++)
{
if( max < s[i] )
{
max = s[i];
}
}
printf("Max of list score is %.2f\n", max);
return 0;
}
在上面你注意你的代码分配初始变量值最大的搜索之前. 为什么不分配最大= 0 或 -1 或一些其它其中有s[0] – 阵列中的第一个元素? 你觉得如果要指定最大= 0 或 -1 这是不是一切正常, 因为每个人的 0 我应该年长也可以找到合适的款式. 但在所有其他, 阵列是负的,寻找最大不一定是真实的. 假定最初指定最大= 0 有 -1. 当进入的小负数的全阵列 -1 有 0 这一发现将是错误, 最大永远是.
主题 2: 输入同学的列表. 打印屏幕上的代码 (位置) 最大点的你在课堂上
有了这个一切都结束了以前所有的升级位. 此外,我们发现最大, 我们也需要找人 (定位) 具有相同的最高分. 可能有 1, 2, 3 或更多的人拥有最大点.
/*
* Input list of socre of students. Out put max score of list
*/
#include <stdio.h>
int main() {
int n; // number student - size of array
printf("Enter number student: ");
scanf("%d", &n);
float s[n], max; // array socre
int i;
// input array score
for(i = 0; i < n; i++)
{
printf("Enter socre of student %d : ", (i + 1) );
scanf("%f", &s[i]);
}
// find max
max = s[0];
for(i = 1; i < n; i++)
{
if( max < s[i] )
{
max = s[i];
}
}
printf("Max of list score is %.2f\n", max);
// find all student have max score
printf("List index of student have max score:\n");
for(i = 0; i < n; i++)
{
if(s[i] == max)
{
printf("%d ", (i + 1) );
}
}
return 0;
}
这篇文章后,, 希望你能应用到应用的阵列的实际想法, 在日常工作中的简单的教训.
锻炼 1: 输入同学的列表. 打印屏幕上的代码 (位置) 你已经拉到了最高分
锻炼 2: 输入同学的列表. 打印屏幕上的代码 (位置) 你大点平均之类的



最新评论