Can you solve it for me!!

View previous topic View next topic Go down

Can you solve it for me!!

Post by BIT0112-Rokon on Mon Sep 27, 2010 5:01 am

Write a recursive program to remove all odd integers from an array. You must not use any extra array or print anything in the function. Just read input, call the recursive function, then print the array in main().

Input:
6
1 54 88 6 55 7
Output:
54 88 6

NOTE: its a copy/paste problem.

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী
avatar
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Re: Can you solve it for me!!

Post by BIT0104-ANIK on Mon Sep 27, 2010 5:12 am

input to array tei prothome nite hobe naki?

_________________________________________________________________
Buddhong shoronogocchami..
dhommong shoronogocchami..
shonghong shoronogocchami..
Jogoter sokol prani.. shukhi hok.
avatar
BIT0104-ANIK
Administrator
Administrator

Course(s) :
  • BIT

Blood Group : O+
Posts : 423
Points : 699

View user profile http://anikstech.blogspot.com

Back to top Go down

Re: Can you solve it for me!!

Post by BIT0112-Rokon on Mon Sep 27, 2010 5:22 am

hmm..
you have to take only one array and that is for taking input.. but you should not take any extra array while processing ...... thats all..........

_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী
avatar
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Re: Can you solve it for me!!

Post by BIT0102-Mohaimin on Tue Sep 28, 2010 10:43 pm

Why is the RECURSIVE thing added if I can solve it without recursion!!! recursion consumes more Memory+Time...
avatar
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

View user profile

Back to top Go down

Re: Can you solve it for me!!

Post by BIT0102-Mohaimin on Tue Sep 28, 2010 11:12 pm

Here is a BAD solution:

Code:

#include <iostream>

using namespace std;

void recurse(int *arr, int &removed, int checkAt, int length){   
   if (checkAt == length - removed){
      return;
   }
   
   if (arr[checkAt]%2){
      for (int i = checkAt; i < (length - removed); i ++){
         arr[i] = arr[i+1];
      }
      recurse(arr, ++removed, checkAt, length);
   }else{
      recurse(arr, removed, ++checkAt, length);
   }
}

int main (){
   int length;
   cin>>length;
   
   int *arr;
   arr = new int[length];
   for (int i = 0; i < length; i ++){
      cin>>arr[i];
   }
   int removed = 0;
   
   recurse(arr, removed, 0, length);
   
   for (int i = 0; i < length-removed; i ++){
      cout<<arr[i]<<" ";
   }
   
   cout<<endl;   
   
   return 0;
}
avatar
BIT0102-Mohaimin
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : B+
Posts : 415
Points : 715

View user profile

Back to top Go down

Re: Can you solve it for me!!

Post by BIT0112-Rokon on Wed Sep 29, 2010 5:55 am

Thanks Mohaimin.. Im trying to figure out recursion actually. I know it consumes time and memory. But it sometime sounds good while problem solving ...


_________________________________________________________________


Code Explosion Blog | Code Explosion Wiki | The Rokonoid | নির্ঝরিণী
avatar
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

View user profile http://blog.codexplo.org

Back to top Go down

Re: Can you solve it for me!!

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum