Perfil de 芷涵Sweety timeFotosBlogListasMás ![]() | Ayuda |
|
20 noviembre my homework(since I forget to take my USB to class)
#include "stdafx.h"
#include <iostream> #include <ctime>
#include <cstdlib> using namespace std; //function char getRandomCharacter(char ch1,char ch2) { return static_cast<char>(ch1+rand()%(ch1-ch2+1));
} int main()
{ //display the uppercase srand(time(0));
for(int i=1;i<=10;i++) //for the ten row {for(int j=1;j<=10;j++)//for the ten charaters in one row cout<<getRandomCharacter('a','z'); cout<<endl; } //dispaly the single digit for(i=1;i<=10;i++) {for(int j=1;j<=10;j++)//for the ten charaters in one row cout<<getRandomCharacter('0','9'); cout<<endl; } return 0; } (the second)
#include "stdafx.h"
#include <iostream> #include <ctime> #include <cstdlib> #include <cmath> using namespace std; int main()
{ double sum=0; double x; srand(time(0)); for(int i=1;i<=10;i++) { x=fmod(rand(),1000.0); sum=sum+x; } double mean=sum/10; double sum1=0,sum2=0;
for(i=1;i<+10;i++) { x=fmod(rand(),1000.0); sum1=sum1+x*x; sum2=sum2+x; } double deviation=sqrt((sum1-sum2*sum2/10)/9); cout<<"Mean is "<<mean<<endl;
cout<<"Deviation is "<<deviation<<endl; return 0; } |
|
|