A
B B
C C C
D D D D
E E E E E
A
A B
A B C
A B C D
A B C D E
it would be nice if you could give me a bit of explanation too... :)
C++..plz help with program codes using 'for' loop to get the foll: outputs:?
//Hi... Here is the Code
//(1)
#include%26lt;iostream.h%26gt;
int main()
{
int r,d,c;
char a;
a='A';
d=a;
for(r=0;r%26lt;5;r++)
{
d=65+r;
a=d;
for(c=0;c%26lt;=r;c++)
{
cout%26lt;%26lt;a;
}
cout%26lt;%26lt;endl;
}
return 0;
}
//Here ASCII Code is used for printing the Characters.
//------------------------------------...
//Here is the Second one
//(2)
#include%26lt;iostream.h%26gt;
int main()
{
int r,c,d;
char a;
a='A';
d=a; //ASCII Code of 'A' is sent to int d.
for(r=1;r%26lt;=5;r++)
{
d=65; // ASCII code of A (65).
a=d;
for(c=1;c%26lt;=r;c++)
{
cout%26lt;%26lt;a;
d++; //increment in ASCII Code to print next character.
a=d;
}
cout%26lt;%26lt;endl;
}
return 0;
}
//Here ASCII Code is used for printing the Characters.
Reply:I cant give you the full code but but I can give you a hint. you have to use two for loops and ASCII values to print the patterns of Alphabets. ASCII value of A=65, B=66 .......... and so on
you can see my blog http://codesbyshariq.blogspot.com for more information
Reply:well even i struggle while doin these pattern problems....too bad i dont remember the code....but u will need one loop for the 5 rows....u can see tht the number of letters are equal to the number of row....i.e a is 1time and it is in 1st row...b is in 2nd row n it is 2 times....tht is the logic tht u hav to apply...
so u need a loop to change the row,one loop for printing the alphabets....this is the solution to the first pattern....similarly u can solve the second pattern...
Reply:int c=1;
for(int i=65;i%26lt;=65+27 /* this is the number of capital letters*/;i++)
{
for(int x=1;x%26lt;=c;x++)
{
printf("%c",i);
}
printf("\n");
c++;
}
//***** this would do the first series
//*** now the second one:
int c=1;
for(int i=65;i%26lt;=65+27 /* this is the number of capital letters*/;i++)
{
for(int x=0;x%26lt;=c;x++)
{
printf("%c",x+65);
}
printf("\n");
c++;
}
//******* END**********//
I did not have the chance to code it and probe it, but I think It works.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment