Thread: Help with small C program

  1. #1
    Registered User
    Join Date
    Jul 2010

    Help with small C program

    Hello everyone,

    Am stuck with a small C program question. Heres the question :

    Write a program to generate and display a table of n and n2, for integer values of n
    ranging from 1 to 10.Be certain to print appropriate column headings.

    And this is what I've done till now :

    #include <stdio.h>
    int main ()
        int n, n2 = 0;
        printf ("Enter the integer values:\n\n") ;
        printf ("n        n2\n\n") ;
        printf ("--       ---\n\n") ;
        for (n = 1; n <= 10; ++n)
            n2 += n ;
            printf ("%i     %i\n\n", n, n2) ;
            getchar () ;
            return 0 ;
    I think most probably the part in bold is my mistake but I cant figure out a solution.

    Please help

  2. #2
    Registered User
    Join Date
    Jul 2010
    Sorry guys it was a silly mistake on my part. The bold part should be n2 = n * n

    Thx for reading everyone

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    So you fixed it then?

    Nevermind - cross-posted anyway

    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  2. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  3. Program to reverse a number. small error with it..
    By comproghelp in forum C Programming
    Replies: 8
    Last Post: 11-22-2004, 10:52 AM
  4. Help writing small program
    By guitarhead2000 in forum C++ Programming
    Replies: 2
    Last Post: 10-13-2004, 12:42 PM
  5. A little Help with a small program
    By whtpirate in forum C Programming
    Replies: 7
    Last Post: 06-05-2003, 06:15 PM