JIGYASA

An online placement forum.


You are not connected. Please login or register

Print -> 1 to N...

Go down  Message [Page 1 of 1]

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

Lucifer


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

View user profile http://jigyasa.forumn.org

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

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

View user profile

3 @indranil on 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....

View user profile http://jigyasa.forumn.org

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

#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;

}

View user profile

5 @kelamatha on Sat Apr 17, 2010 4:05 pm

Lucifer


Admin
correct...

View user profile http://jigyasa.forumn.org

6 #another solution# on Sat Apr 17, 2010 4:10 pm

Lucifer


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

View user profile http://jigyasa.forumn.org

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

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

View user profile

Sponsored content


Back to top  Message [Page 1 of 1]

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