一个有关随机函数rand()的小程序_C/C++语言_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

一个有关随机函数rand()的小程序

作者:黑客防线网安C/C++教程基地 来源:黑客防线网安C/C++教程基地 浏览次数:0

本篇关键词:程序函数随机有关
黑客防线网安网讯:    #include<iostream>  #include <time.h>  #include <fstream>  #include <windows.h>  using namespace std;  unsigned t[300],temp;  void creat_rand() //产生随机数的函...
    #include<iostream>
  #include <time.h>
  #include <fstream>
  #include <windows.h>
  using namespace std;
  unsigned t[300],temp;
  void creat_rand() //产生随机数的函数
  {
  long i=1;
  cout<<"为您产生的随机数如下:"<<endl;
  srand(time(0)); //用此函数设定种子值使每次产生的随机数不一样
  for(i=1;i<21;)
  {
  temp=(rand()%10000+1000);
  if(temp>999 && temp<=9999)
  {
  t[i]=temp;
  cout<<"第"<<i<<"个"<<t[i]<<" ";
  if(i%5==0)
  cout<<endl;
  i++;
  }
  }
  }
  void search_number(unsigned t[],int n)//查找函数
  {
  cout<<endl;
  DeleteFile("randnumber.txt");
  system("pause");
  cout<<"后两位数字相等的随机数:"<<endl;
  ofstream output("randnumber.txt",ios::out);
  int cand1,cand2;
  for(int i=1;i<n;i++)
  {
  cand1=t[i]%10;
  cand2=t[i]%100/10;
  if(cand1==cand2)
  {
  cout<<t[i]<<" ";
  output<<t[i]<<" ";
  }
  }
  output.close();
  }
  void main()//主函数
  {
  creat_rand();
  search_number(t,20);
  }
    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-15083-1.html
网站维护教程更新时间:2012-04-04 22:49:46  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer