How to show a number pattern in C++ [closed]
How can I show the following pattern?
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
This should do the trick:
cout << "1 2 3 4 5" << "\n";
cout << " 1 2 3 4" << "\n";
cout << " 1 2 3" << "\n";
cout << " 1 2" << "\n";
cout << " 1" << endl;
printf("1 2 3 4 5\n 1 2 3 4\n 1 2 3\n 1 2\n 1\n");
That'll be four peanuts please.
#
include <iostream>
void pattern(const int N) {
for (int i=N;i>0;i--) {
for (int j=i;j
std::cout << " ";
for (int j=0;j
std::cout << j+1 << " ";
std::cout << std::endl;
}
}
int main(void){
pattern(5);
return 0;
}
精彩评论