question

C

clasicallyivycious

Hi, all
Can anyone plz. help me out with this problem
Print : A
B A
A B A
B A B A
A B A B A

with the help of "for loop"
 
R

Richard Bos

Can anyone plz. help me out with this problem
Print : A
B A
A B A
B A B A
A B A B A

with the help of "for loop"

Yes. Undoubtedly someone can plz. help you out with that problem. I
suggest you start with your classmates, and if they don't know the
solution either, blag it off a sophomore. If all else fails and you're
really desperate, perhaps you could ask your teacher. Only after you've
done that, _and_ have at least some code to show for it, should you come
back here and ask for help, _not_ for a hand-out.

Richard
 
D

David Resnick

Hi, all
Can anyone plz. help me out with this problem
Print : A
B A
A B A
B A B A
A B A B A

with the help of "for loop"

int i;

for (i=0; i < 1; i++) {
printf("A\nB A\nA B A\nB A B A\nA B A B A\n");
}

OK, perhaps that isn't so helpful. Why don't you give it
a try, and see what you come up with. This is a trivial
problem, you'd learn lots more by doing your own
homework. Post what you come up with if you still
need help, if you make a good try people will assist
you.

-David
 
C

clasicallyivycious

David said:
int i;

for (i=0; i < 1; i++) {
printf("A\nB A\nA B A\nB A B A\nA B A B A\n");
}

OK, perhaps that isn't so helpful. Why don't you give it
a try, and see what you come up with. This is a trivial
problem, you'd learn lots more by doing your own
homework. Post what you come up with if you still
need help, if you make a good try people will assist
you.

The output is going to be:
A
B A
A B A
B A B A
A B A B A i wanted to be in reverse fashion, that's okay , but
i wanted to use something like: (i = 5; i <= 1; i--);
 
K

Keith Thompson

Can anyone plz. help me out with this problem
Print : A
B A
A B A
B A B A
A B A B A

with the help of "for loop"

If we really wanted to punish you, the best way to do it would be to
give you the code to solve the problem. You could turn it in, get
credit for it, and learn nothing.

You should have local resources that can help you with this. Talk to
your instructor, to a teaching assistant, to fellow students. Try
writing the program yourself. Learn.
 
O

OtavioCC

#include <stdio.h>
#include <math.h>

#define UP 1
#define DOWN 0

void myPrintf(int in_length, int in_order)
{
int cont, cont2;
char str[2] = "ab";

if (in_order == UP) {
for (cont = 1; cont < in_length; cont++) {
for (cont2 = 0; cont2 < cont; cont2++) {
if((cont2 % 2) == 0)
printf("%c", str[0]);
else
printf("%c", str[1]);
}
printf("\n");
}
} else if (in_order == DOWN) {
for (cont = in_length; cont > 0; cont--) {
for (cont2 = 0; cont2 < cont; cont2++) {
if((cont2 % 2) == 0)
printf("%c", str[0]);
else
printf("%c", str[1]);
}
printf("\n");
}
}
}

int main(int ac, char**av)
{
myPrintf(5, UP);

myPrintf(5, DOWN);
}
 
C

Christopher Benson-Manica

Keith Thompson said:
If we really wanted to punish you, the best way to do it would be to
give you the code to solve the problem. You could turn it in, get
credit for it, and learn nothing.

That would be an undue hardship on ourselves as well, however, as then
any of us might have the misfortune of working for the successful
cheater. Pointy-haired bosses are made, not born :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,933
Members
47,472
Latest member
blackwatermelon

Latest Threads

Top