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

    Join Date
    Sep 2013
    Rep Power

    A C exercise: Urgent!

    hey i am a beginner and really stuck in assignment:

    Display the alphabet on the screen, one letter on each line. Next to each letter, each line should also contain an average (obtained through the use of a running total) of all letters displayed in the left-hand column up to that point.

    We can only use the running total and a total of 3 Printf statement in the whole program.

    The output of program is suppose to look like this :

    a a
    b a
    c b
    d b
    e c
    f c
    g d
    h d
    i e
    j e
    y m
    z m

    This is what i have coded so far but i am just confused

    #include <stdio.h>
    int main()
    char columm1 = 0;

    int i = 0
    int total = 0
    for (i = 0; i < 27; i++)
    printf("%c, %c /n", columm1, total);

    return 0;

    Please help me with what i have done wrong
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Rep Power
    If you've got a value, say
    int i = 0;

    and you want to print 'a', then you do this

    printf("%c\n", i + 'a' );

    Also, please use [code][/code] tags when posting code.

    Typical - another cross-poster
    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

IMN logo majestic logo threadwatch logo seochat tools logo