Tuesday 22 August 2017

String Triangle using C Language

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
Graphical Representation :-

String Triangle  using C Language

No comments:

Post a Comment

Intent in Kotlin Android Studio

 Hi larnkoders in this post you are going to learn  about, How to make pass to new activity with information or simply go to new activity on...