第一行为一个整数n(n
接下来的2*n行,每2行一组,分别表示一部电影的名字和票房,其中名字部分长度
#include
int main()
{
int n;
scanf("%d",&n);
int i,j,ti[n],t=0;
char s[n][50];
for(i=0;i<n;i++)
{
printf("Enter the amount of the ticket:");
scanf("%d",&ti[i]);
printf("Enter the name of the film:");
for(j=0;s[i][j]!='\0';j++)
{
scanf("%c",&s[i][j]);
}
}
for(i=0;i<n;i++)
{
if(t<ti[i]) t=i;
}
for(i=0;i<50;i++)
{
printf("%c",s[t][i]);
}
}

新手请教C语言问题 找不出代码的错误 感谢
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
6条回答 默认 最新
- 计算机废物 2017-01-07 11:06关注
#include
#include
int main()
{int i,j,ti[100],t=0;//数组要一开始就分配好长度,不能那样子定义
char s[100][50];
for(i=0;i<100;i++)
{
printf("Enter the amount of the ticket:");
scanf("%d",&ti[i]);
printf("Enter the name of the film:");
for(j=0;s[i][j]!='\0';j++)
{
scanf("%c",&s[i][j]);
}
}
for(i=0;i<100;i++)
{
if(t<ti[i]) t=i;
}
for(i=0;i<50;i++)
{
printf("%c",s[t][i]);
}
}本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报