Search C Program

Number Pattern - 18

55555
45555
34555
23455
12345

int main()
{
  int i, j, k;
  for(i=5;i>=1;i--)
  {
    k = i;
    for(j=1;j<=5;j++)
    {
      if(k <= 5)
      {
        printf("%d",k);
      }
      else
      {
        printf("5");
      }
      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


7 comments:

  1. class Pattern
    {
    public static void main(String arr[])
    {
    int k;

    for(int i=5;i>=1;i--)
    {
    k=i;
    for(int j=1;j<=5;j++)

    {

    System.out.print(k);
    k++;
    if(k>5)
    k=5;

    }
    System.out.println();
    }

    }
    }

    ReplyDelete
  2. Replies
    1. dear sarathi its quite a easy one
      its like how u think to take the values of i and j
      say in the pattern above
      threre are 5 rows which are constantly decreasing ie 5
      4
      3
      2
      1
      so i's value ranges from 5 to 1
      then come to j
      u c j's work is to determine how many times it will print all right ?
      so u would not print j here beacause j's starting from various intergers in various rows so we take the 3rd variable k which is equal to the value of i
      now it(k) would print from 5 to the value of 5 as done by jth row
      so there comes the ist line 5 as 5times now
      i will decrement as i--
      so k also will be equals to 4 as now i =4 so for the second row it will print 4 then k will increment and will print 5 as k still<=5 right?
      then since k will increment to 6 so k would print 5 only as
      if(k <= 5)
      {
      printf("%d",k);
      }
      else
      {
      printf("5");
      }
      k++;
      so any value greater than 5 for k would be printed as 5 upto 5 times as j remains within i to 5 only
      so this would continue until i reaches 1
      this was the full explanation of how this code works
      my suggestion u always must bresk up a code into units and then analyze

      Delete
  3. #include

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

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

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

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

    ReplyDelete
  4. Write a Java program for the given problem George loves to play with numbers. His friend Zuckerberg gives him two numbers to add. Zuckerberg writes sometimes 6 as 5 and vice versa. Given two numbers as x and y. Find the maximum and minimum sum Zuckerberg could possibly get the numbers?

    ReplyDelete
  5. It could be done simply like this also
    Int i, j,k,l;
    For(I=5; I>=1;i--)
    {
    For(j=I;j<=4;j++)
    {
    Pritf("%d",j);
    }
    For (k=1;k<=I; k++)
    {
    l=5;
    Printf("%d",l);
    }

    Printf ("\n");
    }

    ReplyDelete
  6. #include
    void main()
    {
    int i,j,k;
    for(i=5;i>=1;i--)
    {
    k=i;
    for(j=1;j<=5;j++)
    {
    k<=5?printf("%d",k++):printf("5");
    }

    printf("\n");
    }

    }

    ReplyDelete