getting problem in looping

Discussion in 'C' started by imported_jitendra kumar, Aug 24, 2011.

  1. imported_jitendra kumar

    imported_jitendra kumar New Member

    Joined:
    Aug 4, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    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;
    }
     
  2. DRK

    DRK New Member

    Joined:
    Apr 13, 2012
    Messages:
    44
    Likes Received:
    3
    Trophy Points:
    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;
    } 
     
  3. gpk kishore

    gpk kishore New Member

    Joined:
    Jun 30, 2011
    Messages:
    82
    Likes Received:
    0
    Trophy Points:
    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'
     
  4. imported_jitendra kumar

    imported_jitendra kumar New Member

    Joined:
    Aug 4, 2011
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    thanks for your valuable suggestion.
     
  5. kanchansanyal151

    kanchansanyal151 New Member

    Joined:
    Sep 5, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice