Thread: Basic function

  1. #1
    Registered User
    Join Date
    Nov 2020
    Posts
    7

    Basic function

    Code:
    • #include <stdio.h>
    • #include <stdlib.h>
    • int main()
    • {
    • int array[10], min = 999999, i;
    • for (i = 0; i < 10; i++)
    • {
    • int num;
    • do {
    • scanf("%d", &num);
    • if (num < 0 || num > 49)
    • printf("Wrong number\n");
    • } while (num < 0 || num > 49);
    • array[i] = num;
    • if (num < min)
    • min = num;
    • }
    • printf("Smallest number: %d", min);
    • return 0;
    • }
    Hello guys, I need to create and insert a simple function above main() maybe any1 has some time and can help me?

  2. #2
    Registered User
    Join Date
    Nov 2020
    Posts
    7
    Im talking about like void, int above main function

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Well what have you tried?

    What would be the purpose of the desired function?

    What have you done other than post this question to research the problem?

  4. #4
    Registered User
    Join Date
    Nov 2020
    Posts
    7
    Well, actually nothing because i cannot think anything i can insert above main function

  5. #5
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Quote Originally Posted by dabraa View Post
    Well, actually nothing because i cannot think anything i can insert above main function
    How are you learning C?

    Are you taking a course from a qualified instructor, studying by yourself from an up to date book on C, or online tutorials and/or YouTube videos?

    In any case, you should have been taught about creating functions, function declaration/prototypes, and function calls.

    If not, then you need to go back and study, and/or review the sections on functions.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Well, actually nothing because i cannot think anything i can insert above main function
    How about a function that reads from stdin, and returns an integer between 0 and 49 ?

    Or generalise it to read from any FILE stream.

    Or generalise it where you can specify the range of valid values.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question of using function in C++
    By faisalfn in forum C++ Programming
    Replies: 4
    Last Post: 12-28-2016, 09:30 PM
  2. C++ basic calling function
    By kaeng in forum C++ Programming
    Replies: 3
    Last Post: 02-06-2010, 05:58 PM
  3. Basic Function Problem
    By AJOHNZ in forum C++ Programming
    Replies: 5
    Last Post: 08-16-2009, 06:12 PM
  4. Function name basic question help
    By kenryuakuma in forum C++ Programming
    Replies: 7
    Last Post: 09-24-2008, 07:48 AM
  5. errors with basic function
    By cDev in forum C Programming
    Replies: 2
    Last Post: 09-23-2006, 09:31 AM

Tags for this Thread