Monday 14 March 2016

Pattern 4


Write a program to print the given pattern.

Input Format:
Input consists of a single integer.

Output Format: 
Refer sample outputs. There is a trailing space at the end of each line.

Sample Input:
5

5 4 3 2 1
5 4 3 2
5 4 3 
5 4
5

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

2 comments:

  1. This is correct code:

    #include
    int main()
    {
    int n,i,j,x=1,k;
    scanf("%d",&n);
    k=n;
    for(i=1; i<=n; i++)
    {
    for(j=k;j>=x;j--)
    {
    printf("%d ",j);
    }
    x++;

    printf("\n");

    }

    return 0;
    }

    ReplyDelete