不太难的编程
来源:百度知道 编辑:UC知道 时间:2024/06/04 05:27:16
产生0到99的随机整数,并统计小于50的数有多少
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
void main()
{int i,r,n=0;
srand((unsigned)time(NULL));
for(i=1;i<51;i++)
{r=rand()%100;
printf("%d ",r);
if(r<50)n++;
}
printf("\n小于50的有:%d个\n",n);
}
#include "iostream"
#include "stdlib.h"
#include "time.h"
using namespace std;
int main()
{
srand( (unsigned)time( NULL ) );
int a, num = 0;
for ( int i = 0; i < 100 ++i) {
a = rand()%100;
if ( a < 50 )
num ++;
}
cout << num << endl;
return 0;
}
产生99个0~99的随机整数,统计小于50的数有多少个:
//---------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{<