12.02.2011

String Triangle

Q. Write a program to display the string INDIA in the following fashion:

I
IN
IND
INDI
INDIA
INDIA
INDI
IND
IN
I

Ans.

/*program to display the string as given fashion*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int x,y;
 static char str[]="INDIA";
 for(x=0; x<5; x++)
 {
    y=x+1;
    printf("%-5.*s\n",y,str);
 }
 for(x=4; x>=0; x--)
 {
    y=x+1;
    printf("%-5.*s\n",y,str);
 }
 getch();
 return 0;
}

Output:-

I
IN
IND
INDI
INDIA
INDIA
INDI
IND
IN
I


You might also like:
  1. Write above program using macro
  2. Write above program using function
  3. Big 98+ C pyramids programs list
  4. Latest asking pyramid programs list

3 comments: