DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2011
    Posts
    1

    [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?!

  2. #2
    Join Date
    Nov 2011
    Posts
    1

    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

  1. Gradebook program
    By [gx]Shadow in forum Java
    Replies: 5
    Last Post: 10-25-2006, 10:20 PM
  2. Replies: 8
    Last Post: 04-24-2006, 10:00 AM
  3. Re: MAKE $$$$$$$$$$ FAST THIS REALLY WORKS
    By Mark Campisi in forum .NET
    Replies: 0
    Last Post: 07-14-2002, 04:05 PM
  4. How do I make a special link?
    By Robert Gelb in forum Enterprise
    Replies: 1
    Last Post: 05-10-2000, 03:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links