编程学习网为您整理以下代码实例,主要实现:生成随机数,希望可以帮到各位朋友。
#include <stdio.h>
#include <stdlib.h>
int main()
{
int iRandomNum = 0;
int iResponse = 0;
iRandomNum = (rand() % 10) + 1;
printf("\nGuess a number between 1 and 10: ");
scanf("%d", &iResponse);
if (iResponse == iRandomNum)
printf("\nYou guessed right\n");
else {
printf("\nSorry, you guessed wrong\n");
printf("The correct guess was %d\n", iRandomNum);
}
}
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!