Jim175
Πολύ δραστήριο μέλος
Ο Jim175 αυτή τη στιγμή δεν είναι συνδεδεμένος. Είναι 20 ετών. Έχει γράψει 844 μηνύματα.
08-02-24
00:14
Καλησπέρα παιδιά, επειδή είμαι αρκετά αρχάριος θα ήθελα μια βοήθεια σχετικά με το πώς λειτουργούν τα παρακάτω προγράμματα και τι εμφανίζουν
chester20080
Περιβόητο μέλος
Ο Μπάμπης αυτή τη στιγμή είναι συνδεδεμένος. Είναι 29 ετών και Πτυχιούχος του τμήματος Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών ΑΠΘ. Έχει γράψει 5,685 μηνύματα.
08-02-24
00:24
λόγω έλλειψης χρονου, το εβαλες στο chatgpt?
Jim175
Πολύ δραστήριο μέλος
Ο Jim175 αυτή τη στιγμή δεν είναι συνδεδεμένος. Είναι 20 ετών. Έχει γράψει 844 μηνύματα.
08-02-24
00:28
Ναι αλλά δε με βοήθησε έβγαζε ότι το πρόγραμμα της ερώτησης 2.4 είναι λάθος γραμμένο κιόλαςλόγω έλλειψης χρονου, το εβαλες στο chatgpt?
chester20080
Περιβόητο μέλος
Ο Μπάμπης αυτή τη στιγμή είναι συνδεδεμένος. Είναι 29 ετών και Πτυχιούχος του τμήματος Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών ΑΠΘ. Έχει γράψει 5,685 μηνύματα.
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.
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.
chester20080
Περιβόητο μέλος
Ο Μπάμπης αυτή τη στιγμή είναι συνδεδεμένος. Είναι 29 ετών και Πτυχιούχος του τμήματος Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών ΑΠΘ. Έχει γράψει 5,685 μηνύματα.
08-02-24
01:31
καλει αναδρομικα την f και αθροιζει αναποδα τον πινακαΝταξει κατάλαβα τι εννοεί, βγάζει νόημα, το 2ο με το foo δεν έχω καταλάβει καθόλου
16+8+4+2+1
και τελος +1 ξανα
=32
Jim175
Πολύ δραστήριο μέλος
Ο Jim175 αυτή τη στιγμή δεν είναι συνδεδεμένος. Είναι 20 ετών. Έχει γράψει 844 μηνύματα.
08-02-24
08:39
Σίγουρα δεν είναι 31?καλει αναδρομικα την f και αθροιζει αναποδα τον πινακα
16+8+4+2+1
και τελος +1 ξανα
=32
chester20080
Περιβόητο μέλος
Ο Μπάμπης αυτή τη στιγμή είναι συνδεδεμένος. Είναι 29 ετών και Πτυχιούχος του τμήματος Ηλεκτρολόγων Μηχανικών & Μηχανικών Υπολογιστών ΑΠΘ. Έχει γράψει 5,685 μηνύματα.
08-02-24
13:45
Νομίζω 32, μπαίνει προτελευταία και αθροιζει 2+1Σίγουρα δεν είναι 31?
Και μπαίνει τελευταία και αθροιζει +a[0] το 1 ξανά
Ε τρέξτο και βλέπεις το αποτέλεσμα
Χρήστες Βρείτε παρόμοια
-
Τα παρακάτω 0 μέλη και 1 επισκέπτες διαβάζουν μαζί με εσάς αυτό το θέμα:Tα παρακάτω 25 μέλη διάβασαν αυτό το θέμα:
-
Φορτώνει...