Someone help me creating a this program. Well, I need a program that makes a triangle out of asterisk but it doesnt use "for" loop it only requires "do-while" loop. Actually I tried making one but it doesn't look like a triangle instead it jsut display a line of asterisk.

#include<stdio.h>
#include<conio.h>
int main()
{
int integer, counter, counter2;
counter = 0;
counter2 = 0;
printf("Enter a number: ");
scanf("%d",&integer);
do {
    printf("*");
    integer++;
    }while(counter<0);

do {
    printf("*");        
    counter++;

    }while(counter<integer);

getch();
return 0;
}

Recommended Answers

All 3 Replies

  1. One do loop needs to enclose the other.
  2. The variable in the inner loop (perhaps counter) needs to reset to zero everytime the outer loop starts.
  3. After the inner loop, print a "\n" (This starts a new line.)
  4. The inner loop variable (counter)needs to be less than the outer loop variable (counter2) which in turn needs to be less than the input variable (integer).
  5. This is much easier to do with for loops, but I'm guessing you're stuck with do-while.

This was already tackled at this post, see the doing, and try to apply to your need:
Click Here
Search the forums first, you'll be amazed of what you can find. ;)

@DeanMSands Yes sir indeed, I still can't use the for loop cause right now I am still tackling about do-while loop. Can you give me a code sir?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.