Jim175
Πολύ δραστήριο μέλος
Ο Jim175 αυτή τη στιγμή δεν είναι συνδεδεμένος. Είναι 20 ετών. Έχει γράψει 844 μηνύματα.
08-02-24
01:01
Νταξει κατάλαβα τι εννοεί, βγάζει νόημα, το 2ο με το foo δεν έχω καταλάβει καθόλουναι βρισκει ως λαθος το δευτερο srand(t) με το ιδιο t
Το αποτελεσμα ειναι παντα 0 στο sum
This C program generates an array a of 10 random integers between 0 and 99 (inclusive), calculates the sum of 10 random numbers generated using rand(), and subtracts each element of the array a from the generated random numbers while accumulating the sum. Finally, it prints the result.
However, the second call to srand(t) with the same seed t as the first one effectively resets the random number generator to the same state, causing it to produce the same sequence of random numbers. As a result, the elements of the array a and the random numbers generated in the second loop are identical to those generated in the first loop. Therefore, when subtracting the elements of a from the random numbers in the second loop, the result will always be zero, leading to the sum being printed as zero.
To solve this issue and get a meaningful result, you should not reinitialize the random number generator with the same seed.
Jim175
Πολύ δραστήριο μέλος
Ο Jim175 αυτή τη στιγμή δεν είναι συνδεδεμένος. Είναι 20 ετών. Έχει γράψει 844 μηνύματα.
08-02-24
00:28
Ναι αλλά δε με βοήθησε έβγαζε ότι το πρόγραμμα της ερώτησης 2.4 είναι λάθος γραμμένο κιόλαςλόγω έλλειψης χρονου, το εβαλες στο chatgpt?