不知道你要什么语言 我用delphi写个
var total;
for i:=1 to 10 do
begin
randomize();
num[i-1]:=rand(10);
total:=total+num[i-1];
showmessage("第"+inttostr(i)+"个数为"+inttostr(num[i-1]));
end;
showmessage("总和为"+inttostr(total));
#include
#include
using namesapce std;
int main()
{
srand(time(NULL));
int num[10];
int sum = 0;
for (int i = 0; i < 10; i ++)
{
num[i] = rand()%10;//要是1~10就是rand()%10+1
cout << num[i] << "\t";
sum += num[i];
}
cout << endl << sum;
return 0;
}
用srand()定义区间,在用rand()%11,取得0-10的11个数
#include
#include
#include
void main()
{
int i,num[10],sum=0;
time_t t;
srand((unsigned) time(&t));
for(i=0; i<10; i++)
{
num[i]= rand()%11;
sum+=rand()%11;
printf("%d ",num[i]);
}
printf("\n%d\n",sum);
system("PAUSE");
}