chester20080
Περιβόητο μέλος
Ο Μπάμπης αυτή τη στιγμή είναι συνδεδεμένος. Είναι 29 ετών και Πτυχιούχος του τμήματος Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών ΑΠΘ. Έχει γράψει 5,622 μηνύματα.
08-02-24
13:45
Νομίζω 32, μπαίνει προτελευταία και αθροιζει 2+1Σίγουρα δεν είναι 31?
Και μπαίνει τελευταία και αθροιζει +a[0] το 1 ξανά
Ε τρέξτο και βλέπεις το αποτέλεσμα
chester20080
Περιβόητο μέλος
Ο Μπάμπης αυτή τη στιγμή είναι συνδεδεμένος. Είναι 29 ετών και Πτυχιούχος του τμήματος Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών ΑΠΘ. Έχει γράψει 5,622 μηνύματα.
08-02-24
00:37
ναι βρισκει ως λαθος το δευτερο srand(t) με το ιδιο tΝαι αλλά δε με βοήθησε έβγαζε ότι το πρόγραμμα της ερώτησης 2.4 είναι λάθος γραμμένο κιόλας
Το αποτελεσμα ειναι παντα 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.
chester20080
Περιβόητο μέλος
Ο Μπάμπης αυτή τη στιγμή είναι συνδεδεμένος. Είναι 29 ετών και Πτυχιούχος του τμήματος Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών ΑΠΘ. Έχει γράψει 5,622 μηνύματα.
08-02-24
00:24
λόγω έλλειψης χρονου, το εβαλες στο chatgpt?