C语言 数组的问题!!急救!!

\u6025\u6551c\u8bed\u8a00\u9898\u76ee\uff01\uff01\uff01\uff01

#include
#define N 1
struct student
{
char name[10];
int number;
float english;
float math;
float computer;
float sum;
float average;
}a[N];
int i,j,k;
float t;
float b[N];
void input()
{
for(i=0;i<N;i++)
{
printf("\u8bf7\u8f93\u5165\u5b66\u751f\u59d3\u540d\uff1a\n");
scanf("%s",a[i].name);
printf("\u8bf7\u8f93\u5165\u5b66\u751f\u5e8f\u53f7\uff1a\n");
scanf("%d",&a[i].number);
printf("\u8bf7\u8f93\u5165\u5b66\u751f\u82f1\u8bed\u6210\u7ee9\uff1a\n");
scanf("%f",&a[i].english);
printf("\u8bf7\u8f93\u5165\u5b66\u751f\u6570\u5b66\u6210\u7ee9\uff1a\n");
scanf("%f",&a[i].math);
printf("\u8bf7\u8f93\u5165\u5b66\u751f\u8ba1\u7b97\u673a\u6210\u7ee9\uff1a\n");
scanf("%f",&a[i].computer);
a[i].sum=a[i].english+a[i].math+a[i].computer;
a[i].average=a[i].sum/3;
}
}
void sort()
{
for(j=0;j<N-1;j++)
for(i=0;i<N-j+1;i++)
if(a[i].average<a[i].average)
{t=a[i].average;a[i].average=a[i+1].average;a[i+1].average=t;}
for(k=0;k<N;k++)
b[k]=a[k].average;
printf("\u5b66\u751f\u59d3\u540d \u5b66\u751f\u5e8f\u53f7 \u82f1\u8bed\u6210\u7ee9 \u6570\u5b66\u6210\u7ee9 \u8ba1\u7b97\u673a\u6210\u7ee9 \u603b\u5206 \u5e73\u5747\u5206 \n");
for(i=0,k=0;i<N;i++,k++)
printf(" %s %d %g %g %g %g %g \n",a[k].name,a[k].number,a[k].english,a[k].math,a[k].computer,a[k].sum,a[i].average);
}
void main()
{
input();
sort();
}




\u697c\u4e3b\uff0c\u7a0b\u5e8f\u6211\u662f\u5e2e\u4f60\u5199\u4e86\uff0c\u4f46\u662f\u4e00\u697c\u8bf4\u7684\u662f\u6709\u9053\u7406\u7684\uff0c\u4e8c\u697c\u592a\u52bf\u5229\u4e86\uff0c\u6211\u4e0d\u662f\u8bf4\u6279\u8bc4\u4f60\uff0c\u53ea\u662f\u5e0c\u671b\u4f60\u80fd\u597d\u597d\u542c\u542c\u6211\u8fd9\u4e2a\u8fc7\u6765\u4eba\u548c\u4f60\u8bf4\u8bf4\uff0c\u8ba1\u7b97\u673a\u8981\u5b66\u597d\uff0c\u771f\u7684\u662f\u8981\u82b1\u529f\u592b\u7684\uff0c\u8c03\u8bd5\u7a0b\u5e8f\uff0c\u81ea\u5df1\u60f3\u7a0b\u5e8f\u624d\u662f\u91cd\u8981\u7684\uff0c\u5b66\u6821\u7684\u5206\uff0c\u6839\u672c\u5c31\u662f\u4e0d\u503c\u4e00\u63d0\uff0c\u4f60\u61c2\u4e86\u5c31\u597d\uff0c\u697c\u4e3b\uff0c\u4f60\u8981\u597d\u597d\u52aa\u529b\uff0c\u4f60\u4e0d\u61c2\u53ef\u4ee5\u95ee\uff0c\u4f46\u6211\u7edd\u4e0d\u8d5e\u6210\u4f60\u95ee\u5b8c\u4e4b\u540e\u4e0d\u53bb\u7422\u78e8\u522b\u4eba\u7684\u7b54\u6848\u662f\u600e\u4e48\u6765\u7684\uff0c\u8fd9\u662f\u6211\u4e00\u70b9\u70b9\u5fe0\u544a\uff0c\u5e0c\u671b\u4f60\u80fd\u8046\u542c\uff0c\u5bf9\u4f60\u6709\u5e2e\u52a9\u7684\uff0c\u795d\u4f60\u5b66\u4e60\u8fdb\u6b65\u5427\uff01

\u4e0d\u8981\u60ac\u8d4f\u5206\u3002

\u7ed9\u4f60\u4fee\u6539\u4e86\u7b2c\u4e8c\u4e2a\u3002
\u8f93\u5165\u82e5\u5e72\u4e2a\u6570\uff0c\u8f93\u5165\u6570\u503c\u662f99999\u8868\u793a\u8f93\u5165\u7ed3\u675f\u3002
i\u662f\u8f93\u5165\u65f6\u7684\u8ba1\u6570\u5668\u3002

#include
void main()
{
int a[10000];
int i=0;
int j,k;
int aa;

Lab1:
scanf("%d",&a[i]);
if (a[i] == 99999) goto done; //\u8f93\u516599999\uff0c\u5219\u8f93\u5165\u7ed3\u675f
i = i + 1; // \u5426\u5219\uff0c\u8ba1\u6570\u5668\u52a0 1
goto Lab1; // \u8fd4\u56de\u4e0a\u9762\uff0c\u518d\u63a5\u6536\u4e0b\u4e00\u4e2a\u8f93\u5165\u6570

done:;
printf("i=%d\n",i);

for (k=0;k<i;k++) printf("%d ",a[k]);
printf("\n"); // \u6253\u5370\u8f93\u5165\u6570

j = i / 2;

for (k=0;k <= j; k++){
aa = a[k]; // \u6682\u5b58
a[k] = a[i-1-k]; // \u4ea4\u6362
a[i-1-k] = aa; // \u4ea4\u6362
}

for (k=0;k<i;k++) printf("%d ",a[k]);
// \u6253\u5370\u6362\u5e8f\u540e\u7684\u8f93\u5165\u6570
}

(1)
题目含义是这样的:
有以下变量
int k;
int const nMembers; //已初始化
int currentMembers[nMembers];//值是已经初始化好了的
int memberID; //已初始化
int isAMember;
然后要求是:
遍历currentMember数组,如果包含有和memberID相同的值则把isAMember赋1,否则将其赋0;
代码如下:
for (k=0; i<nMembers; ++k)
{
if(currentMembers[k] = memberID) {
isAMember = 1;
break;
}
}
isAmember = 0;

(2)题目是这样子的:
有以下数据,
int j, k
int const nZips;//已初始化
int zipcodeList[nZips] //已初始化
int duplicates;
要求是,如果sizcodeList数组里有任意两个相同的数则把duplicates赋1,否则赋0;
代码如下:
for (j=0; j < nZips; ++j)
{
for (k=0; k < nZips-j; ++k)
{
if (zipcodeList[j] == zipcodeList[k]) {
duplicates = 1;
break;
}
}
}
duplicates = 0;

(3)
题目是这样的,有以下几个数据
int const ndays; //已初始化
int parkingTickets[ndays] ; //在ndays那天的tickets
int mostTickets, k;
要求是求出最多的tickets那天,并赋给mostTickets
代码如下:
mostTickets = parkingTickets[0]
for(k=1;k < ndays; k++)
{
if(mostTickets < parkingTickets[k])
{
mostTickets = parkingTickets[k];
}
}

不会是翻译方面的障碍吧
(1) Given:
an int variable k ,
an int array currentMembers that has been declared and initialized,
an int variable nMembers that contains the number of elements in the array,
an int variable memberID that has been initialized, and
an int variable isAMember ,
write code that assigns 1 to isAMember if the value of memberID can be found in currentMembers , and that assigns 0 to isAMember otherwise. Use only k , currentMembers , nMembers , and isAMember .

A;
......
isAMember=0;
for(k=0;k<nMembers;k++)
{
if(currentMembers[k]==memberID)
{
isAMember=1;
break;
}
}
......
(2)You are given two int variables j and k , an int array zipcodeList that has been declared and initialized, an int variable nZips that contains the number of elements in zipcodeList , and an int variable duplicates .

Write some code that assigns 1 to duplicates if any two elements in the array have the same value, and that assigns 0 to duplicates otherwise.
Use only j , k , zipcodeList , nZips , and duplicates .

A;
......
duplicates=0;
nZips--;
for(j=0;j<nZips;j++)
for(k=j+1;k<=nZips;k++)
{
if(zipcodeList[i]==zipcodeList[k])
{
duplicates=1;
break;
}
}
......

(3)An array of integers named parkingTickets has been declared and initialized to the number of parking tickets given out by the city police each day since the beginning of the current year. (Thus, the first element of the array contains the number of tickets given on January 1; the last element contains the number of tickets given today.)

A variable named ndays has been declared and initialized to hold the size of the array. (Thus, if today were January 18, ndays would have the value 18; if today were February 3, ndays would have the value 34.)

In addition, a variable named mostTickets has been declared, along with a variable k .

Without using any additional variables, and without changing the values of ndays or the elements of the parkingTickets array, write some code that results in mostTickets containing the largest value found in parkingTickets .

A;
......
mostTickets=parkingTickets[0]
for(k=1;k<ndays;k++)
{
if(mostTickets<parkingTickets[k])
{
mostTickets=parkingTickets[k];
}
}
......

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>

void func1()
{
int k;
int currentMembers[256] = { 5, 10, 15, 20, 25 };
int nMembers = 5;
int memberID = 10;
int isMember;

isMember = 0;
for (k = 0; k < nMembers; k++)
{
if (currentMembers[k] == memberID)
{
isMember = 1;
break;
}
}

printf("isMember: %d\n", isMember);
}

void func2()
{
int j, k;
int zipcodeList[256] = { 5, 10 , 15, 20, 20 };
int nZips = 5;
int duplicates;

duplicates = 0;
for (j = 0; j < nZips - 1 && duplicates == 0; j++)
{
for (k = j + 1; k < nZips; k++)
{
if (zipcodeList[j] == zipcodeList[k])
{
duplicates = 1;
break;
}
}
}

printf("duplicates = %d\n", duplicates);
}

void func3()
{
int parkingTickets[256] = { 5, 10, 7, 11, 10 };
int ndays = 5;
int mostTickets, k;

mostTickets = parkingTickets[0];
for (k = 1; k < ndays; k++)
{
if (mostTickets < parkingTickets[k])
{
mostTickets = parkingTickets[k];
}
}
printf("mostTickets = %d\n", mostTickets);
}

void main()
{
func1();
func2();
func3();
}


都是高手
我真不该进来

扩展阅读:c#考试题库 ... c一维数组求平均数 ... c#语言教程 ... c#面试宝典 ... c#面试题 ... 各国语言翻译器 ... c语言按从小到大输出 ... 以色列语言翻译器 ... c程序中一维数组 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网