C语言程序设计问题(高手帮下忙)

2024-12-26 02:58:12
推荐回答(3个)
回答1:

#include
main()
{
int i,men,num=1,len=1,sum=1;
int x[]={1,2,3,3,4,4,5,5,5,6};

for(i=1;i<10;i++){
if(x[i]==x[i-1]){
sum=sum+1;
}
else{
num=num+1;
if(len len=sum;sum=1;men=x[i-1];
}
}
}
printf("%d",num);//平台的个数
printf("\n");
printf("%d",len);//最长平台的长度
printf("\n");
printf("%d",men);//构成最长平台的那个数组值
printf("\n");
}

回答2:

#include
#include
#define max 20

int main(int argc, char *argv[])
{int N,arr[max];
int arr1[max][max]={0};
int k,j,i,count;
int m=0,max1=0;
printf("please input total number:");
scanf("%d",&N);
for(i=0;i scanf("%d",&arr[i]);
for(i=0;i {k=0;
m++;
arr1[m-1][k]=arr[i];
for(j=i+1;j if(arr[j]!=arr[i]) {i=j;break;}
else
{arr1[m-1][k++]=arr[j];i=j;}
}
for(i=0;i {count=0;
for(j=0;arr1[j]!=0;j++)
count++;
if(max1 }
printf("the lengthest is:\n");
for(j=0;arr1[j]!=0;j++)
printf("%d",arr1[k][j]);
printf("%d",max1);

system("PAUSE");
return 0;
}

回答3:

#include

int fun(int x[],int size)
{
int * p0,* p1,* pos;
p1=p0=x;
int max=0;
while(p1 {
if(* p1==* p0)
p1++;
else
{
if(p1-p0>max)
{
max=p1-p0;
pos=p0;
}
p0=p1;
}
}
for(p0=pos;p0 printf("%d",* p0);
printf("\n");
return max;
}

void main()
{
int X[]={1,2,3,3,4,4,5,5,5,6};
printf("%d\n",fun(X,sizeof(X)/sizeof(int)));
}