Thread: Assignments help

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    28

    Assignments help

    Hey guys, I am suppose to do this but I am stuck, any help would be appreciated.

    1 - Sum of Squares
    Write a function called sumSquares that returns the sum of the squares of its float array parameter. The function should have a second parameter for the size of the array.

    Example

    Code:
    const int MAX_WORD = 10;
    const int ROW = 3;
    const int COLUMN = 4;
    const int SS1 = 4;
    const int SS2 = 1;
    const int SORTED1 = 8;
    const int SORTED2 = 1;
    const int SORTED3 = 5;
     
    int main()
    {
      // Sum of Squares Tests----------------------------
      float ssArray1[SS1];
      float ssArray2[SS2];
      printf("sum of squares test 1: enter %d numbers\n", SS1);
      for(int i = 0; i < SS1; ++i){
             scanf("%f",&ssArray1[i]);
      }
      printf("sum of squares = %.2f\n", sumSquares(ssArray1, SS1));
     
      printf("\nsum of squares test 2: enter %d numbers\n", SS1);
      for(int i = 0; i < SS1; ++i){
             scanf("%f",&ssArray1[i]);
      }
      printf("sum of squares = %.2f\n", sumSquares(ssArray1, SS1));
     
      printf("\nsum of squares test 3: enter %d numbers\n", SS2);
      for(int i = 0; i < SS2; ++i){
             scanf("%f",&ssArray2[i]);
      }
      printf("sum of squares = %.2f\n", sumSquares(ssArray2, SS2));
     
      // Sorted Tests------------------------------------

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Why are you stuck? Please ask specific questions.

    Jim

  3. #3
    Registered User
    Join Date
    Jan 2013
    Posts
    28
    I don't know what to do, a tip to where to start or what to use would be nice. I am suppose to use the stdio and stdlib only.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    So what does your sumSquares() look like?

    Jim

  5. #5
    Registered User
    Join Date
    Jan 2013
    Posts
    28
    something like this
    Code:
    float sumSquares(float a[], float b)
    {
        int c;
        float total = 0;
        for(c = 0; c < b; ++c)
        {
            total = a[c]*a[c] + total;
        }
        return total;
    }
    is this correct? I am quite confused.

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    Not really the second parameter should be an int, not a float.

    Jim

  7. #7
    Registered User
    Join Date
    Jan 2013
    Posts
    28
    I think I got it, thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with 2 assignments
    By pauzza in forum C Programming
    Replies: 7
    Last Post: 11-23-2010, 03:59 PM
  2. Assignments or challenges
    By Dogmasur in forum C Programming
    Replies: 12
    Last Post: 08-20-2008, 02:24 AM
  3. String assignments
    By mcotter222 in forum C Programming
    Replies: 23
    Last Post: 04-24-2008, 08:50 AM
  4. Need help on one of my assignments
    By engstudent363 in forum C Programming
    Replies: 5
    Last Post: 02-13-2008, 03:24 PM
  5. Embedded assignments
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 08-28-2001, 10:58 AM