Ok so I've been away from math for a long while now (and programming for that matter) and I've got this assignment that i'm kinda stuck on
i'll paste my code at the bottom... it's not complete, i'll say that now but i just need some1 to steer me in the right direction.
As i'm not entirely familiar with the calculations of the perfect numbers ( i know what it means just not entirely sure of how to code it)
i'll paste my code at the bottom... it's not complete, i'll say that now but i just need some1 to steer me in the right direction.
As i'm not entirely familiar with the calculations of the perfect numbers ( i know what it means just not entirely sure of how to code it)
Code:
#include <stdio.h> main() { // initialisation des variables int nbrMax; // Nbr d'entiers à saisir int tableauNbr[nbrMax-1]; // Tableau pour contenir les nombres entrés par l'usager int i; // Compteur boucle int j, k, somme; // variables pour calcul nbr parfait char condition; // Oui ou Non // Boucle do ... while, pour ne pas devoir repartir le programme pour chaque calcul do { printf ("Entrez le nombre d'entier (Max 10):\n"); scanf ("%d", &nbrMax); // boucle pour la saisie des nombres et remplissage le tableau. for (i = 0; i < nbrMax; i++) { scanf ("%d", &tableauNbr[i]); } // Calculs pour trouver les nombres parfaits somme = 0; for (j = 0; j < nbrMax; j++) { for (k = 1; k < tableauNbr[j]; k++) { if(tableauNbr[j]%k==0) { somme += k; } } // Affichage des resultats if (somme = tableauNbr[j]) printf("%d est un nombre parfait\n", tableauNbr[j]); else printf("%d n'est pas un nombre parfait\n", tableauNbr[j]); } // Condition requise pour repartir du début printf ("\nVoulez vous faire un autre calcul, (o/n)?"); fflush (stdin); // Fonction pour vider stdin condition = toupper(getchar()); // Capitaliser la letter et soumettre à condition } while ( condition == 'O'); // Repartir du début si O system("pause") ; }
Comment