4자리 숫자 복권번호를 출력하는 프로그램을 작성하시오. 복권번호의 최소값은 1000이고 최대값은 9999입니다.
프로그램을 실행하고 임의의 키를 누르면 임의의 4자리 복권번호가 출력되도록 작성하시오.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main(void)
{
printf("복권추첨을 시작합니다.\n");
printf("준비되었으면 아무키나 누르세요.\n");
printf("아무숫자나 입력하고 Enter>>");
int a;
scanf("%d", &a);
printf("천백십일\n");
printf("%d%d%d%d\n", rand()%9+1, rand()%10, rand()%10, rand()%10);
printf("당첨번호를 확인하세요.\n");
return 0;
}
// 실행 결과
프로그램을 실행하고 임의의 키를 누르면 임의의 4자리 복권번호가 출력되도록 작성하시오.
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main(void)
{
printf("복권추첨을 시작합니다.\n");
printf("준비되었으면 아무키나 누르세요.\n");
printf("아무숫자나 입력하고 Enter>>");
int a;
scanf("%d", &a);
printf("천백십일\n");
printf("%d%d%d%d\n", rand()%9+1, rand()%10, rand()%10, rand()%10);
printf("당첨번호를 확인하세요.\n");
return 0;
}
// 실행 결과
'공부 > c언어' 카테고리의 다른 글
[c언어] for문을 이용한 배열 요소의 출력 (0) | 2011.05.31 |
---|---|
[c언어](연습문제) 생년월일을 입력하면 만 나이를 계산 (3) | 2011.05.30 |
[c언어](연습문제) 구구단 문제를 함수 rand()를 이용하여 랜덤으로 출력 (0) | 2011.05.30 |
[c언어] 0부터 1사이의 실수 난수를 출력(rand) (0) | 2011.05.25 |
[c언어] 로또 당첨번호 생성. 1부터 45사이의 정수 난수를 출력(rand, srand) (3) | 2011.05.25 |