what is the solution

Discussion in 'C Programming' started by wahid, Jan 10, 2010.

  1. wahid

    wahid Guest

    • Write a program, that would take a number n
    from user, and then output the square and
    cube of first n natural numbers.

    Sample Output
    • Enter a number: 5
    • Output for 1: square 1, cube 1
    • Output for 2: square 4, cube 8
    • Output for 3: square 9, cube 27
    • Output for 4: square 16, cube 64
    • Output for 5: square 25, cube 125
     
    wahid, Jan 10, 2010
    #1
    1. Advertising

  2. wahid

    Ian Collins Guest

    wahid wrote:
    > • Write a program


    There's a novel idea, why don't you give it a try?

    --
    Ian Collins
     
    Ian Collins, Jan 10, 2010
    #2
    1. Advertising

  3. On 10 Jan 2010 at 7:08, wahid wrote:
    > • Write a program, that would take a number n from user, and then
    > output the square and cube of first n natural numbers.


    #include <stdio.h>
    #include <limits.h>

    int main(void)
    {
    int i, d, rv = 0;
    fputs("Enter a Number: ", stdout);
    fflush(stdout);
    if(scanf("%d", &d) == 1 && d >= 1) {
    if(1. * d * d * d > ULLONG_MAX) {
    fputs("Integer overflow\n", stderr);
    rv = 1;
    } else
    for(i = 1; i <= d; i++)
    printf("Output for %d: square %llu, cube %llu\n", i, 1ULL * i * i,
    1ULL * i * i * i);
    } else {
    fputs("Invalid input: needed a positive integer\n", stderr);
    rv = 1;
    }
    return rv;
    }
     
    Antoninus Twink, Jan 10, 2010
    #3
  4. On Jan 10, 9:22 am, Francis Glassborow
    <> wrote:
    > wahid wrote:
    > > Write a program, that would take a number n
    > > from user, and then output the square and
    > > cube of first n natural numbers.

    >
    > > Sample Output
    > > Enter a number: 5
    > > Output for 1: square 1, cube 1
    > > Output for 2: square 4, cube 8
    > > Output for 3: square 9, cube 27
    > > Output for 4: square 16, cube 64
    > > Output for 5: square 25, cube 125

    >
    > This is the fourth problem you have posted here without any added
    > material from you.
    >
    > Either you are an unbelievably lazy student, or you are too stupid to be
    > studying programming or you are an extremely bad troll.
    >


    He's obviously Twink's alter ego. ;-)
     
    Michael Foukarakis, Jan 11, 2010
    #4
  5. wahid

    Albert Guest

    wahid wrote:
    > • Write a program, that would take a number n
    > from user, and then output the square and
    > cube of first n natural numbers.
    >
    > Sample Output
    > • Enter a number: 5
    > • Output for 1: square 1, cube 1
    > • Output for 2: square 4, cube 8
    > • Output for 3: square 9, cube 27
    > • Output for 4: square 16, cube 64
    > • Output for 5: square 25, cube 125


    #include <stdio.h>

    int main()
    {
    int i, n;

    printf("Enter a number: ");
    scanf("%d", &n);
    for (i = 1; i <= n; i++)
    printf("Output for %d: square %d, cube %d\n", i, i * i, i * i * i);
    return 0;
    }
     
    Albert, Jan 20, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Francis
    Replies:
    0
    Views:
    435
    Andrew Francis
    Jun 28, 2006
  2. =?Utf-8?B?Y2FzaGRlc2ttYWM=?=

    Solution file not in the solution folder

    =?Utf-8?B?Y2FzaGRlc2ttYWM=?=, Sep 12, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,128
    Laurent Bugnion
    Sep 12, 2006
  3. , India
    Replies:
    17
    Views:
    1,093
    James Kanze
    Oct 1, 2007
  4. Replies:
    8
    Views:
    523
  5. email55555 email55555

    [SOLUTION] Ruby Quiz #14 LCD Numbers ( solution #2 )

    email55555 email55555, Jan 9, 2005, in forum: Ruby
    Replies:
    16
    Views:
    295
    David Tran
    Jan 10, 2005
Loading...

Share This Page