Help with small C program

This is a discussion on Help with small C program within the C Programming forums, part of the General Programming Boards category; Hello everyone, Am stuck with a small C program question. Heres the question : Write a program to generate and ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    28

    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 :

    Code:
    #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
    Posts
    28
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    So you fixed it then?

    Nevermind - cross-posted anyway
    http://forums.devshed.com/c-programm...am-749991.html

    Closed
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02: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, 09: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

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