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
my name's Aya amro
SOLUTION:
The following code will print first letter of your first and last name beside each other:
#include <iostream>
using namespace std;
int main()
{
int n; // variable declaration
cout<<"Enter no of lines (min 4): ";
cin>>n; // Get user input for number of lines
for (int i = 0; i < n; i++) {
int letter=0;
// In your case both letter are A, so reusing logic to print twice
while(letter<2){
// No of lines
for(int j=0;j<=n/2;j++){
// Condition for vertical, first and middle lines respectively
if ((j==0||j==n/2)&&i!=0||i==0&&j!=0&&j!=n/2||i==n/2){
cout<<"*";
}
else{
cout<<" ";
}
}
cout<<" "; // Adjust this for space between two letters
letter++;
}
cout<<endl;
}
return 0;
}
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.