PLEASE HELP!!! diagonal output?

This is a discussion on PLEASE HELP!!! diagonal output? within the C Programming forums, part of the General Programming Boards category; Please help me, I am really having a hard time to program these: 1. Write a program that input integer ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    3

    Question PLEASE HELP!!! diagonal output?

    Please help me, I am really having a hard time to program these:

    1. Write a program that input integer and displays the digits diagonally.
    Ex. Entered number: 3562
    output: 3
    5
    6
    2

    2. Write a program that read in a number n and then outputs the sum of the aquares of the number n and then outputs the sum of the squares of the numbers from 1 to n. if the input is 3, for example, the output should be 14. The program should allow the user to repeat this calculation as often as desired.

    --------------------------------------------------------------------
    I tried solving it but there are always errors. I think looping is needed to solve that. And how to display the output diagonally?
    pls help.

    Here's what ive tried for number 1:
    Code:
    #include<stdio.h>
    #include<conio.h>
    
    void main () {
    
    char string[256]:
    printf("input nuber: \n");
    scanf("%s", &number);
    
    printf("%s", string);
    
    getch();
    }
    I know that it is not right but that is the only idea i have.

    PLEAS HELP.
    This kind of question is included in our exam.
    Last edited by grace12bueno; 08-27-2009 at 09:13 PM. Reason: for correction.

  2. #2
    Registered User
    Join Date
    Aug 2009
    Posts
    3
    im sorry, the output of number should be in diagonal. the example misfunctioned.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    Read the numbers into a string, and output it using a loop.

  4. #4
    Registered User
    Join Date
    Aug 2009
    Posts
    3
    is that already correct? We haven't discussing that lesson yet. I have just do lots of research.

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    void main () {
    
    char string[256]:
    printf("input nuber: \n");
    scanf("%if", &string);
    
    printf("%if", string);
    
    getch();
    }
    Last edited by grace12bueno; 08-27-2009 at 09:16 PM. Reason: correction

  5. #5
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    The input part is right, but you need to output it with a loop, treating the string as an array (instead of a string).

  6. #6
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by grace12bueno View Post
    is that already correct? We haven't discussing that lesson yet. I have just do lots of research.

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    void main () {
    
    char string[256]:
    printf("input nuber: \n");
    scanf("%if", &string);
    
    printf("%if", string);
    
    getch();
    }
    1. void main is wrong. USe int main(void) instead.
    2. What is %if?
    3. string itself is an address, so you dont need '&' with it in scanf().
    4. Note the colon(instead of ; ) in the first line after main.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  7. #7
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by grace12bueno View Post
    is that already correct? We haven't discussing that lesson yet. I have just do lots of research.

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    void main () {
    
    char string[256]:
    printf("input nuber: \n");
    scanf("%if", &string);
    
    printf("%if", string);
    
    getch();
    }
    My solution will be :
    1.Input the string.
    2. Print the chars of the string using width specifiers of varying width. That will output the chars of the string in diagonal format.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 02:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 02:08 PM
  3. Replies: 4
    Last Post: 11-30-2005, 03:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 04:27 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21