can someone make a simple program that prints numbers in series depending on the persons input ..


for eg :-

if input is 5 then output should be :

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

....please help asap ..
thank you in advance ...

Recommended Answers

All 18 Replies

>make a simple program
If its so simple, why can't you do it?, or at least make an attempt at it.
All you need to know to be able to do this, is how to use nested loops and from there i'm sure you could figure it out yourself.

here is a hint

loop()//handle the row
{
[INDENT]loop()//handle the colum
{//print row here
}[/INDENT]
}

thanks for your help .... actualli i fall in to that "students asking help for homework without attempting it... " category..

i will giv it a try now .. thanks for ur hint absentshadow ...

here is my partially successful attempt at making this program ....

so now if my input is 5, my output is:

.....1
....1 
...1 
..1
.1

but my desired output is :

.....1
....1 2
...1 2 3
..1 2 3 4
.1 2 3 4 5
#include<iostream.h>
#include<conio.h>
#include<string>

void main()
{

int a, b , c, row, et, eta  ;
string  i;


cout<<"enter the number of rows \n" ;
cin>>a;

row = a;
et = row;
eta = et;
i = "1";


for (   ; row > 0 ; row-- , eta-- )
{


	et = eta ;


   for(   ; et > 0 ; et--)
   {
    cout<<"."   ;
   }


    cout<<i;


   cout<<"\n";

}

getch();
}

AM I ELIGIBLE FOR ANY HELP NOW ??:confused: :icon_confused:

You need two for-loops.
First one (outer) should count rows, while inner one should (depending of the row it's in) count columns

can you give an example for counting columns ... i did the rows part ... it works .. now how do i count the colums .. because it has to look like a nice triangle ( or pyramid) so i had to add the dots before the numbers .. and the dots are causing trouble for counting rows ..

In the same way you count down the dots, count up in numbers.

Take a look at your middle snippet in post #6. In each row there is a series of spaces followed by a series of digits. There is a relationship to the number of spaces and the number of digits and there is a relationship to the type of digits used and the row number. Use a pencil and paper to determine those relationships. Then put that into code. I think you could use 3 loops. One to control the row. Then two inner loops, one to control the number of spaces (or dots) and a second one done sequentially to the first to control the digits.

Separate printout to the screen in:
dots before numbers and number.
So, first, if you are in row 0 (first one) the dots should be invert from that (like some_value - nr_of_row), so if you go down the dots should decrease (some_value you have to figure out yourself).
And after dots just print numbers with some_other_value space after them

the problematic part is the series of numbers ... i cant add string to integers so i am having difficulty making a string of numbers like 1 2 3 4 5 ... i can only go upto 1 ...
the dots were easy coz they wer onli dots.. the number series keeps increasing which is making it difficult for me ....

//start printing numbers
for (i = starting_num; i <= ending_num; i++){
     cout<<i;
     cout<<"   " //this prints separation between two numbers
}

THANKKKK YYOOOUUUUUU Sci@phy !!!!!

wid all u pplz help i did it ..
thank you thank you .. :)


here is my code .. i will make it beautiful later but this is the current working code for anyone else lookin to make such a program ....

n its gud to see people guiding me instead of giving the full solution ......
love u guys ... thank you ... :)

#include<iostream.h>
#include<conio.h>
#include<string>

void main()
{

int a, row, et, eta , p, i, s ;



cout<<"enter the number of rows \n" ;
cin>>a;

row = a;
et = row;
eta = et;
i = 1;



for (   ; row > 0 ; row-- , eta-- )
{


	et = eta ;


   for(   ; et > 0 ; et--)
   {
    cout<<"."   ;
   }


    for (p = 1, s = 1; p <= i; p++, s++)
	{

	cout<<s;

	cout<<" " ;
	}
   i = i + 1;


   cout<<"\n";

}

getch();
}

Ok, and you have just one slight error that programmers freak about. Instead of writing void main() , consider using int main() .

yea i noticed it on this website and i was gonna ask but i forgot ... i write viod main coz it saves me tym from writing return = o .. so what actualli is the difference ????? and whats the big deal if i write it one way or the other ??

Simplyfied, there is some "GODlike" program that starts your C++ code:

int a = main();
//do stuff with a

If you write "void main()" variable a will be garbage.

MOST of the time, it doesn't matter, but it's better not to go against GODlike program :)

More info on:
http://www.gidnetwork.com/b-66.html

>i write viod main coz it saves me tym from writing return = o
The return statement is optional in standard C++, so void main actually costs you an extra keystroke.

>so what actualli is the difference ?????
void main isn't guaranteed to work, int main is.

>whats the big deal if i write it one way or the other ??
If your compiler supports it and you never plan to use another compiler (including upgrades to your current compiler), then the only problem is people will think you're a bad programmer.

ohhh ..... thank you again for ur help ...

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.