In: Computer Science
Write a C++ Program to print the first letter of your first and
last name using stars.
Note:
1) Using nested For Loop
2) The number of lines is given by user.
3) Using one Outer loop to print your letters.
4) Print the letters beside each other.
#include <iostream>
using namespace std;
int main()
{
//variable declaration
int n;
//array declaration
string firstName[10], lastName[10];
//get the number of lines
cout<<"Enter the number of lines: ";
cin>>n;
//get user input
for(int i=0; i<n; i++)
{
cout<<"Enter the first name and last name: ";
cin>>firstName[i];
cin>>lastName[i];
}
//display the list of the name using *
cout<<endl<<"The list of the name
is:"<<endl;
for(int i=0; i<n; i++)
{
cout<<"*";
for(int j=1; j<firstName[i].length(); j++)
{
cout<<firstName[i][j];
}
cout<<" *";
for(int j=1; j<lastName[i].length(); j++)
{
cout<<lastName[i][j];
}
cout<<endl;
}
return 0;
}
OUTPUT:
Enter the number of lines: 5
Enter the first name and last name: Matrix Dim
Enter the first name and last name: Aman Kapoor
Enter the first name and last name: Hi Hello
Enter the first name and last name: Ok Bye
Enter the first name and last name: Tam King
The list of the name is:
*atrix *im
*man *apoor
*i *ello
*k *ye
*am *ing