[[연습 1]]
#include <iostream>
using namespace std;
int main()
{
int stNum;
cout << "학생수 입력 : ";
cin >> stNum;
double *height;
height = new double[stNum];
double sum = 0;
for(int i=0; i < stNum; i++)
{
cout << endl << i+1 << "번째 학생의 키 : ";
cin >> height[i];
sum += height[i];
}
cout << endl << endl;
cout << stNum << "명의 학생 신장평균은 " << sum / stNum << " 입니다.\n\n";
delete [] height;
return 0;
}
[[연습 2]]
#include <iostream>
#include <stdlib.h> //rand, srand
#include <time.h> // time
using namespace std;
void input(char *input, int cnt);
void output(char *output, int cnt);
int main()
{
cout << "대문자 개수 입력 : ";
int alphaCnt;
cin >> alphaCnt;
char *albet;
albet = new char[alphaCnt];
input(albet, alphaCnt);
output(albet, alphaCnt);
delete [] albet;
return 0;
}
void input(char *input, int cnt)
{
srand(time(NULL));
for(int i=0; i < cnt; i++)
{
input[i] = rand()%26 + 65;
}
}
void output(char *output, int cnt)
{
cout << "\n\n\t\t*** 랜덤 알파벳 출력 ***\n\n";
for(int i=0; i < cnt; i++)
{
cout << output[i] << "\t";
}
cout<< endl << endl;
}