Newbie learnin C, need help on a Ques

Discussion in 'Software' started by Sure, Jun 6, 2005.

  1. Sure

    Sure Private E-2

    This is what i am tryin to write for

    EX: write a program that inputs 3 different integers from the keyboard, then prints the sum, the average, the product , the smallest and the largest of these numbers. use only single-section form of if statements....

    screen should look like this:

    Input three different integers: 13 27 14
    Sum is 54
    Average is 18
    Product is 4914
    Smallest is 13
    Largest is 27



    This is what i got sofar , cant get the smaller and larger to work.......

    #include <stdio.h>

    int main()
    {
    int x,y,z,sum,avg,prod,sml,large;

    printf( "Enter three numbers:" );
    scanf( "%d%d%d" , &x, &y , &z );

    sum = x+y+z;

    printf( "sum is %d\n", sum );

    avg = sum/3;

    printf( "avg is %d\n", avg );

    prod = x*y*z;

    printf( "prod is %d\n", prod );



    return 0;

    }
     
  2. Sure

    Sure Private E-2

    got that one can anyone do this:
    was easy tryin to teach myself aint goin that well



    What i need to do:


    The factorial of a non-negative integer n is written n! (pronounced "n factorial") and is defined as follows:

    n! = n * (n-1) * (n-2) * ... * 1 (for values of n greater than or equal to 1)

    and

    0! = 1

    For example 5! = 5*4*3*2*1, which is equal to 120.

    Write a program that inputs a non-negative integer and computes and prints its factorial. Use a "while loop" as part of your program implementation.

    Implement the program described above using Top-Down, Stepwise refinement (as demonstrated in the Chapter 3 course slides). Include in a large comment block at the start of the program ( start the comment block with /* and end it with */ ) the Pseudo Code produced for the 3 stages of Stepwise refinement.

    As the programmer, you are responsible for making sure that your program is computing the correct values. I will sometimes assist you in this by supplying some of the test data I will be using to test your program. One of the tests I will run is to see if your program can correctly compute 12! (the answer is: 479001600).
     
  3. iamien

    iamien Cptn "Eh!"

    havnt run this buuuuut
    Code:
    assume whatever headers  you need are included,  this is just math and functions
    
    long factorial(long x)
    {
    
       return (x != 0 ) ? ( x * factorial(x - 1) ) : 1; // if x is 0 break recursion
    }
    
    
     
  4. Sure

    Sure Private E-2

    couldnt get it to work .. thx anyways
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds