| | |
something recursive...
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2008
Posts: 11
Reputation:
Solved Threads: 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..
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...
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..
C Syntax (Toggle Plain Text)
#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...
•
•
Join Date: Jun 2007
Posts: 59
Reputation:
Solved Threads: 3
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: And also put this in the main function:
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..
C Syntax (Toggle Plain Text)
void readA(int A[]){ if (nr>0) { printf("\nenter an integer : "); scanf("%d",&A[--nr]); readA(A); }
C Syntax (Toggle Plain Text)
int main(){ int A[inte]; printf("How many numbers : "); scanf("%d",&nr); readA(A); } }
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..
Last edited by Chaster; Feb 18th, 2009 at 10:38 am.
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:
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.
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.
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:
Now the main() .This is completely useless.
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...
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:
C Syntax (Toggle Plain Text)
void readA(int A[]){ int A[inte]; printf("\nenter an integer : "); scanf("%d",A[inte]); }
C Syntax (Toggle Plain Text)
void displayA(const int A[],int low, int high){ if(low<=high) { printf("%d",A[low]); displayA(A,low+1,high); } }
C Syntax (Toggle Plain Text)
void displayrev(const int A[], int low, int high){ if (a>=0) printf("\nA[displayrev(a-1)]"); }
C Syntax (Toggle Plain Text)
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.
C Syntax (Toggle Plain Text)
main(){ int A[inte]; printf("Enter the numbers AGAIN : "); scanf("%d",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...
I Surf in "C"....
![]() |
Similar Threads
- how to recursive search of subdiretories in BASH script (Shell Scripting)
- Recursive binary search (C)
- recursive findaverage function for Binary search tree (C)
- recursive algorithm (C)
- Recursive prime number f(x) (C)
Other Threads in the C Forum
- Previous Thread: Another Question
- Next Thread: Pipe() and Execve() Problem
Views: 394 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory drawing dynamic executable fflush file fork frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o inches infiniteloop initialization interest kilometer km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape socketprograming spoonfeeding stack standard strchr string strings structures student suggestions system systemcall test testautomation unix user voidmain() wab win32 win32api windows.h





