Friday, 3 July 2015

Inverted Right Triangle

Write a program to do the following :

a) Take height h as the input
b) Based on the height, print h lines in output such that they form a pattern in the shape of an "inverted" right angled triangle
c) Each line should form an Arithmetic Progression with the starting element = row_number and common difference = 1. Take modulo 10 for numbers greater than 9

Input Format :
A single integer representing the height of the pattern

Output Format :
Output should contain lines equal in number to the height of the pattern with each line representing a row. Display the pattern with no extra empty lines above or below the pattern or in between successive rows of the pattern.

Example :

Input 
6

Output
123456
23456 
3456  
456   
56    
6

/*CODE*/
#include<stdio.h>
int main()
{
int N,i,j,temp;
scanf("%d",&N);
for(j=N;j>0;j--)
{
for(i=N-j+1;i<=N;i++)
{
temp=i%10;
printf("%d",temp);
}
printf("\n");
}
return 0;
}

No comments:

Post a Comment