#include <iostream>
using namespace std;
int main(){
cout<<"please input num"
int width;
cin>>width;
cout<<"please input height"
int height;
cin>>height;
int area = width*height;
cout<<"Your area "<<area<<"\n";
}
์์ฝ๋๋ฅผ ํจ์๋ก ๋ง๋ ๊ฒ
#include<iostream>
//using std::endl;
using namespace std;//cout, endl, cin ๋ฑ..
int x = 10000;//์ ์ญ๋ณ์
int getArea(int width, int height)//์ ์ญ ํจ์
{
return width*height;
}
void line(); //ํจ์์ ์ํ์ด๋ผ๊ณ ํจ -> main๋ณด๋ค ์์ ์์ด์ผ ์คํ ๊ฐ๋ฅ.
int main()
{
int width, height;
line();
cout<<"๋๋น์ ๋์ด๋ฅผ ์ ๋ ฅํ์ธ์.";
cin>>width>>height;
cout<<"์ฌ๊ฐํ์ ๋ฉด์ ์?"<<getArea(width,height)<<endl;//returnํ ํจ์ ํธ์ถ๋ฒ.
line(); //void ํจ์ ํธ์ถ๋ฒ
}
void line()
{
for(int i=0;i<50;i++)
{
cout<<"-";
}
cout<<endl;
}
๊ฒฐ๊ณผ
#include<iostream>
#include<time.h>
#include<stdlib.h>
using namespace std;//cout, endl, cin ๋ฑ..
int main()
{
srand(time(NULL));
cout<<"์์์ ์ : " <<rand()%100+1<<endl;//1~100์ฌ์ด์ ์์์ ์
int x[10];
cout <<"๋ฐฐ์ด์ ํฌํค :" <<sizeof(x)/sizeof(x[0])<<endl;
}
๊ฒฐ๊ณผ
#include<iostream>
#include<time.h>
#include<stdlib.h>
using namespace std;//cout, endl, cin ๋ฑ..
void getSort(int arr[], int k);
int main()
{
srand(time(NULL));
int x[10];//๋ฐฐ์ด์ ์์์ ์๋ฅผ ๋ฃ๊ณ ์ถ๋ ฅํ ๊ทธ ํฉ, ํ๊ท , ์ต๋ ๊ฐ ๊ตฌํ๊ธฐ.
int z = sizeof(x)/sizeof(x[0]);
cout <<"๋ฐฐ์ด์ ํฌํค :" <<z<<endl;
int sum=0;
for(int i=0;i<10;i++){
x[i]=rand()%100+1;
cout<<x[i]<<" "<<endl;
sum += x[i];
}
cout<<"add : "<<sum<<", age : "<<sum/z;
int max=x[0];
for(int i =0;i<10;i++)
{
if(x[i]>max){
max=x[i];
//max++
}
cout<<", max : "<<max<<endl;
getSort(x,z);
}
}
void getSort(int arr[], int k)
{
int x,y,temp;
for(x=0;x<k-1;x++)
{
for(y=x+1; y<k; y++)
{
if(arr[x]>arr[y])
{
temp=arr[x];
arr[x]=arr[y];
arr[y]=temp;
}
}
}
for(x=0;x<10;x++){
cout<<arr[x]<<" ";
}
cout<<endl;
}