用c语言编写:随机产生指定了长度的字一串字符。如指定10.计算机随机产生10个。帮帮。要运行成功啊

如题所述

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

void proChar(int l){

  srand(time(0));

  int i,asscii=0;

  for(i=0;i<l;i++){

   asscii =rand()%62;

   if(asscii<=9){

    asscii+=48;

   }else if(asscii>9&&asscii<=35){

    asscii+=87;

   }else if(asscii>35){

    asscii+=29;

   }

  printf("%c",asscii);

  asscii=0;

  }

  printf("\n");

}

void main(){

 int length;

 printf("输入字符码长度:");

 scanf("%d",&length);

 proChar(length);

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-11-13
#include<iostream.h>
#include<stdlib.h>
#include<time.h>

void main()
{
srand()(time(0));
int i,j,a[10];
for(i=0;i<10;i++)
a[i]=rand()()%90+10;
for(i=0;i<9;i++)
for(j=i+1;j<10;j++)
if (a[i]>a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
for(i=0;i<10;i++)
cout<<a[i]<<ends;
cout<<endl;
}追问

不成功啊

第2个回答  2013-11-13
用产生伪随机数n指定生成的字符数量,然后在一个循环结构里继续用指定范围的伪随机数打印出ASCII码。
大家正在搜