Search C Program | nimishsoft@gmail.com

Number Pattern - 19

1
23
456
78910

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



Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C



18 comments:

  1. program to print the above pattern up to a given value n & the program should use a function which takes n as its parameter..........

    pls help me....

    ReplyDelete
    Replies
    1. #include
      int main()
      {
      int i,j,k,n;
      printf("Enter value of n:")
      scanf("%d",&n);
      k=1;
      for(i=1;i<n;i++)
      {
      for(j=1;j<=i;j++)
      {
      printf("%d",k++);
      }
      printf("\n");
      }
      return 0;
      }

      Delete
    2. #include
      int main()
      {
      int i,j,k;
      k=1;
      printf("%d",k);
      printf("\n");
      for(i=2;i<5;i++)
      {
      for(j=1;j<=i;j++)
      {
      printf("%d",k++);
      }
      printf("\n");
      }
      return 0;
      }

      Delete
    3. If k=1 then it will print 2 ati=1 and j=1. We need 1 at I=1and j=1. So we need to put k=0 no?

      Delete
  2. insert printf and scanf to scan the value of n
    then instead of i<5, put i<n

    ReplyDelete
  3. the program has prototype error.

    ReplyDelete
  4. sir pls do this program using only two variable i and j not any other variable

    ReplyDelete
  5. ankita anand ,
    because u cannot predict the value naturally that where its ending in each row that is
    weather 3 6 pr 10
    in the ist line its printing from 1 to 1 as the value of i is equal to 1
    similarly
    in the second line its printing the from the incremented value of i ie
    from 2 to 3 as i = 2 here so two time u are printing two numbers two and 3 as k is also incrementing simultaneously
    got it?

    ReplyDelete
  6. #include

    int main()
    {
    int r,i,j,k;

    printf("Enter the no. of rows : ");
    scanf("%d",&r);

    for(i=1,k=1;i<=r;i++)
    {
    for(j=1;j<=i;j++,k++)
    {
    printf("%d",k);
    }
    printf("\n");
    }
    }

    ReplyDelete
  7. // A program written very silly
    1 // Program will display the following pattern
    2 // 1
    3 // 2 3
    4 // 4 5 6
    5 // 7 8 9 10
    6 #include
    7
    8 int main(void)
    9 {
    10
    11 int i, j, k;
    12
    13 for(i = 1, k = 0; i < 10; ++k, i += k)
    14 {
    15 for(j = i; j <= (k + i); j++)
    16 {
    17 printf("%3d", j);
    18 }
    19 printf("\n");
    20 }
    21 return 0;
    22 }

    ReplyDelete
  8. Sir can you please explain why we are getting output from 1 ,if k++ has been used and it was initialised by 1 the output should start from 2 .

    ReplyDelete
    Replies
    1. k++ is postfix increment, which is done after the statement is executed.

      Delete
    2. Thank you so much sir.

      Delete
  9. #include
    void main()
    {

    int i,j;
    for(i=1;i<5;i++)
    {
    for(j=i*(i-1)/2+1;j<=i*(i+1)/2;j++)
    printed("%d ",j);
    print("\n");
    }
    }

    ReplyDelete
  10. Write a C program for the following pattern?


    0

    7 0 7

    6 7 0 7 6

    5 6 7 0 7 6 5

    4 5 6 7 0 7 6 5 4

    3 4 5 6 7 0 7 6 5 4 3

    2 3 4 5 6 7 0 7 6 5 4 3 2

    1 2 3 4 5 6 7 0 7 6 5 4 3 2 1

    ReplyDelete