c++随机函数,函数如下,譬如输入3,输出的五个数都是一样的,怎么改
#include<stdio.h>#include<stdlib.h>#include<time.h>voidcj(){inti,j;srand((unsigned)ti...
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void cj()
{ int i,j;
srand((unsigned)time(NULL));
i=rand()%3+1;
printf("%d",i);
}
main()
{ int n;
srand((unsigned)time(NULL));
printf("一等奖输入1\n二等奖输入2\n三等奖输入3\n");
scanf("%d",&n);
switch(n)
{ case 1: cj();break;
case 2: cj();cj();cj();break;
case 3: cj();cj();cj();cj();cj();break;
default: printf("Error\n");break;
}
} 展开
#include <stdlib.h>
#include <time.h>
void cj()
{ int i,j;
srand((unsigned)time(NULL));
i=rand()%3+1;
printf("%d",i);
}
main()
{ int n;
srand((unsigned)time(NULL));
printf("一等奖输入1\n二等奖输入2\n三等奖输入3\n");
scanf("%d",&n);
switch(n)
{ case 1: cj();break;
case 2: cj();cj();cj();break;
case 3: cj();cj();cj();cj();cj();break;
default: printf("Error\n");break;
}
} 展开
展开全部
//#include "stdafx.h"//In VC++6.0, with this line, please#include #include "math.h"using namespace std;int main(void){ double x,y; cout > x; y = x<0 ? 3*x*x-5/x : 0<=x && x<5 ? 1/(2+cos(x)) : sqrt(sin(x)+1); cout << "y(" << x << ") = " << y << endl; return 0;}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询