#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Arrow Until Number to character.Help please !


    Hello everyone,i'm learning C new myself from one book and I can't write this code,please help me :S

    problem : it's given to us = 2a3b4c5d

    How can i do it to aabbbccccddddd ?

    we must print the char next to the until number ? thank you
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    Start with something like this
    Code:
    int num;
    char ch;
    printf("Enter it\n");
    scanf("%d%c",&num,&ch);
    printf("The number is %d, and the char is %c\n", num, ch );
    Now, can you
    - use num to print ch a number of times?
    - put a loop around the whole thing?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0
    hi again,i can't understand my friend,i can't do it :/ i'm using your code,but i don't know how can i do that.. I mean,

    The problem : 2a3b4c5d(or maybe 5a3c2f6g) it's given to us.

    And the desired from us : print char,until to the left number.. I mean,

    2a3b4c5d = aabbbccccddddd

    5a3c2f6g = aaaaacccffgggggg something like that :/
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0
    hi again,i can't understand my friend,i can't do it :/ i'm using your code,but i don't know how can i do that.. I mean,

    The problem : 2a3b4c5d(or maybe 5a3c2f6g) it's given to us.

    And the desired from us : print char,until to the left number.. I mean,

    2a3b4c5d = aabbbccccddddd

    5a3c2f6g = aaaaacccffgggggg something like that :/
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    Posting the same message twice won't get you anywhere.

    You have the character and the number of times to output it. Do you know how to write a for loop?
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    26
    Rep Power
    0

    until a no.


    hi.i am also a beginner.but i think i understood the problem.add the following intobyoue end of the code
    Code:
    for(int i=1;i <=num;i++){printf("%s",ch);}

IMN logo majestic logo threadwatch logo seochat tools logo