● rand()함수에 대해 알아봅시다
#include <cstdio>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
void gotoxy(int x, int y)
{
COORD NewPos={x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),NewPos);
}
int main()
{
int a, b, i;
srand(time(NULL));
a = rand() % 10;
printf("rand() % 10 = %d\n", a);
a = rand() % 100 + 1;
printf("rand() % 100 = %d\n", a);
a = rand() % 90 + 10;
printf("rand() % 90 + 10 = %d\n", a);
for(i=0;i<10;i++)
{
a = rand() % 10 + 1;
b = rand() % 10 + 1;
printf("%d + %d = %d\n", a, b, a+b);
}
return 0;
}
[ c언어 7-1 문제 ] gotoxy함수를 이용해서 화면에 0부터9까지 수를 출력하는데 위치를 rand()를 이용해서 출력해봅시다
'C언어로 게임만들기' 카테고리의 다른 글
9. C언어로 게임만들기 - _kbhit() - 키가 눌렀는지 검사하는 함수 (0) | 2020.03.30 |
---|---|
8. C언어로 게임만들기 - time() 함수 (0) | 2020.03.29 |
6. C언어로 게임만들기 - 글자색변경하기 (0) | 2020.03.28 |
5. C언어로 게임만들기 - gotoxy함수 - 달팽이 모양 출력하기 (0) | 2020.03.27 |
4. C언어로 게임만들기 - gotoxy함수 - 사각형출력하기 (0) | 2020.03.27 |