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.

simple C assignment..

Status
Not open for further replies.

dck

Junior Member level 1
Joined
Aug 6, 2008
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,411
how do we program in C to produce an output of

BBBBBBBBB
BBBBBBB
BBBBB
BBB
B



using nested loops..
thnx..
 

I don't know why you would need nested loops, one loop will do:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int main(int argc, char *argv[])
{
    char c[] = "BBBBBBBBB", i;
    
    for(i = strlen(c); i > 0; i--)
    {
        printf("\n%s", c);
        c[i - 1] = 0;
            
    } 
     getch();
  
  
  return 0;
}

written with DevC++

If you need nested loops because it's a homework assignment, then you need to be specific about what is allowed and what is not allowed. A specific set of conditions might make it necessary to write a nested loop, but I an not going to waste my time trying to figure them out.
 

i only learned to use stdio.h library..
the question specifies on using nested (for) loops..
 

Here you go
Code:
#include <stdio.h>

#define LENGTH		9
#define STEP		2
#define CHARACTER	'B'

void main(void)
{
	int i,j;
	for(i=LENGTH; i>0; i-=STEP)
	{
		for(j=0; j<i; j++)
		{
			printf("%c",CHARACTER);
		}
		printf("\n");
	}
}
 

    dck

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top