Question 5.15

mail@pastecode.io avatar
unknown
c_cpp
a year ago
743 B
1
Indexable
Never
#include <iostream>
#include <string>

int main() {
  int usrInput;
  std::cout << "Please enter an integer: ";
  std::cin >> usrInput;
  char arr[usrInput];
  std::cout << "Pattern A" << std::endl;
  for (int i = 0; i < usrInput; i++) {
    arr[i] = '*';
    arr[i + 1] = '\0'; // Null-terminate the string
    std::cout << arr << std::endl;
  }
  std::cout << "Pattern B" << std::endl;
  for (int i = 0; i < usrInput; i++) {
    std::cout << &arr[i] << std::endl;
  }
  std::cout << "Pattern C" << std::endl;
  for (int i = 0; i < usrInput; i++) {
    std::cout << arr << std::endl;
    arr[i] = ' ';
  }
  std::cout << "Pattern D" << std::endl;
  for(int i = usrInput-1; i>=0;i--){
    arr[i] = '*';
    std::cout << arr << std::endl;
  }
}