|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
int c;
cout << "Zahl 1 eingeben"<< endl;
cin >> a;
cout << "Zahl 2 eingeben"<< endl;
cin >> b;
c=a*b
cout << c << endl;
cin.get(); cin.get();
return 0;
}
|
|
|
Quellcode |
1 2 |
#include <foo> ... |
)
Editiere mal deinen Beitrag und füge den Code in Code-Blocken


|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
srand(time(NULL));
int i;
for (i = 0; i < 10; i++)
{
printf("%i\n", rand() % 50);
}
}
|
Zitat
A typical way to generate pseudo-random numbers in a determined range using rand is to use the modulo of the returned value by the range span and add the initial value of the range:
( value % 100 ) is in the range 0 to 99
( value % 100 + 1 ) is in the range 1 to 100
( value % 30 + 1985 ) is in the range 1985 to 2014
|
|
Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <iostream>
#include <cstdlib>
#include <ctime>
int main ()
{
srand(time(NULL));
int i;
for (i = 0; i < 10; i++)
{
std::cout << rand() % 50 << std::endl;
}
}
|
Burning Board, entwickelt von WoltLab GmbH.
UbuntuFreunde von Easyy-S und basslord seit 06.12.06
Ubuntufreunde.de runs on ubuntu 10.04





