Solved

# function

Posted on 2005-03-20
Medium Priority
154 Views

write a member function MAP that maps each element of a sorted list    list1 to its factorial number and stors it in a new sorted list   list2

Example: MAP([1,2,3,4])=[1,2,6,24]

0
Question by:alnaqbi
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 6

LVL 5

Expert Comment

ID: 13586369
#include<iostream>
#include<conio.h>

using namespace std;
int map(int i);

int main()
{
int list1[5]={1,2,3,4,5};
int list2[5];

for(int i=0;i<5;i++)
list2[i]=map(list1[i]);

for(int i=0;i<5;i++)
cout<<list2[i]<<endl;;

getch();
return 0;
}

int map(int i)
{
if(i==0)return 1;
else return re(i-1)*i;
}
0

LVL 5

Expert Comment

ID: 13586372
sorry a bit error:
#include<iostream>
#include<conio.h>

using namespace std;
int map(int i);

int main()
{
int list1[5]={1,2,3,4,5};
int list2[5];

for(int i=0;i<5;i++)
list2[i]=map(list1[i]);

for(int i=0;i<5;i++)
cout<<list2[i]<<endl;;

getch();
return 0;
}

int map(int i)
{
if(i==0)return 1;
else return map(i-1)*i;
}
0

LVL 5

Expert Comment

ID: 13586381
is that what you want?
0

Author Comment

ID: 13614361
thanks beryl666 .. but this the error I got .. can you tell me how to solve it.. thanks

Compiling...
alnaqbi.cpp
c:\documents and settings\c4\desktop\alnaqbi.cpp(15) : error C2374: 'i' : redefinition; multiple initialization
c:\documents and settings\c4\desktop\alnaqbi.cpp(12) : see declaration of 'i'
Error executing cl.exe.

alnaqbi.obj - 1 error(s), 0 warning(s)

0

LVL 5

Expert Comment

ID: 13614906
// i guess you are using visual c++ > it will work now
#include<iostream>
#include<conio.h>

using namespace std;
int map(int i);

int main()
{
int list1[5]={1,2,3,4,5};
int list2[5];

for( i=0;i<5;i++)
list2[i]=map(list1[i]);

for(int i=0;i<5;i++)
cout<<list2[i]<<endl;;

getch();
return 0;
}

int map(int i)
{
if(i==0)return 1;
else return map(i-1)*i;
}
0

LVL 5

Accepted Solution

beryl666 earned 200 total points
ID: 13614912
//sorry again it should be

for(int  i=0;i<5;i++)
list2[i]=map(list1[i]);

for(i=0;i<5;i++)
cout<<list2[i]<<endl;;
0

LVL 5

Expert Comment

ID: 13633472
can you get the answer right?
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base classâ€¦
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article locâ€¦
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
###### Suggested Courses
Course of the Month12 days, left to enroll