当前位置:编程学习 > C/C++ >>

一道关于function的C语言题目

我们有2个array里面有10个elements, 一行是学生的ID, 一行是分数。 学生ID是一个有8个characteristics的string, ((7 numbers plus the end of string mark '\0', A valid student numbers start with a '1', an input of 0 is used to exit the program, 这个是说每个学生ID后面加'\0', 输入开头字母是1的学生ID 能查成绩, 如果输入第一个数字是0就推出程序)。 写一个C编程 里面有2个input, ID 和 mark 如果 学生ID 存在, 那么出现成绩 如果不存在 就出现 no marks 英文原文见下 We have two arrays of 10 elements: a list of students IDs and a list of marks. The main method and test data is defined in the file attached. The student ID is a string with 8 characters (7 numbers plus the end of string mark '\0', A valid student numbers start with a '1', an input of 0 is used to exit the program. Write the function called update_mark which has two input parameters: a student ID and a mark. If the student exist, it will increment their mark and print the new mark. If it does not exist it will print a message saying so. Hint: review the code you wrote in the workshop for find. Now you need to find a string instead of an integer, and use the index of the student ID to update their mark
追问:能写给我吗 拜托了
答案:#include"stdio.h"
#include"malloc.h"

void initArray(int a[],int aLength)
{
 int i;
 printf("请输入%d个整数(整数之间以空格隔开):",aLength);
 for(i=0;i<aLength;i++)
  scanf("%d",&a[i]);
}//完成对数组a的初始化工作,其中aLength为数组a的长度

int largestValue(int a[],int aLength)
{
 int largestValue;//用来接收数组中的最大数
 int i;
 initArray(a,aLength);
 largestValue=a[0];//初始化最大数为数组中的第一个数
 for(i=1;i<aLength;i++)
  if(largestValue<a[i])
   largestValue=a[i];
 return largestValue;
}//获得数组a中的最大数,其中aLength为数组a的长度

void main()
{
 int aLength;//数组的长度
 int *a;//用来接收数组的开始地址
 printf("数组的长度:");
 scanf("%d",&aLength);
 a=(int *)malloc(sizeof(int)*aLength);
 printf("最大数为:%d\n",largestValue(a,aLength));
}
其他:把附带的源码贴出来啊,里面有main函数和测试代码。 

上一个:以下结构体成员应用形式不正确的是 struct {int day,mouth,year}a,*p=&a A p->day B a->day C (*p).day
下一个:c语言:在主函数中输入10个等长的字符串。用另一个函数对它们排序。然后再主函数中输出。求高人指点!!

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,