//C++로 시작하는 객체지향 프로그래밍 p.277 예제 6.11
Q. 지정한 줄당 문자수만큼 ch1과 ch2사이의 문자를 출력한다. 'l'에서 'z'까지 한 줄당 10개의 문자를 출력하는 테스트 프로그램을 작성하여라.
#include <iostream>
using namespace std;
void printChars(char ch1, char ch2, int numberPerLine){
int x = 1 ;
for (int i = ch1; i <= ch2; i++, x++) {
cout << (char)i << " ";
if (x%numberPerLine ==0)
cout << " \n";
}
}
int main(){
char x, y;
int numberPerLine;
cout << "Enter a Start Character : ";
cin >> x;
cout << "Enter a End Character : ";
cin >> y;
cout << "Enter a number Per Line : ";
cin >> numberPerLine;
printChars(x, y, numberPerLine);
system("pause");
return 0;
}
댓글 없음:
댓글 쓰기