Object
Write a program to input your name and print it diagonally on screen ten times.
Algorithm
- Declare integer variables row and col.
- Declare string name up to 10 characters.
- Read name.
- Repeat FOR row = 1 to 10 by 1
- Repeat FOR col = 1 to row by 1
- Give a space.
- Write name and advance a line.
- [End of inner FOR loop.]
- [End of outer FOR loop.]
- Repeat FOR col = 1 to row by 1
- Exit.
Flowchart

C++ Source Code
// program 47
#include <iostream>
using namespace std;
int main()
{
int row, col;
char name[10];
cout << "Enter your name: ";
cin >> name;
for (row = 1; row <= 10; row++)
{
for (col = 1; col <= row; col++)
cout << " ";
cout << name << "\n";
}
return 0;
}
C Source Code
/*program 47*/
#include<stdio.h>
int main()
{
int row, col;
char name[10];
printf("Enter your name: ");
scanf("%s", &name);
for(row=1; row<=10; row++)
{
for(col=1; col<=row; col++)
printf(" ");
printf("%s\n", name);
}
return 0;
}
Output
Enter your name: shahzad
shahzad
shahzad
shahzad
shahzad
shahzad
shahzad
shahzad
shahzad
shahzad
shahzad
