how to solve this task

WAP to print:
1
2
3
4
   1
  2 3
 4 5 6
7 8 9 10 
in C.

The number of rows(n) is input by the user.


I have tried the code but m not gettin da required output.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<stdio.h>
#include<conio.h>
void main()
{
  int i,j,k,n;
  clrscr();
  printf("\nEnter the number of rows: ");
  scanf("%d",&n);

  for(i=1;i<=n;i++)
  {

       for(k=n;k>i;k--)
       {

	    printf(" ");

       }

       for(j=1;j<=i;j++)
       {

	    printf("%d ",(i-1)+j);

       }

       printf("\n");

  }

  getch();

}
Well this is a c++ forum.
Still your problem can be solved ,you are not using loops correctly
Code for given output will be as follows::
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,n;
int c=1;
clrscr();
printf("\nEnter the number of rows: ");
scanf("%d",&n);

for(i=1;i<=n;i++)
{

for(k=1;k<=n-i;k++)
{

printf(" ");

}

for(j=1;j<=i;j++)
{

printf("%d ",c);
c++;
}

printf("\n");

}

getch();

}
With Regards,
Matanuragi
I know, dude. You don't go to a c++ forum, especially when cplusplus is the website name and post something other than C++. I mean come on. We specialize in C++, we're glad to help you out but we'll have a hard time understanding it.
Lots of people know C as well as C++. All blue cloud used were a few simple C I/O statements.
Last edited on
It says C++ and stuff, but most people don't care if you need help on C...it's like eker676 said, most people know both.
Topic archived. No new replies allowed.