0

//This is an example, coding not complete. Say main runs the function add, int add adds two random numbers and int random gets a random number from the array. By keeping 3 functions, how would I pass b and c to int add? Right now b and c are undeclared

int main{
add()
}


int add(){
 d = b + c
 printf("the sum of two random nubmers are %d, d)

int ranom(){ 
    a = [1,2,3,4,5,6]
    b = rand[a]
    c = rand[a]
2
Contributors
1
Reply
11
Views
2 Years
Discussion Span
Last Post by deceptikon
0

Functions support parameters, which are designed for this exact purpose:

int add(int a, int b)
{
    return a + b;
}

int main(void)
{
    int a = 5;
    int b = 2;
    int c = add(a, b);

    printf("%d + %d = %d\n", a, b, c);

    return 0;
}

This is basic C that any reference will cover

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.