使用嵌套的for语句编写cprogram(作业) [英] write a cprogram using nested for statements (Homework)

查看:113
本文介绍了使用嵌套的for语句编写cprogram(作业)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写一个用于嵌套语句的cprogram,以对以下输出进行dicplay:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

write a cprogram usung for nested statements to dicplay the following output:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

推荐答案

请对其进行测试:):

Please test it :) :

#include <stdio.h>
 
int main()
{
  int i, j;
  for (i = 1; i <= 5; i++) {
    for (j = 1; j <= i; j++) {
      prinf("%d ", i);
    }
    printf("\n");
  }
  return 0;
}


我认为Eugen Podsypalnikov所说的是真的...
如果要让用户定义系列,只需在其中添加一个变量即可.

I think what Eugen Podsypalnikov saying is true...
If you want to make it user define series just add one variable in it.

#include <stdio.h>

int main()
{
  int i, j, n;
  printf("Enter range : ");
  scanf("%d",&n);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= i; j++) {
      prinf("%d ", i);
    }
    printf("\n");
  }
  return 0;
}


这篇关于使用嵌套的for语句编写cprogram(作业)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆