JIGYASA
Would you like to react to this message? Create an account in a few clicks or log in to continue.
JIGYASA

An online placement forum.


You are not connected. Please login or register

Print -> 1 to N...

4 posters

Go down  Message [Page 1 of 1]

1Print -> 1 to N... Empty Print -> 1 to N... Sat Apr 03, 2010 3:38 pm

Lucifer


Admin

WAP to print nos. from 1 to N without using any looping construct...

https://jigyasa.forumotion.com

2Print -> 1 to N... Empty Re: Print -> 1 to N... Mon Apr 05, 2010 10:15 am

indranil



Lucifer wrote:WAP to print nos. from 1 to N without using any looping construct...

recursion, isn't it? Wink. I leave it with this hint Smile

3Print -> 1 to N... Empty @indranil Mon Apr 05, 2010 4:41 pm

Lucifer


Admin

Yes, u r correct.... Now that everyone knows how to get to the solution, can somebody post a fully working code for the same....

https://jigyasa.forumotion.com

4Print -> 1 to N... Empty Re: Print -> 1 to N... Fri Apr 16, 2010 3:02 pm

kelamatha



#include "stdafx.h"

//! this is where the count starts
#define min 1
//! this is my n
#define max 5

//! function signature
int mynumber( int a );

int _tmain(int argc, _TCHAR* argv[])
{
int i = ( int ) min ;
return mynumber( i );
}

//! my number definition
int mynumber( int a )
{
//! print the current value of a
printf("\n%d ", a );

if( a == (int) max )
{
//! do not do anything we have reached the max n
}
else
{
//! call this function recursively
mynumber( a + 1 );
}
//return to the caller here it is main
return a;

}

5Print -> 1 to N... Empty @kelamatha Sat Apr 17, 2010 4:05 pm

Lucifer


Admin

correct...

https://jigyasa.forumotion.com

6Print -> 1 to N... Empty #another solution# Sat Apr 17, 2010 4:10 pm

Lucifer


Admin

void print (int n)
{
if (n!=0)
{
print(n-1);
printf("%d\n", n);
}
return;
}

https://jigyasa.forumotion.com

7Print -> 1 to N... Empty Re: Print -> 1 to N... Sat May 01, 2010 2:22 pm

pro



void print(int n)
{
if(n==0)
return;
print(n-1);
printf("%d",n);
}

Sponsored content



Back to top  Message [Page 1 of 1]

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