Solved

# function

Posted on 2005-03-20
Medium Priority
155 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
• 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

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â€¦
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticallâ€¦
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.
###### Suggested Courses
Course of the Month8 days, 3 hours left to enroll