Thread: Making A Program That Outputs Array Values

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    23

    Making A Program That Outputs Array Values

    Can anyone help me write this program in C. Im drawing a blank right now and cant figure out what Im Supposed to do. I know that the User is supposed to input a number of values then input each value individually.

    Sending and Scanning an Array in C?
    I dont really understand what i'm supposed to do here. It supposed to scan the user input values in an array then figure out which is the smallest, biggest, and average

    The prototypes for the functions must be:

    void GetValues(int x[], int *pN);
    int FindBig(int x[], int n);
    int FindSml(int x[], int n);
    float FindAvg(int x[], int n);

    GetValues should put values in both the x[] array and at *pN
    FindBig should return the largest integer in the first n elements of x[]
    FindSml should return the smallest integer in the first n elements of x[]
    FindAvg should return the average of the first n elements of x[]

    Thus, the main program should look something like the following:
    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    // prototypes as listed above
    void main()
    {
    int a[100], myBig, mySml, n;
    float myAvg;
    GetValues(a,&n);
    myBig=FindBig(a,n);
    mySml=FindSml(a,n);
    myAvg=FindAvg(a,n);
    printf("The largest value is: %d\n",myBig);
    printf("The smallest value is: %d\n",mySml);
    printf("The average value is: %.2f\n",myAvg);
    }

    Example of What Its Supposed to Do.

    Enter number of integer values: 5
    Enter value 1: 20
    Enter value 2: -15
    Enter value 3: 90
    Enter value 4: 2
    Enter value 5: 30
    The largest value is: 90
    The smallest value is: -15
    The average value is: 25.40

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    So just use scanf to read every single number in the array.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    23
    I tried that It wont work.

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by xxxixpats View Post
    I tried that It wont work.
    Post here what you have tried.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c++ parrallel array program
    By corbinc in forum C++ Programming
    Replies: 1
    Last Post: 11-07-2009, 01:10 PM
  2. Replies: 16
    Last Post: 05-29-2009, 07:25 PM
  3. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  4. making a math quiz program
    By mackieinva in forum C Programming
    Replies: 10
    Last Post: 09-17-2007, 03:38 PM
  5. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM