+ 1
why the output showing distinct numbers? little confused plz help?
why this code showing different numbers in execution the following program? #include <iostream> #include <cstdlib> using namespace std; int main() { for (int x = 1; x <= 10; x++) { cout << rand() << endl; } } output: 41 18467 6334 26500 19169 15724 11478 29358 26962 24464
6 odpowiedzi
+ 2
You are telling the program to give you random numbers so yes they are different. if you want to get random num let's say from 0 to 100 then u do rand () % 100; If it did not work, try saving it inside an int variable and then use it again in the for loop.
+ 1
No problem 👍
+ 1
Bcoz u have used rand() function.......rand() is used to generate any random numbers.......U have applied loop till 10.....so it has printed 10 random numbers
0
@kouroshazizi thanks for your help☺
0
thank u for ur help @Mohitkulkarni :)
- 1
hr,#((g))