Click here to Skip to main content
15,903,388 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
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
Posted
Updated 11-Mar-10 4:35am
v2

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;
}
 
Share this answer
 
v2
I think what Eugen Podsypalnikov saying is true...
If you want to make it user define series just add one variable in it.

C#
#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;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900