Search C Program | nimishsoft@gmail.com

Number Pattern - 5

12345
1234
123
12
1

#include <stdio.h>

int main()
{
    int i, j;
    for(i=5;i>=1;i--)
    {
        for(j=1;j<=i;j++)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}


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

28 comments:

  1. what is the error in this code for the above program?
    #include

    main()
    {

    int i,j;
    for( i=1; i>=5;i--)
    {
    for(j=1;j<5-(i-1);j++)
    {
    printf("%d",j);
    }
    printf("\n");
    }
    }

    ReplyDelete
    Replies
    1. How this fow loop condition will get satisfied ??
      for( i=1; i>=5;i--)

      i is eq 1 and your condition is i >=5 which will be false...

      Delete
    2. for condition is false:
      correct condition
      for(i=1;i<=5;i++)

      Delete
    3. This comment has been removed by the author.

      Delete
  2. #include
    using namespace std;
    int main(){
    int n,i,j;
    cout<<"asdf";
    cin>>n;
    for(i=1;i<=n;i++){
    for(j=1;j<n-i+1;j++){
    cout<<j;
    }
    cout<<endl;

    }
    return 0;
    }

    ReplyDelete
  3. write the same program with the help of a while loop

    ReplyDelete
    Replies
    1. /*
      * To represent the parts of a for loop,
      * we'll use the for(x;y;z) representation,
      * where x is the initializer (e.g. i = 1),
      * y is the conditional statement (e.g. i <= j),
      * and z is the increment statement (e.g. ++j).
      *
      * In this code, there are two loops used,
      * so we'll refer to first one as the outer loop,
      * and the second as the inner loop.
      */
      #include

      void main(void)
      {
      int i, j;

      printf("Enter a number (for lines): ");
      scanf("%d", &i); /* If we are to use the value inputted here
      * as the initial value for our outer loop below,
      * then we need not initialize it,
      * i.e., we would leave the x part of the for loop,
      * so it looks like 'for(;y;z)' if we use the for loop
      */

      while (i) // 'while(i)' is basically the same as 'while(i>0)' here
      { // since any nonzero number is considered true. This is the outer y.
      j = 1; // This is the inner x.
      while (j <= i) // The inner y.
      {
      printf("%d ", j);
      ++j; // The inner z.
      }
      printf("\n");
      --i; // The outer z.
      }
      }

      /* You see, the program is really hard to read and maintain
      * if we use while loop for these things, that's why for loops
      * are preferred here.
      */

      Delete
  4. temp=n;
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=temp;j++)
    printf("j");
    temp--;
    printf("\n");
    }

    ReplyDelete
  5. int i,j;
    for(i=1;i<=5;i++) {
    for(j=1;j<=(6-i);j++) {
    printf("%d",j);
    }
    printf("/n");
    }

    ReplyDelete
  6. #include

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

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

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

    return 0;
    }

    ReplyDelete
  7. The soltn is incorrect there is no coding for sopace first apply for loop for space then another for loop to print the pattern

    ReplyDelete
  8. Write a program to input any Sentence and find the longest word and the second longest word.
    eg: India is my Country
    longest word: Country
    Second longest word: India.
    How do i write this program.

    ReplyDelete
  9. somebody please explain me this code

    ReplyDelete
  10. explain this code please

    ReplyDelete
  11. can you write a pragram for belo pattern
    12345
    1234
    123
    12
    1

    ReplyDelete
  12. #include
    int main()
    {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
    for(int j=n;j>=i;j--)
    {
    printf("%d ",n-j+1);
    }
    printf("\n");
    }
    return 0;
    }

    ReplyDelete
  13. int main()
    {
    int k,n,i,j;
    scanf("%d",&n);
    k=n;
    for(i=1;i<=n;i++)
    {
    for(j=1;j<=k;j++)
    {
    printf("%d ",j);
    }
    printf("\n");
    k--;
    }

    return 0;
    }

    ReplyDelete
  14. correct answer is i<=1
    the error is i>=1

    ReplyDelete
  15. In C++ language.

    #include
    using namespace std;

    int main(){
    int n;
    cin >> n;
    int i = 1;
    while(i<=n){
    int j = 1;
    while(j <= n-i+1){
    cout << j;
    j++;
    }
    i++;
    cout << endl;
    }
    }

    ReplyDelete
  16. Helpful article...learn more C programming examples from Pattern Programs

    ReplyDelete
  17. Good brother..here anyone interested in digital marketing, visit expertskeys.com

    ReplyDelete
  18. A2C4E
    1B3D
    A2C
    1B
    A


    PLEASE GIVE ME A SOLUTION

    ReplyDelete
  19. 12345
    1234
    123
    12
    1
    program for this one

    ReplyDelete