0

uhm, i really need help on recursion problems, and the first problem before my assignment is me because i really dont know how to do it, or how to construct it successfully... this is my assignment:

a program that will read 10 integers,display them as inputted and in reverse order,
display the minimum and the maximum imput using the following functions:

void readA(int A[])
-a function that reads an array of integers

int minimum(const int A[],int low, int high)
-a recursive function that returns the minimum element in the array A

int maximum(const int A[], int low, int high)
-a recursive function that returns the maximum element in the Array A.

void displayA(const int A[], int low, int high)
-a recursive function that displays the element of array A

void displayrev(const int A[],int low,int high)
-a recursive function that displays the elements of the array A in reverse order

*uhm, and this is my nonsense code that i've done, and even me didnt know what it is doing, but for me, at least i've tried..:'(

#include<stdio.h>
#define inte 10 

void readA(int A[]){
int A[inte];
printf("\nenter an integer : ");
scanf("%d",A[inte]);
}
void displayA(const int A[],int low, int high){
if(low<=high)
{
printf("%d",A[low]);
displayA(A,low+1,high);
}
}
void displayrev(const int A[], int low, int high){
if (a>=0)
printf("\nA[displayrev(a-1)]");
}
main(){
int A[inte];

printf("Enter the numbers AGAIN : ");
scanf("%d",A[inte]);

}

there are many things that i didn't have there, i just dont know how, that's why i need help, please help me...super thanks guys...

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by csurfer
0

Well, we are not supposed to do your homework, but here is some code you can use as starting point. So, the code for the recursive input:

void readA(int A[]){
    if (nr>0) {
        printf("\nenter an integer : ");
        scanf("%d",&A[--nr]);
        readA(A);
    }

And also put this in the main function:

int main(){
int A[inte];

printf("How many numbers : ");
scanf("%d",&nr);
readA(A);
}     
}

where nr is a variable of type int.

P.S. Sorry, I've just noticed that readA shouldn't even be recursive... Well I think its still a good example, and U can use it..

0

Yes you have really messed up the code at some places :)

Well I wont give you the codes but will help you out in pointing your errors and what you need to add to your codes.Here it goes:

void readA(int A[]){
int A[inte];
printf("\nenter an integer : ");
scanf("%d",A[inte]);
}

This code reads entire array so run a for loop to take in all the inputs you are just taking one input.And ya you are passing array A[] from main and taking it here so why are you re-declaring that array within this function ??? There is no need for int A[inte] within.

void displayA(const int A[],int low, int high){
if(low<=high)
{
printf("%d",A[low]);
displayA(A,low+1,high);
}
}

This code is ok and will fulfill your requisite but don't use "const" at all instances because it may cause big problems if used without caution.

void displayrev(const int A[], int low, int high){
if (a>=0)
printf("\nA[displayrev(a-1)]");
}

This code is nothing. It doesn't even print anything.Your approach to displayA is correct so use the same here in a different way as:

void displayrev(const int A[],int low, int high){
if(low<=high)
{
printf("%d",A[high]);
displayrev(A,low,high-1);
}
}

Now the main() .This is completely useless.

main(){
int A[inte];

printf("Enter the numbers AGAIN : ");
scanf("%d",A[inte]);

}

After the declaration of array A[inte]
call the read array A function written just for that purpose. Once this is done you can move on with your other parts of coding.

And ya try your might on a bit difficult things like finding min and max through recursion also.I don't see any code pertaining to it here.Try...;)

This topic has been dead for over six months. 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.