Help programs with functions "third year secondary school"

This is a discussion on Help programs with functions "third year secondary school" within the C Programming forums, part of the General Programming Boards category; Hi, i'm new to this forum. I attend the third year of secondary school. today the teacher explained the functions ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    7

    Help programs with functions "third year secondary school"

    Hi, i'm new to this forum.
    I attend the third year of secondary school.
    today the teacher explained the functions but i didn't understand very well. kindly help me to carry out these programs in c. I use DevC++.

    1- Calculate the sum and average of two vectors containing 5 integers. Compare the values ​​of the average viewing an appropriate message.
    -Parameters of the average (sum, n_ele)
    -Program with refunds

    Thanks !

    An example of my programs
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    void Doppio (int n);
    void Triplo (int n);
    int main(void) {
        int n;
        printf("immetti n "); 
        scanf("%d",&n);
        Doppio(n);
        Triplo(n);
        system("pause");
        }
    void Doppio (int n) {
         int Doppio;
         Doppio=n*2;
         printf("Il Doppio e' %d\n", Doppio); 
         return;
         }
    void Triplo (int n) {
         int Triplo; 
         Triplo=n*3;
         printf("Il Triplo e' %d\n", Triplo);
         return;
    }

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Parameters of the average (sum, n_ele)
    Okay, so:

    Code:
    int average (int sum, int n);
    Where "sum" is the total of the values in the vector, and n is the number of values in the vector. The function returns an int. The definition is about 2-3 lines at most. I'm sure you've done enough math to figure out what they should be.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    7
    Thanks for the answer
    This is the program, how do you think, it's ok?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    float media (float s, int n);
    float media2 (float s2, int n);
    main () {
         int n=5, i, v[n], v2[n], st;
         float s=0, s2=0;
         for(i=0; i<n; i++) {
         printf("Enter numbers first vector ");
         scanf("%d",&v[i]);
         }
         for(i=0; i<n; i++) {
         printf("Enter numbers second vector ");
         scanf("%d",&v2[i]);
         }
         for(i=0; i<n; i++) {
                  s=s+v[i];
                  }
         for(i=0; i<n; i++) {
                  s2=s2+v2[i];
                  }
         st=s+s2;
         printf("the sum of two vectors is %d\n",st);
         media(s,n);
         media2(s2,n);
         if(media>media2) {
         printf("The average of the first carrier is greater than the average of the second vector\n");
         }
         else {
         printf("The average of the second carrier is greater than the average of the first vector\n");
              }
         system("pause");
         }
         float media (float s, int n) {
             float media;
             media=s/5;
             printf("The average of first vector is %.2f\n",media);
             return media;
             }
         float media2 (float s2, int n) {
               float media2;
               media2=s2/5;
               printf("The average of second vector is %.2f\n",media2);
               return media2;
               }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 01-13-2008, 09:38 PM
  2. "action on key hold" programs?
    By siddharth2212 in forum C++ Programming
    Replies: 11
    Last Post: 07-29-2007, 12:19 PM
  3. running programs as "hidden" or in the "background"
    By Leeman_s in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2002, 03:47 AM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM

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