生成随机数

#include stdio.h #include stdlib.h int main(){int iRandomNum = 0;int iResponse = 0;iRandomNum = (rand() % 10) + 1;

编程学习网为您整理以下代码实例,主要实现:生成随机数,希望可以帮到各位朋友。

#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);
   }
}

本文标题为:生成随机数

基础教程推荐