C++ 1일차
#include <iostream.h>
void main()
{
int a,b;
int sum;
cout<<"숫자 2개를 입력하세요.\n";
cin>>a>>b;
if (a<b)
{
for(sum=0,a+=1;a<b;a++)
{
sum+=a;
}
}
else if (a>b)
{
for(sum=0,b+=1;a>b;b++)
{
sum+=b;
}
}
else
{
sum=0;
}
cout<<"두 값 사이의 합은 "<<sum<<"입니다.\n";
}
*/
/*
#include <iostream.h>
void main()
{
int num;
cout<<"몇단을 출력할까요?\n";
cin>>num;
for(int i=1;i<=9;i++)
{
cout<<num<<" * "<<i<<" = "<<num*i<<"\n";
}
}
*/
//동적할당은 c++로
//int *p=(int *)malloc(4);
//int *p=new int;
//free(p);
//delete p;
//int *p=(int *)malloc(4*sizeof(int));
//int *p=new int[4];
#include <iostream.h>
void change(int *p,int num)
{
num--;
int *Temp=new int[num];
for(int i=0;i<=num;i++)
{
Temp[i]=p[num-i];
}
for(int j=0;j<=num;j++)
{
p[j]=Temp[j];
}
}
void main()
{
cout<<"생성할 숫자의 갯수는?";
int num;
cin>>num;
int *p=new int[num];
for(int i=0;i<num;i++)
{
p[i]=i+1;
}
change(p,num);
for(int j=0;j<num;j++)
{
cout<<p[j]<<"\n";
}
delete p;
}