Re: [Help Needed] Converting C++ program into Mathematica Function

• To: mathgroup at smc.vnet.net
• Subject: [mg71195] Re: [mg71156] [Help Needed] Converting C++ program into Mathematica Function
• From: "Chris Chiasson" <chris at chiasson.name>
• Date: Fri, 10 Nov 2006 06:37:54 -0500 (EST)
• References: <200611090839.DAA15731@smc.vnet.net>

```Does your MathLink program produce the same output as the Mathematica
code you gave?

On 11/9/06, a1b2c3d4 <ms-z- at hotmail.com> wrote:
> i've tried for quite some time but am still stuck at it.
>
> the C++ program is as follows:
>
> #include<stdio.h>
> main()
> {
> int Current_line, Num_Of_Star, Num_Space;
> int N, Num_Star_Current_line,m;
> printf("\n How many Lines:");
> scanf("%d",&N);
> for(Current_line = 1; Current_line <= N; Current_line=Current_line+1)
> {
>
> Num_Space = N -Current_line;
> for(m =1; m <= Num_Space;m = m+1)
> {
> printf(" ");
> }
>
> Num_Star_Current_line = Current_line * 2 -1;
> for(Num_Of_Star =1; Num_Of_Star <= Num_Star_Current_line; Num_Of_Star= Num_Of_Star + 1)
> {
> printf("*");
> }
>
> printf("\n");
> }
> }
>
>
> The Mathematica function i've tried to write is as follows:
>
> printstars := Block[{n, i, space1, star1},
> n = Input["Enter the number of lines:"];
> For[i = 1, i ¡<= n, i++,
> (space1 = n - i; star1 = i 2 - 1);
> Do[Print[" "], {space1}];
> Do[Print["*"], {star1}];
>
> ]]
>
> However, Mathematica gives output for each * on a new line. I've tried to use the function "StringJoin" but still can't seem to make it work.
>
> Anyone has suggestions? Your help will be greatly appreciated.
>
>

--
http://chris.chiasson.name/

```

• Prev by Date: Re: Insertion into sorted list
• Next by Date: Re: Understanding N and Precision
• Previous by thread: Re: [Help Needed] Converting C++ program into Mathematica Function
• Next by thread: Re: [Help Needed] Converting C++ program into Mathematica Function