Thread: Need Help 2 Questions assignment

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    7

    Question Need Help 2 Questions assignment

    I am new in C programming and i need urgently help about my assignment. Just 2 question i could not find the answers

    Thanks a lot

    1) Input a number N (where <100) and a one-dimensional real array with N elements.
    The program should then find and should output the values that are above the average of the array values.
    ------------------------------------------------------------------
    2) Write a program to perform a searching operation on a one-dimensional array of size100.The values of this array are characters.The program should read the array values and another character value to search for.The search procedure consists of matching the inputted character with one of the array items.If a match is found then an appropriate message should be outputted.Use a function to make the search in your program.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I am new in C programming
    So you posted on the C++ forum (I've moved it)

    > and i need urgently help about my assignment.
    And we need you to urgently read these.
    Announcements - C++ Programming
    Announcements - General Programming Boards

    > Just 2 question i could not find the answers
    'find'?
    If you were thinking you could just google your way through a course then just leave now, and drop the course.

    Help comes to those who show some genuine initiative (posting some code), not fly-by posters who dump their assignment and hope for a finished answer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    7
    Ok thanks for your advices.Sorry but i am new in this forum.And still i am waiting help, i hope somebody understand my situation now,pleasee

  4. #4
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    Let's forget about the second question for now and worry about the first one.

    and a one-dimensional real array
    C doesn't have a 'real' type.
    The program should then find and should output the values that are above the average of the array values.
    Well, the first thing you'd need to do is figure out the average of all the elements in the array. Write a function that does exactly that and store its return value in an object of the same base type of the array you're using. Then write a function that emits only the numbers that are greater than that value.

    One thing you'd need to think about is how you're going to initialise the elements of the array, the test question doesn't specify that so you'd need further clarification (and get the damn type right too). Frankly, I wouldn't worry about any of that for now and just hard-code an array of doubles, like so:

    Code:
    const double f[] = { 12.3, 41.2 10.2, 1.4, 0, 21, 40.5 };
    Then write two functions with the following prototypes:

    Code:
    double average(const double *ptr, size_t nelems);
    
    void print(const double *ptr, size_t nelems, double threshold);
    Though, I'd say the test question is horribly brief and that you'd be better off learning C from a reference like K&R2. Anyway, have fun.

  5. #5
    Registered User
    Join Date
    Mar 2013
    Posts
    7
    Thanks for your reply..My code is this,but i want to add for finding above the avarage also ,do you have an idea ?

    Code:
    #include <stdio.h>
    int main()
    {
      int n, i;
      float num[100], sum = 0.0, average;
      printf("Enter the numbers of data: ");
      scanf("%d", &n);
      while (n > 100 || n <= 0) {
        printf("Error! number should in range of (1 to 100).\n");
        printf("Enter the number again: ");
        scanf("%d", &n);
      }
      for (i = 0; i < n; ++i) {
        printf("%d. Enter number: ", i + 1);
        scanf("%f", &num[i]);
        sum += num[i];
      }
      average = sum / n;
      printf("Average = %.2f", average);
      return 0;
    }
    Last edited by Salem; 03-07-2013 at 08:27 AM. Reason: fixed formatting - use "paste as text" in future

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > for (i = 0; i < n; ++i)
    Use another loop like this, and compare each num[i] with average.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Ah, so the original use of the word 'find' wasn't a translation error after all, it really was meant to convey "hey, I'm just a google code search wannabe"

    Steps 1 and 2 completed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Mar 2013
    Posts
    7
    Copy or not ! i cant learn C programming in one day.But i am trying to solve my problems and i have to give them tomorrow. Anyway, i solve my first question with Salem helps.Thanks.
    But i dont know how to start my second question.Really i could not understand .Anybody has an idea how to do it?

  10. #10
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by maria34 View Post
    i cant learn C programming in one day.But i am trying to solve my problems and i have to give them tomorrow.
    if you have to turn them in tomorrow, I suspect that you had more than one day to accomplish this. perhaps you should not have waited until the last minute to put some effort into it. the "urgency" of your problem is no concern of ours. we have no motivation to be any more helpful to you than to anyone else. the fact that you waited until the day before the assignment is due is your own fault, and dealing with the consequences will be your responsibility, not ours.

  11. #11
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    You'll never learn it by just copying.

    Regarding your question, what have you got so far? Even a "main()" function with a defined character array would be a good start.

    If you can do that much, show us. If you can't - then you might have just copy/pasted your way towards failing a class...

  12. #12
    Registered User
    Join Date
    Mar 2013
    Posts
    7
    Quote Originally Posted by Matticus View Post
    You'll never learn it by just copying.

    Regarding your question, what have you got so far? Even a "main()" function with a defined character array would be a good start.

    If you can do that much, show us. If you can't - then you might have just copy/pasted your way towards failing a class...
    HaHaHa

  13. #13
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by maria34 View Post
    HaHaHa
    See, here I was giving you an opportunity to start the program (i.e. the "easy parts") with the intention of helping you along.

    I'm still up for it. The choice is yours.

  14. #14
    Registered User
    Join Date
    Mar 2013
    Posts
    7
    50 £ ready for second question !!! Come on guysssss

  15. #15
    Registered User
    Join Date
    Mar 2013
    Posts
    7
    Quote Originally Posted by Matticus View Post
    See, here I was giving you an opportunity to start the program (i.e. the "easy parts") with the intention of helping you along.

    I'm still up for it. The choice is yours.
    dont reply my questions.shut up ,go&sleep!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment working but have questions
    By Dynamic in forum C++ Programming
    Replies: 13
    Last Post: 11-04-2011, 02:08 PM
  2. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  3. Replies: 3
    Last Post: 04-26-2009, 08:54 AM
  4. three questions about hw assignment
    By jlmac2001 in forum C++ Programming
    Replies: 8
    Last Post: 09-11-2003, 01:55 PM
  5. can someone help me with this assignment
    By sayeem81 in forum C Programming
    Replies: 3
    Last Post: 01-23-2002, 10:56 AM

Tags for this Thread