rand 질문!
Judicious
2023.04.01
rand 사용시 범위질문 요약 :a=rand()%98+1; //-요거의 범위를모르겠네요질문 내용 :
#include stdio.h
int main()
{
int a;
srand(time(NULL));
a=rand()%100+1;
printf(%d,a);
}
//요렇게 간단하게 프로그램을 짤떄 a=rand()%100; 이렇게쓰면 0~99잖아요 범위가a=rand()%100+1; 이렇게하면 범위가 1~99로 되나요? 아니면 0~101 이되나요?
-
튼튼
rand()%100; 0~99
rand()%100 + 0; 0~99
rand()%100 + 1; 1~100
rand()%100 + 2; 2~101
rand()%100 + 3; 3~102 -
오빤테앵겨
최소+1 최대+1 이렇게하면 되는군요!;아핫
-
가욋길
a=rand()%100+1;
이거하면
범위가 0~99에 1을 더하니
1~100 이되지요 ~ -
에드문드
#include stdio.h
#include time.h
#include stdlib.h
int main()
{
\tint com,user;
\tsrand(time(NULL));
\tcom=rand()%98+1;
\tscanf(\%d\