请问这种格式怎么输出来

Bpf345 2015-04-06 02:51:37
输入一个正整数repeat (0<repeat<10),做repeat 次下列运算:

输入一个正整数n, 再输入n 个整数,输出最大值。
输入数据:正整数repeat,输入一个正整数n,再输入n 个整数
输出数据:最大值
输入示例
例:括号内是说明

输入

3 (repeat=3)

4 2 123 -100 0

4 9 1 -1 8

3 1 3 5




输出示例

123

9

5

#include<stdio.h>
int main()
{int repeat,n,a,max,i,j;
scanf("%d(repeat=%d)",&repeat,&repeat);
for(j=1;j<=repeat;j++)
{scanf("%d",&n);
scanf("%d",&max);
for(i=1;i<n;i++)
{scanf("%d",&a);
if(max<a)
max=a;
}}
printf("%d\n",max);
return 0;
}
...全文
187 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Bpf345 2015-04-07
  • 打赏
  • 举报
回复
请大家注意下输出示例是 123 9 5 并不是输入一行后下一行回车输出最大值
anshiny 2015-04-07
  • 打赏
  • 举报
回复
引用 7 楼 Bpf345 的回复:
请大家注意下输出示例是 123 9 5 并不是输入一行后下一行回车输出最大值
int main() {
    int repeat, n, a, max, i, j;
	int result[10] = {0};
    scanf("%d", &repeat);
    for(j=1; j<=repeat; j++) {
        scanf("%d", &n);
        scanf("%d", &a);
        max = a;
        for(i=2; i<=n; i++) {
            scanf("%d", &a);
            if(max < a)
                max = a;
        }
		result[j-1] = max;
    }
	for(j=0; j<repeat; j++) {
        printf("%d\n", result[j]);
    }   
    return 0;
} 
baidu_27192001 2015-04-07
  • 打赏
  • 举报
回复
4楼正解,2楼有问题
guicaisa 2015-04-06
  • 打赏
  • 举报
回复
楼上已给出正确答案,漏脸凭运气接分。。。。
anshiny 2015-04-06
  • 打赏
  • 举报
回复
int main() {
	int repeat, n, a, max, i, j;
	scanf("%d", &repeat);
	for(j=1; j<=repeat; j++) {
		scanf("%d", &n);
		scanf("%d", &a);
		max = a;
		for(i=2; i<=n; i++) {
			scanf("%d", &a);
			if(max < a)
				max = a;
		}
		printf("%d\n", max);
	}	
	return 0;
} 
Bpf345 2015-04-06
  • 打赏
  • 举报
回复
输入3 (repeat=3) 4 2 123 -100 0 4 9 1 -1 8 3 1 3 5 输出示例 123 9 5 请问怎样输出这种格式
苏叔叔 2015-04-06
  • 打赏
  • 举报
回复
仅供参考:


#include<stdio.h>
int main()
{
	int repeat, n, a, max, i, j;
	//scanf("%d(repeat=%d)", &repeat, &repeat);
	scanf("%d", &repeat);
	for (j = 1; j <= repeat; j++)
	{
		scanf("%d", &n);
		scanf("%d", &max);
		for (i = 1; i < n; i++)
		{
			if (i == 1)
				scanf("%d", &max);
			else
			{
				scanf("%d", &a);
				if (a > max) max = a;
			}
		}
		printf("%d\n", max);
	}
	return 0;
}
//3
//2 1 2
//2
//3 1 2 3
//3
//4 1 2 3 4
//4
jiht594 2015-04-06
  • 打赏
  • 举报
回复
先把以前的帖子结了

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧