-
[Java] Make triangle with the special char * without using Loops!!!
Hello,
i want to make a triangle without the use of loops(For,while,do while etc)
For example Lets say that i give as input the number 4. The output must be:
*
* *
* * *
* * * *
Its very easy using loops but without?!
-
Able to solve it using Recusrion
//Devendra - 9762114222
//Mail me at - dev4developer@yahoo.co.in
#include <stdio.h>
#include <conio.h>
void print_output(int);
void print_star(int);
int main(){
int input = 0;
clrscr();
printf("Enter input:");
scanf("%d", &input);
print_output(input);
getch();
return 0;
}
void print_output(int n){
static int i =1;
if(i> n)
return;
else{
print_star(i);
printf("\n");
i++;
print_output(n);
}
}
void print_star(int n){
if(n==0)
return;
else{
printf("*");
n--;
print_star(n);
}
}
Similar Threads
-
By [gx]Shadow in forum Java
Replies: 5
Last Post: 10-25-2006, 10:20 PM
-
Replies: 8
Last Post: 04-24-2006, 10:00 AM
-
By Mark Campisi in forum .NET
Replies: 0
Last Post: 07-14-2002, 04:05 PM
-
By Robert Gelb in forum Enterprise
Replies: 1
Last Post: 05-10-2000, 03:40 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks