C语言 数组的问题!!急救!!
(1)Given:anintvariablek,anintarraycurrentMembersthathasbeendeclaredandinitialized,ani...
(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 .
(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 .
(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 .
是网上的作业 英文的 不好意思 请大家多多指教! 展开
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 .
(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 .
(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 .
是网上的作业 英文的 不好意思 请大家多多指教! 展开
展开全部
(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];
}
}
题目含义是这样的:
有以下变量
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];
}
}
......
(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();
}
#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();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
额
都是高手
我真不该进来
都是高手
我真不该进来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询