Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

req: C programming help

Status
Not open for further replies.

isuranja

Member level 5
Member level 5
Joined
Nov 12, 2004
Messages
90
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Sri Lanka
Activity points
712
I want get following result using nested loop in C.

*
**
***
****
*****
******
*******
********
*********
**********

This is my code but it's not working please do advice.

#include <stdio.h>
main()
{
int i;
int j;

i = 1;
j = 1;

while( i <= 10) {
printf("*");
i = i + 1;
while( j <= 10) {
printf("*/n");
j = j + 1;
}
}
}

Please help on this.

Thanks,
Isuranja
 

Maybe this can help you??

Code:
#include <stdio.h>

void main(void) 
{ 
	int i; 
	int j=1; 

	while(j <= 10) 
	{ 
		i=1;
		
		while(i <= j)
		{
			printf("*");
			i++;
		}
		
		printf("\n"); 
		j++;
	}
}
 

hi,
I am pointing you the basic problem with code and if u still want any help please write me...
#include <stdio.h>
main()
{
int i;
int j;

i = 1;
j = 1;

while( i <= 10) {
printf("*");
i = i + 1;
while( j <= 10) {
printf("*/n");#here you are using "/n"inspite of "\n" and u have given additional * too so i feel there is no need of loop for "\n" too...As after * printing u required only one \n...so better u print whatever * u wanna in loop and after that u try to go for only one \n.
j = j + 1;
}
}
}
 

here is more compact code
""
#include<stdio.h>
main()
{
int i, j;
for(i=1; i<11 ; i++)
{
for(j=0;j<i;j++)printf("*");
printf("\n");
}
}

""
 

#include <stdio.h>
void main(void)
{
int a;
int b=1;
while(b <= 10)
{
a=1;
while(a <= b)
{
printf("*");
a++;
}
printf("\n");
b++;
}
}
 

    isuranja

    Points: 2
    Helpful Answer Positive Rating
hi this is your code after adjusment
Code:
#include <stdio.h>
#include <conio.H>
main()
{
int i;
int j;

i = 1;
j = 1;
printf("*\n\r");

while( i <= 10)
	{
	j=1;
	printf("*");
	i = i + 1;
	while( j < i)
		{
		if(j==(i-1)) printf("*\n\r");
		else printf("*");
		j = j + 1;
		}
	}
getch();
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top