Thread: Help with simple operations

  1. #1
    Registered User
    Join Date
    May 2006
    Location
    Chicago
    Posts
    2

    Help with simple operations

    Hello,

    I am brand new to programming in C and am having some trouble with a very simple program. I am attemting to find the average, sum and product of two numbers (taken as paramaters). The code compiles but gives obviously wrong results.

    the ouput is:

    The sum is 4013265
    The product is 4013264
    The Average is 2006632


    Any help Would be appreaciated. Feel free to criticise my code.

    Thanks.
    Code:
     
     
    int main(int n1,int n2) 
    {
    int o1=n1+n2; /* o1, o2, 03 are output variables */
    int o2=(n1*n2);
    int o3=((n1+n2)/2);
    printf("The sum is %d \n",o1 );
    printf("The product is %d \n", o2);
    printf("The Average is %d \n",o3);
    exit(0);
    }

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    May 2006
    Location
    Chicago
    Posts
    2
    Thanks for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 11:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 08:52 AM