728x90
1๋ฒ
#include<iostream>
double aver(double x, double y);
int main()
{
using namespace std;
double x, y,z;
for(;;)
{
cout << "๋ ์ ์
๋ ฅ: ";
cin >> x >> y;
if (x == 0 || y == 0)
break;
z = aver(x, y);
cout << "์กฐํํ๊ท = " << z << endl;
}
return 0;
}
double aver(double x, double y)
{
return 2.0 * x * y / (x + y);
}
2๋ฒ
#include<iostream>
using namespace std;
int input(double score[], int n);
void output(const double score[], int n,double aver);
double aver_cum(const double score[], int n);
int main()
{
cout << "๊ณจํ ์ค์ฝ์ด ์
๋ ฅ (์ซ์๋ฅผ ์ ์ธํ ๋ฌธ์ ์
๋ ฅ์ ์ข
๋ฃ)\n";
double score[10],aver;
int n;
n=input(score, 10);
aver = aver_cum(score, n);
output(score, n, aver);
return 0;
}
int input(double score[], int n)
{
for (int i = 0; i < 10; i++)
{
cout << i + 1 << "๋ฒ์งธ: ";
if (!(cin >> score[i]))
{
n = i;
break;
}
}
return n;
}
double aver_cum(const double score[], int n)
{
double sum=0.0;
for (int i = 0; i < n; i++)
sum += score[i];
return sum / n;
}
void output(const double score[], int n, double aver)
{
for (int i = 0; i < n; i++)
cout << i + 1 << "๋ฒ: " << score[i] << " ";
cout << "\nํ๊ท ์ค์ฝ์ด : " << aver;
}
3๋ฒ
#include<iostream>
using namespace std;
struct box
{
char maker[40];
float height;
float width;
float length;
float volume;
};
void output(struct box);
void set_vol(struct box *);
int main()
{
struct box a = {
"abc",10,20,3,600
};
output(a);
struct box b;
cout << "maker: "; cin >> b.maker;
cout << "height: "; cin >> b.height;
cout << "width: "; cin >> b.width;
cout << "length: "; cin >> b.length;
set_vol(&b);
output(b);
}
4๋ฒ
#include<iostream>
long double probability(unsigned numbers, unsigned picks,unsigned mega);
int main()
{
using namespace std;
double total, choices, mega;
cout << "์ ์ฒด ์์ ๊ฐ์์ ๋ฝ์ ์์ ๊ฐ์๋ฅผ ์
๋ ฅํ์ญ์์ค:\n";
while ((cin >> total >> choices) && choices <= total)
{
cout << "๋ ๋ฒ์งธ ๋ฒ์๋ฅผ ์
๋ ฅํ์ญ์์ค:\n";
cin >> mega;
cout << "๋น์ ์ด ์ด๊ธธ ํ๋ฅ ์ ";
cout << probability(total, choices, mega);
cout << "๋ฒ ์ค์์ ํ ๋ฒ ์
๋๋ค.\n";
cout << "๋ค์ ๋ ์๋ฅผ ์
๋ ฅํ์ญ์์ค. (๋๋ด๋ ค๋ฉด q๋ฅผ ์
๋ ฅ): ";
}
cout << "ํ๋ก๊ทธ๋จ ์ข
๋ฃ.\n";
return 0;
}
5๋ฒ
#include<iostream>
int fact(int n);
int main()
{
for (;;)
{
std::cout << "๊ณ์น ์
๋ ฅ: ";
int n;
if (!(std::cin >> n))
break;
std::cout<<n<<"! = "<<fact(n)<<std::endl;
}
return 0;
}
int fact(int n)
{
if (n > 0)
return n * fact(n - 1);
else
return 1;
}
long double probability(unsigned numbers, unsigned picks, unsigned mega)
{
long double result = 1.0;
long double n;
unsigned p;
for (n = numbers, p = picks; p > 0; n--, p--)
result = result * n / p;
return result * mega;
}
void output(struct box a)
{
cout << a.maker << " " << a.height << " " << a.width
<< " " << a.length << " " << a.volume << endl;
}
void set_vol(struct box* b)
{
b->volume = b->height * b->width * b->length;
}
6๋ฒ
#include<iostream>
int Fill_array(double ar[], int n);
void Show_array(const double ar[], int n);
void Reverse_array(double ar[], int n);
using namespace std;
int main()
{
double ar[10];
int n = Fill_array(ar, 5);
Show_array(ar, n);
cout << "REVERSE" << endl;
Reverse_array(ar + 1, n - 2);
Show_array(ar, n);
}
int Fill_array(double ar[], int n)
{
int i = 0;
for (; i < n; i++)
{
cout << i + 1 << "๋ฒ์งธ double ๊ฐ : ";
if (!(cin >> ar[i]))
break;
}
return i;
}
void Show_array(const double ar[], int n)
{
for (int i = 0; i < n; i++)
cout << i + 1 << " : " << ar[i] << endl;
}
void Reverse_array(double ar[], int n)
{
for (int i = 0; i < n / 2; i++)
{
int temp;
temp = ar[i];
ar[i] = ar[n - i - 1];
ar[n - i - 1] = temp;
}
}
728x90