coding????

16 replies [Last post]
ash_rock
Offline
Last seen: 9 years 32 weeks ago
Joined: 2010-01-08
bOt Points: 114

 i need the code in c++ for this output;

*

**

***

****

*****

shashwat
Offline
Last seen: 1 year 8 weeks ago
Joined: 2009-02-18
bOt Points: 1160
Program to print star pattern

Hi ash_rock,

Check out your program below-

#include<stdio.h>

#include<iostream.h>

void print(int n,char c)

{

if(n>1)

print(n-1,c);

cout<<c;

}


 


int main()

{

int number=10;

char c='*';

for(int i=1;i<=number;i++)

{

print(i,c);

cout<<endl;

}

Founder and Admin

ash_rock
Offline
Last seen: 9 years 32 weeks ago
Joined: 2010-01-08
bOt Points: 114
its not wrkin on dos

its not wrkin on dos

ash_rock
Offline
Last seen: 9 years 32 weeks ago
Joined: 2010-01-08
bOt Points: 114
der is no error  but program

der is no error  but program is not showin output

ash_rock
Offline
Last seen: 9 years 32 weeks ago
Joined: 2010-01-08
bOt Points: 114
wat to do nw?

wat to do nw?

shashwat
Offline
Last seen: 1 year 8 weeks ago
Joined: 2009-02-18
bOt Points: 1160
Hi ash_rock, You need to

Hi ash_rock,

You need to include clrscr() and getch() functions  for dos. Program is working fine check out the code below -

 

#include<stdio.h>

#include<iostream.h>

#include<conio.h>
void print(int n,char c)

{

if(n>1)

print(n-1,c);

cout<<c;

}


int main()

{

clrscr();
int number=10;

char c='*';

for(int i=1;i<=number;i++)

{

print(i,c);

cout<<endl;

}
getch();
return 0;

}

 

 

Also the above program uses recursive function. Here is a much simpler version of the same. Try out this too.

#include<stdio.h>

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

int main()

{

int number=10;
clrscr();

for(int i=1;i<=number;i++)

{

for(int j=1;j<i;j++)

cout<<"*";

cout<<endl;

}

getch();
return 0;

Founder and Admin

ash_rock
Offline
Last seen: 9 years 32 weeks ago
Joined: 2010-01-08
bOt Points: 114
yeah i had put getch b4 also

yeah i had put getch b4 also but after return 0;

well nw its wrkin still der is one minute error in out put but i had remend it,,,,,,

its cout<<"\n";

not cout<<end1;

well thnks shashwant ...............

but i need ur help to understand dis code ok

Note:- This post has been edited by ash_rock at Fri, 2010-01-08 13:46.

ash_rock
Offline
Last seen: 9 years 32 weeks ago
Joined: 2010-01-08
bOt Points: 114
 i will post my codin n see

 i will post my codin

n see y its not wrkin
ur codin is lil typical
shashwat
Offline
Last seen: 1 year 8 weeks ago
Joined: 2009-02-18
bOt Points: 1160
Hi ash_rock, Both the lines

Hi ash_rock,

Both the lines will give the same output -

cout<<"\n"; 

OR

cout<<endl;

Here \n stands for newline and endl stands for endline. Did you try out the simpler version?

Founder and Admin

ash_rock
Offline
Last seen: 9 years 32 weeks ago
Joined: 2010-01-08
bOt Points: 114
 Smiley

 

ash_rock
Offline
Last seen: 9 years 32 weeks ago
Joined: 2010-01-08
bOt Points: 114
pls explain me this codin

pls explain me this codin ;

 

void print(int n,char c)

{

if(n>1)

print(n-1,c);

cout<<c;

}

 

well i had written in the easy way the same like u but it was not runnin properly :(

shashwat
Offline
Last seen: 1 year 8 weeks ago
Joined: 2009-02-18
bOt Points: 1160
Hi ash_rock, This is a

Hi ash_rock,

This is a recursive program. Do you know what is recursive programming? If not then first try out the simpler program which i have posted above. 

Founder and Admin

ash_rock
Offline
Last seen: 9 years 32 weeks ago
Joined: 2010-01-08
bOt Points: 114
my codin is

my codin is ;

 

#include<stdio.h>

#include<iostream.h>

#include<conio.h>

int main()

{

clrscr();

char a='*'

for(1=1;i<=5;i++)

{

for(j=1;j<i;j++)

cout<<a;

}

cout<<"\n";

getch();

return 0;

}

ash_rock
Offline
Last seen: 9 years 32 weeks ago
Joined: 2010-01-08
bOt Points: 114
recursive programming no i

recursive programming no i dnt knw ?

shashwat
Offline
Last seen: 1 year 8 weeks ago
Joined: 2009-02-18
bOt Points: 1160
Hi ash_rock, You have not

Hi ash_rock,

You have not declared integers i and j.

Also you have a missing semicolon ; after this line char a="*"

You need to include this line cout<<"\n" inside curly brackets i.e. inside for loop.

Also the second for loop condition should be j<=i.

So you final code will be -

#include<stdio.h>

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

int main()

{

int i,j;

char a='*';

clrscr();
for(i=1;i<=5;i++)

{

for(j=1;j<=i;j++)

cout<<a;

cout<<"\n";

}
getch();

return 0;

Founder and Admin

ash_rock
Offline
Last seen: 9 years 32 weeks ago
Joined: 2010-01-08
bOt Points: 114
yeah u r ryt

yeah u r ryt ............................

thnks alot :)

shashwat
Offline
Last seen: 1 year 8 weeks ago
Joined: 2009-02-18
bOt Points: 1160
You are welcome.  

You are welcome.  

Founder and Admin