Program :Make Alphabet Triangle
In This Program I use Nested Loop To Make a Alphabet Triangle check out Program.
#include<iostream.h>
#include<conio.h>
int main()
{
for(int i=65; i<75; i++) //i=65 that in ASCII 65 = A
{ // and 75 is K but it will less than 75 so it print till J
for(int j=0; j<10-i+65; j++)
{ /* here i set j=0 and j < less than (10 - i) that i set to it decrease one by one so in this I add 65 in i so keep i zero at start and increase one by one */
cout << (char)i; // to convert int to char so i write (char) before write variable
}
cout << endl; // new line use every time it print one alphabets
}
getch();
}
OUTPUT
In This Program I use Nested Loop To Make a Alphabet Triangle check out Program.
#include<iostream.h>
#include<conio.h>
int main()
{
for(int i=65; i<75; i++) //i=65 that in ASCII 65 = A
{ // and 75 is K but it will less than 75 so it print till J
for(int j=0; j<10-i+65; j++)
{ /* here i set j=0 and j < less than (10 - i) that i set to it decrease one by one so in this I add 65 in i so keep i zero at start and increase one by one */
cout << (char)i; // to convert int to char so i write (char) before write variable
}
cout << endl; // new line use every time it print one alphabets
}
getch();
}
OUTPUT
what about this output?
ReplyDeleteA
AB
ABC
ABCD
for that try this
Delete#include
using namespace std;
int main()
{
int i;
char j;
for(i =65; i<=67; i++)
{ for(int j=65;j<=i; j++)
{
cout<<j;
}
cout <<endl;
}
return(0);
}
How about this output using nested loop
DeleteS
SA
SAM
SAMP
SAMPL
SAMPLE
SAMPL
SAMP
SAM
SA
S
W
WO
WOR
WORK
WOR
WO
W
#include<iostream>
Deleteusing namespace std;
/*
S
SA
SAM
SAMP
SAMPL
SAMPLE
SAMPL
SAM
SA
S
W
WO
WOR
WORK
WOR
WO
W
*/
void designFunction(char myString[],int size){
for(int i=0;i<size;i++){
for(int j=0;j<=i;j++){
cout<<myString[j];
}
cout<<endl;
}
for(int i=size-2;i>=0;i--){
for(int j=0;j<=i;j++){
cout<<myString[j];
}
cout<<endl;
}
}
int main(){
designFunction("SAMPLE",6);
designFunction("WORK",4);
return 0;
}
for that try this
ReplyDelete#include"iostream.h"
main()
{
for(int i =65; i<69; i++)
{
for(int j=0;j<i-65+1; j++)
{
cout << (char)(65+j);
}
cout <<endl;
}
}
a
ReplyDeleteb c
d e f
g h i j
#include"iostream.h"
Deletemain()
{
for(int i=65,k=0; i<69; i++)
{
for(int j=0;j<i-65+1; j++,k++)
{
cout << (char)(65+k);
}
cout <<endl;
}
}
E D C B A B C D E
ReplyDeleteD C B A B C D
C B A B C
B A B
A
#include<iostream>
ReplyDeleteusing namespace std;
/*
E D C B A B C D E
D C B A B C D
C B A B C
B A B
A
*/
int main()
{
int numofrows = 5;
for(int i=0;i<numofrows;i++){//5 rows
for(int j=65+numofrows-1-i;j>=65;j--)
cout << (char)j;
for(int k=66;k<66+numofrows-1-i;k++)
cout << (char)k;
cout <<endl;
}
return 0;
}
A
ReplyDeleteD C B
E F G H I
P O N M L K J
# # # # # # # # #
J K L M N O P
I H G F E
B C D
A
/*
DeleteA
D C B
E F G H I
P O N M L K J
# # # # # # # # #
J K L M N O P
I H G F E
B C D
A
*/
#include<iostream>
#include<stdlib.h>
using namespace std;
main()
{
int n=4,k=0,i=0;
for(i=0;i<n;i++)
{
int l=k;
if(i%2 == 0)
for(int j=65+k;j<65+l+((2*i)+1);j++,k++)
cout << (char)j;
else
for(int j=64+l+((2*i)+1);j>64+l;j--,k++)
cout << (char)j;
cout <<endl;
}
cout <<"#########\n";
for(i=n-1;i>=0;i--)
{
int l=k;
if(i%2 == 0)
for(int j=64+k;j>64+l-((2*i)+1);j--,k--)
cout << (char)j;
else
for(int j=65+l-((2*i)+1);j<=64+l;j++,k--)
cout << (char)j;
cout <<endl;
}
}
How about this output
DeleteS
SA
SAM
SAMP
SAMPL
SAMPLE
SAMPL
SAM
SA
S
W
WO
WOR
WORK
WOR
WO
W
This comment has been removed by the author.
Delete#include
ReplyDeletevoid main()
{
int i,x=0;
char j='A';
for(i =65; i<69; i++)
{ for(x=65;x<i+1; x++)
{
j=x;
cout<<j<<'\t';
}
cout<<'\n';
}
}
This gives output as
A
A B
A B C
A B C D
increase limit of i to get more.
Cheers :)
Sabash beta!!
DeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete#include
Deleteint main()
{
int x=0,y,z;
char c='a';
for(x=0;x<=5;x++)
{
for(z=x;z<=5;z++)
{
printf(" ");
}
for(y=x;y>=0;y--)
{
printf("%c ", c);
c++;
printf(" ");
}
printf("\n");
}
return 0;
out put
}
................a
...............b c
..............c d e
.............f g h i
............j k l m n
...........o p q r s t
This comment has been removed by the author.
ReplyDelete/*
ReplyDeleteA
A B A
A B C B A
A B C D C B A
A B C D E D C B A
*/
#include
using namespace std;
int main() {
const int _A = 65;
for(int i=0;i<5;i++){
for(int j=0;j=0;k--){
cout << (char)(_A+k)<<" ";
}
cout << endl;
}
return 0;
}
how to make
ReplyDeletea b c d e
a b c d
a b c
a b
a
#include "iostream"
Deleteusing namespace std;
int main() {
const int _A = 97;
for(int i=0;i<5;i++){
for(int j=0;j<5-i;j++){
cout << (char)(_A+j)<<" ";
}
cout << endl;
}
return 0;
}
output
a b c d e
a b c d
a b c
a b
a
A
ReplyDeleteA B
A B A
AB C BA
ABC D CBA
A very excellent blog post. I am thankful for your blog post. I have found a lot of approaches after visiting your post. how to learn braille for blind
ReplyDelete