How can I make these 2 programs in C ??

Status
Not open for further replies.

zeeshan_04

Broken In
Hi Guys,

I want 2 make 2 programs in "C" which displays numbers as shown below.

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

-------------------------------------------------

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

--------------------------------------------------

How can I make these 2 programs in C ??

Please help guys. Thanks in advance.
 

NikhilVerma

Padawan
DUDE!!

DUDE!!
It's so simple!
just include this in your main function...

FIRST ONE

Code:
// I am supposing that number of rows is n

int i,k;
for(i=1;i<=n;i++)
{
	for(k=1;k<=i;k++)
		cout<<k<<" ";
	cout<<endl;
}

SECOND ONE

Code:
// I am supposing number of rows to be n again

int i,k,ctr=1;
for(i=1;i<=n;i++)
{
	for(k=1;k<=i;k++)
		cout<<ctr++<<" ";
	cout<<endl;
}


If anyone has any probs regarding programming in C++ ... Just ask me...
 

GNUrag

FooBar Guy
zeeshan_04 said:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Code:
#include <stdio.h>
 
int main() {
 
  for (int i =1; i<=10; i++) {
    for (int j=1; j<=i; j++)
      printf("%d ",j);
    printf("\n");
  }
}

zeeshan_04 said:
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

Code:
#include <stdio.h>
 
int main() {
  int k=1;
  for (int i =1; i<=10; i++) {
    for (int j=1; j<=i; j++)
      printf("%d ",k++);
    printf("\n");
  }
}

-------------
What purpose did this solve ?
 

NikhilVerma

Padawan
go4inet said:
cool... if i need help... i will post

need help in Data Structures with C++ ! Anyone good on that ?


Yep...
What do you want to know about? Classes or structures...


diab0lic666 said:
Why you ppl make others to do your home work???

Coz It's the only place they will get help.
There's noting wrong when you ask someone to do your homework..
Yeah.. If you repeatedly ask for it then it's wrong...
 

slugger

Banned
help needed in C

I am using Turbo C++ compiler for practicing C programming. Everytime I try to run a program, I get a message saying
'Unable to open include file STDIO.H'
When I ran a search for the file I found it in the same folder where the program is installed.
Actually the problem extends to all header filez as I get the same message everytime followed by the header file name.
BTW I'm installing Borland C++ 5.5 today. will tell u if it solves the problem. But I still want to know why am goetting the message in TC++
Plz help
 

puja399

In the zone
NikhilVerma said:
....
There's noting wrong when you ask someone to do your homework..
Yeah.. If you repeatedly ask for it then it's wrong...

No, it's all wrong. You should not do other's homeworks. It will hamper learning. If someone has trouble in understanding a programming concept, there is no trouble in helping, but doing other's homework will retard the student. So, I suggest that we stop doing other's homeworks.
 

aadipa

Padawan
puja399 said:
NikhilVerma said:
....
There's noting wrong when you ask someone to do your homework..
Yeah.. If you repeatedly ask for it then it's wrong...

No, it's all wrong. You should not do other's homeworks. It will hamper learning. If someone has trouble in understanding a programming concept, there is no trouble in helping, but doing other's homework will retard the student. So, I suggest that we stop doing other's homeworks.

Doing some1's homework is no no for me. First one should try, if stuck some where, post the original code so that we can correct it, or atleast give a hint to continue.
 

kalpik

In Pursuit of "Happyness"
^^ exactly... Post your own code before asking for suggestions...

@slugger: Check if your paths are correct in options->directories.
 

a_to_z123

asia://india/ka/bangalore
Re: help needed in C

slugger said:
I am using Turbo C++ compiler for practicing C programming. Everytime I try to run a program, I get a message saying
'Unable to open include file STDIO.H'
When I ran a search for the file I found it in the same folder where the program is installed.

Just go to the 'Options-->Directories' Menu and set the paths where you've your TC copied to.
e.g.
For 'Include Directories' ------ C:\TC\INCLUDE\
For 'Library Directories' ------ C:\TC\LIB\
etc. etc.
'Output Directory' is the one where you want your EXE files to be created.
And I don't know what are the 'Source Directories' :)
Anyway this much will solve your problem...
 
Status
Not open for further replies.
Top Bottom