Monday 14 March 2016

Pattern 2


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


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


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

1 comment:

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

    }
    n--;
    printf("\n");
    }
    return 0;
    }

    ReplyDelete