i m writing a prog. on looping whose output would be J JI JIT JITE JITEN JITEND JITENDR JITENDRA but i am not able to get it compiled and run.i wrote prog as follows: #include<stdio.h> int main(){ int i,j; char ch={'J','I','T','E','N','D','R','A'} for(i=0;i<=8;i++){ for(j=0;j<=i;j++){ printf("%c",ch[]); } printf("\n"); } return 0; }
Use CODE tags to mark source code and use tabulators. Here's correct code with marked elements to fix. Code: #include<stdio.h> int main(){ int i,j; char ch[COLOR="red"][][/COLOR]={'J','I','T','E','N','D','R','A'}[COLOR="Red"];[/COLOR] for(i=0;i[COLOR="red"]<[/COLOR]8;i++){ for(j=0;j<=i;j++){ printf("%c",ch[[COLOR="Red"]j[/COLOR]]); } printf("\n"); } return 0; }
sir(jitendra) u have not initialised it as a character array according to ur declaration only first character will be stored or it may give as error by initalising it as array char ch[9] ur characters are stored as ch[0]='J',ch[1]='I' ..........and so on and last ch[8]='\0'