티스토리 뷰
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
typedef struct rect{
int x, y;
int width, height;
}RECT;
int main(){
RECT *arr[100] = {NULL};
int count = 0;
int i;
while(1){
char choice;
printf("직사각형을 만드시겠습니까 (Y/N): ");
scanf("%c", &choice);
fflush(stdin);
if(toupper(choice) == 'N'){
break;
}
arr[count] = malloc(sizeof(RECT));
arr[count] ->x = rand()%400;
arr[count] ->y = rand()%400;
arr[count] ->width = rand()%100;
arr[count] ->height = rand()%100;
count++;
}
printf("%d개의 직사각형이 만들어졌습니다.\n", count);
for(i = 0; i < count; i++){
printf("%d번째 직사각형 : (%3d,%3d) w = %3d, h=%3d\n",
i+1, arr[i]->x, arr[i]->y, arr[i]->width, arr[i]->height);
}
for(i = 0 ; i < count; i++){
free(arr[i]);
arr[i] = NULL;
}
return 0;
}
티스토리 방명록
- Total
- Today
- Yesterday
Contact: j0n9m1n1@gmail.com