?
Solved

loops

Posted on 2003-12-06
13
Medium Priority
?
338 Views
Last Modified: 2007-12-19
I need to make a program which if I input 7 for example the output will be :

*
**
***
****
*****
******
*******
0
Comment
Question by:msaa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 9

Expert Comment

by:tinchos
ID: 9890755
Hi msaa,

I guess that this is a homework assignment and by the site policy we're not allowed to do it for you.
If you try to do it yourself we'll be able to assist you in it.

Here's a hint

The user will enter a number (called n)

foreach number until n

you have to print n '*'

Try coding it yourself and I'll help you as much as I can

Hope this helps

Tincho
0
 

Author Comment

by:msaa
ID: 9890766
thank you, no its not a homework.. we had a homework and I did it which was like this:

#include <stdio.h>

int a,n;

main()

{

printf("Enter N: ");
scanf("%d",&d);

for(a=0;a<d;a=a+1) {
printf("*");      }


            return 0;

                }

but I wanted to modify the code so that it will work as I wanted.. tried alot but couldnt get use of it :(
0
 
LVL 9

Accepted Solution

by:
tinchos earned 150 total points
ID: 9890787
msaa,

Your code was printing just one "*" for each element

try with........

#include <stdio.h>
#include <stdlib.h>

main()
{
      int a, b, d;


      printf("Enter N: ");
      scanf("%d",&d);

      /* I want to print N lines */
      for( a = 1; a <= d; a++ )
      {
             /* For each value of 'a' you have to print 'a' '*' */
             for( b = 1; b <= a; b++ )
                  printf("*");      

             printf( "\n" );
      }

      system( "PAUSE" );

      return 0;
}

Hope it helps

Tincho
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:msaa
ID: 9890804
thanks, what does the new stdlib.h do? is it for the pause? coz were not into it yet.. well im using turbo c++ on windows xp.. the program compiles ok but doesnt run it says undefined symbol_system in module IFS.CPP , and linker error: no module definition file specified : using defaults!
0
 

Author Comment

by:msaa
ID: 9890810
sorry it worked now.. i removed the pause and the stdlib.h ... I dont know whats the use of them and it worked without them :D thank you anyway
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9890855
msaa,

> sorry it worked now.. i removed the pause and the stdlib.h ... I dont know
> whats the use of them and it worked without them :D thank you anyway

yes, the use is for the system( "PAUSE" ); instruction

It does the little "Press any key to continue"......

Tincho
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9890861
msaa,

And glad it helped msaa

Then it's just time to close the question and go on.

Cheers

Tincho
0
 

Author Comment

by:msaa
ID: 9890862
aha, thank you :)
0
 

Author Comment

by:msaa
ID: 9890887
a++ = a+1 right?

why if I changed it to a+1 in the code it gives errors?
0
 
LVL 9

Expert Comment

by:tinchos
ID: 9890891
a++ is the same than a = a + 1;

0
 
LVL 9

Expert Comment

by:tinchos
ID: 9890893
msaa,

In fact

a = a + 1;
a += 1;
a++;
++a;

in this case represents all the same

Tincho
0
 

Author Comment

by:msaa
ID: 9890907
but its not working if i made it a=a+1 ! thats strange
0
 

Author Comment

by:msaa
ID: 9890910
sorry it was a mistake from me.. it worked now.. thank you very much :)(
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question