你好,我需要一些帮助这个程序:) [英] hello, I need some help with this program:)

查看:70
本文介绍了你好,我需要一些帮助这个程序:)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输出必须是(例如,如果我们选择数字4)

the output has to be (for an example if we choose the number 4)

1
2 3
4 5 6 
7 8 9 10



和我写的程序是


and the program that I wrote is

#include<stdio.h>
void main()
{
int i,j,num;
printf("please enter a number\n");
scanf("\n");
for (j=1;j<=num;j++)
{
for(i=1;i<=j;i++)
printf("...") //this is where I get stuck.
printf("\n");
}
}</stdio.h>

推荐答案

我可以:

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



你确实做对了。你会遇到想要打印的数字。我简单地介绍了一个新的变量,它被打印并递增。


You did actually right. You get stuck with the number you want to print. I simply introduced a new variable, that is printed and incremented.


你期望输出的系列称为 Floyd的三角形。



您可以在这里找到它的程序。
The series you expected as output is called Floyd's triangle.

You can found its program here.


您好用户10409403,请尝试此代码伙伴

Hi User 10409403, try this code buddy
int count=1; //declare and initialize a variable 
//read maxSize with the value you want like 4 or 5 and test for different numbers
for(int i=1;i<=maxSize;i++)
{
	for(j=1;j<=i;j++)
	{
	    printf("%d\t",count++);
	}
printf("\n");
}



因为我没有c编译器,我无法测试,但根据我的逻辑,这将完美。如果有效,请试着告诉我们。



谢谢

Ganesh


As I donot have c compiler with me, I could not able to test but according to my logic that would work perfectly. Please try and let us know if that works or not.

Thanks
Ganesh


这篇关于你好,我需要一些帮助这个程序:)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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