M
M
marlaaa2022-04-20 19:46:08
C++ / C#
marlaaa, 2022-04-20 19:46:08

How to pad the end of each line with '*' character?

As a result of the task, if N, for example, enter 6, then it should come out:
A*****
AB****
ABC***
ABCD**
ABCDE*
ABCDEF

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
    setlocale(LC_ALL , "Russian");
    int N;
    cout << "Введите N";
    cin >> N;
    ofstream file("proga.txt");
    for (int i = 0; i < N; i++)
    {
        for (char j = 'A'; j <= 'A' + i; j++)
            file << j;
            file << '\n';
    }

    file.close();
    return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2022-04-20
@marlaaa

If you have idisplayed characters in a string, and there should be a total Nof characters, then it remains to display N-iasterisks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question