|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
UNE PETITE CALCULETTE [DEV-C++]
Information sur la source
Description
Bon ben une simple calculette, le code est long mais tres simple, elle peut faire pas mal de truc, ainsi qu'afficher la table d'un nombre demande (c'est pas tres utile mais bon...)
Source
- #include <stdio.h>
-
- void main()
- {
- float nombre1;
- float nombre2;
- int increment=1;
- int choix;
- double fact;
-
- while (increment==1)
- {
- printf("######################################################\n");
- printf("#---------------------CALCULETTE---------------------#\n");
- printf("######################################################\n\n");
- printf("Choisissez une categorie :\n\n");
- printf("1. additions 5. exposants\n");
- printf("2. soustractions 6. factoriels\n");
- printf("3. multiplications 7. tables de multiplications\n");
- printf("4. divisions 8. quitter\n\n");
- scanf("%d",&choix);
- while ( (choix < 1) || (choix > 8) )
- {
- printf("\nERREUR : veuillez entrer un nombre de 1 a 8 ! ");
- scanf("%d",&choix);
- }
- while (choix == 1)
- {
- printf("\nEntrez un premier nombre : ");
- scanf("%f",&nombre1);
- printf("\nEntrez un second nombre : ");
- scanf("%f",&nombre2);
- printf("\n%.3f + %.3f = %.3f\n\n",nombre1,nombre2,(nombre1+nombre2));
- printf("Faites 1 pour refaire une addition et 2 pour revenir au menu : ");
- scanf("%d",&choix);
- while ( (choix < 1) || (choix > 2) )
- {
- printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
- scanf("%d",&choix);
- }
- if (choix==2) choix=0;
- if (choix==1) choix=1;
- }
- while (choix == 2)
- {
- printf("\nEntrez un premier nombre : ");
- scanf("%f",&nombre1);
- printf("\nEntrez un second nombre : ");
- scanf("%f",&nombre2);
- printf("\n%.3f - %.3f = %.3f\n\n",nombre1,nombre2,(nombre1-nombre2));
- printf("Faites 1 pour refaire une soustraction et 2 pour revenir au menu : ");
- scanf("%d",&choix);
- while ( (choix < 1) || (choix > 2) )
- {
- printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
- scanf("%d",&choix);
- }
- if (choix==2) choix=0;
- if (choix==1) choix=2;
- }
- while (choix == 3)
- {
- printf("\nEntrez un premier nombre : ");
- scanf("%f",&nombre1);
- printf("\nEntrez un second nombre : ");
- scanf("%f",&nombre2);
- printf("\n%.3f x %.3f = %.3f\n\n",nombre1,nombre2,(nombre1*nombre2));
- printf("Faites 1 pour refaire une multiplication et 2 pour revenir au menu : ");
- scanf("%d",&choix);
- while ( (choix < 1) || (choix > 2) )
- {
- printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
- scanf("%d",&choix);
- }
- if (choix==2) choix=0;
- if (choix==1) choix=3;
- }
- while (choix == 4)
- {
- printf("\nEntrez un premier nombre : ");
- scanf("%f",&nombre1);
- printf("\nEntrez un second nombre : ");
- scanf("%f",&nombre2);
- printf("\n%.3f : %.3f = %.3f\n\n",nombre1,nombre2,(nombre1/nombre2));
- printf("Faites 1 pour refaire une division et 2 pour revenir au menu : ");
- scanf("%d",&choix);
- while ( (choix < 1) || (choix > 2) )
- {
- printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
- scanf("%d",&choix);
- }
- if (choix==2) choix=0;
- if (choix==1) choix=4;
- }
- while (choix==5)
- {
- printf("\nEntrez un nombre : ");
- scanf("%f",&nombre1);
- printf("\nEntrez son exposant : ");
- scanf("%d",&choix);
- while ( (nombre1 == 0) && (choix < 1) )
- {
- printf("\nERREUR : il est impossible de calculer un exposant\n");
- printf(" plus petit que 1 pour le nombre zero\n");
- printf(" car cela reviendrait a diviser zero par zero, ce qui\n");
- printf(" conduit a une aberration.\n\n");
- printf("Veuillez donc entrer un autre exposant pour zero : ");
- scanf("%d",&choix);
- }
- nombre2=1;
- if (choix < 0)
- {
- for (increment=0 ; increment > choix ; increment--) nombre2=nombre2/nombre1;
- }
- if (choix >= 0)
- {
- for (increment=0 ; increment < choix ; increment++) nombre2=nombre2*nombre1;
- }
- printf("\n%.3f exposant %d = %.3f\n\n",nombre1,choix,nombre2);
- printf("Faites 1 pour refaire l'exposant d'un nombre et 2 pour revenir au menu : ");
- scanf("%d",&choix);
- while ( (choix < 1) || (choix > 2) )
- {
- printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
- scanf("%d",&choix);
- }
- increment=1;
- if (choix==2) choix=0;
- if (choix==1) choix=5;
- }
- while (choix==6)
- {
- printf("\nEntrez un nombre : ");
- scanf("%d",&choix);
- while ( (choix < 0) || (choix > 170) )
- {
- printf("\nERREUR : veuillez entrer un nombre entier positif pas plus grand que 170 ! ");
- scanf("%d",&choix);
- }
- fact=1;
- for (increment=1 ; increment <= choix ; increment++) fact=fact*increment;
- printf("\n%d! = %.0f\n\n",choix,fact);
- printf("Faites 1 pour refaire un factoriel et 2 pour revenir au menu : ");
- scanf("%d",&choix);
- while ( (choix < 1) || (choix > 2) )
- {
- printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
- scanf("%d",&choix);
- }
- increment=1;
- if (choix==2) choix=0;
- if (choix==1) choix=6;
- }
- while (choix==7)
- {
- printf("\nVous voulez la table de quelle nombre ? ");
- scanf("%f",&nombre1);
- printf("\nVous la voulez jusqu'ou ? ");
- scanf("%d",&choix);
- printf("\n");
- while (choix > 250)
- {
- printf("ERREUR : veuillez ne pas depasser 250 ! ");
- scanf("%d",&choix);
- }
- for (increment=1 ; increment<=choix ; increment++) printf("%3d x %.3f = %.3f\n",increment,nombre1,(nombre1*increment));
- printf("\n\nFaites 1 pour refaire une table de multiplication et 2 pour revenir au menu : ");
- scanf("%d",&choix);
- while ( (choix < 1) || (choix > 2) )
- {
- printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
- scanf("%d",&choix);
- }
- increment=1;
- if (choix==2) choix=0;
- if (choix==1) choix=7;
- }
- if (choix==8) increment=0;
- }
- }
#include <stdio.h>
void main()
{
float nombre1;
float nombre2;
int increment=1;
int choix;
double fact;
while (increment==1)
{
printf("######################################################\n");
printf("#---------------------CALCULETTE---------------------#\n");
printf("######################################################\n\n");
printf("Choisissez une categorie :\n\n");
printf("1. additions 5. exposants\n");
printf("2. soustractions 6. factoriels\n");
printf("3. multiplications 7. tables de multiplications\n");
printf("4. divisions 8. quitter\n\n");
scanf("%d",&choix);
while ( (choix < 1) || (choix > 8) )
{
printf("\nERREUR : veuillez entrer un nombre de 1 a 8 ! ");
scanf("%d",&choix);
}
while (choix == 1)
{
printf("\nEntrez un premier nombre : ");
scanf("%f",&nombre1);
printf("\nEntrez un second nombre : ");
scanf("%f",&nombre2);
printf("\n%.3f + %.3f = %.3f\n\n",nombre1,nombre2,(nombre1+nombre2));
printf("Faites 1 pour refaire une addition et 2 pour revenir au menu : ");
scanf("%d",&choix);
while ( (choix < 1) || (choix > 2) )
{
printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
scanf("%d",&choix);
}
if (choix==2) choix=0;
if (choix==1) choix=1;
}
while (choix == 2)
{
printf("\nEntrez un premier nombre : ");
scanf("%f",&nombre1);
printf("\nEntrez un second nombre : ");
scanf("%f",&nombre2);
printf("\n%.3f - %.3f = %.3f\n\n",nombre1,nombre2,(nombre1-nombre2));
printf("Faites 1 pour refaire une soustraction et 2 pour revenir au menu : ");
scanf("%d",&choix);
while ( (choix < 1) || (choix > 2) )
{
printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
scanf("%d",&choix);
}
if (choix==2) choix=0;
if (choix==1) choix=2;
}
while (choix == 3)
{
printf("\nEntrez un premier nombre : ");
scanf("%f",&nombre1);
printf("\nEntrez un second nombre : ");
scanf("%f",&nombre2);
printf("\n%.3f x %.3f = %.3f\n\n",nombre1,nombre2,(nombre1*nombre2));
printf("Faites 1 pour refaire une multiplication et 2 pour revenir au menu : ");
scanf("%d",&choix);
while ( (choix < 1) || (choix > 2) )
{
printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
scanf("%d",&choix);
}
if (choix==2) choix=0;
if (choix==1) choix=3;
}
while (choix == 4)
{
printf("\nEntrez un premier nombre : ");
scanf("%f",&nombre1);
printf("\nEntrez un second nombre : ");
scanf("%f",&nombre2);
printf("\n%.3f : %.3f = %.3f\n\n",nombre1,nombre2,(nombre1/nombre2));
printf("Faites 1 pour refaire une division et 2 pour revenir au menu : ");
scanf("%d",&choix);
while ( (choix < 1) || (choix > 2) )
{
printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
scanf("%d",&choix);
}
if (choix==2) choix=0;
if (choix==1) choix=4;
}
while (choix==5)
{
printf("\nEntrez un nombre : ");
scanf("%f",&nombre1);
printf("\nEntrez son exposant : ");
scanf("%d",&choix);
while ( (nombre1 == 0) && (choix < 1) )
{
printf("\nERREUR : il est impossible de calculer un exposant\n");
printf(" plus petit que 1 pour le nombre zero\n");
printf(" car cela reviendrait a diviser zero par zero, ce qui\n");
printf(" conduit a une aberration.\n\n");
printf("Veuillez donc entrer un autre exposant pour zero : ");
scanf("%d",&choix);
}
nombre2=1;
if (choix < 0)
{
for (increment=0 ; increment > choix ; increment--) nombre2=nombre2/nombre1;
}
if (choix >= 0)
{
for (increment=0 ; increment < choix ; increment++) nombre2=nombre2*nombre1;
}
printf("\n%.3f exposant %d = %.3f\n\n",nombre1,choix,nombre2);
printf("Faites 1 pour refaire l'exposant d'un nombre et 2 pour revenir au menu : ");
scanf("%d",&choix);
while ( (choix < 1) || (choix > 2) )
{
printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
scanf("%d",&choix);
}
increment=1;
if (choix==2) choix=0;
if (choix==1) choix=5;
}
while (choix==6)
{
printf("\nEntrez un nombre : ");
scanf("%d",&choix);
while ( (choix < 0) || (choix > 170) )
{
printf("\nERREUR : veuillez entrer un nombre entier positif pas plus grand que 170 ! ");
scanf("%d",&choix);
}
fact=1;
for (increment=1 ; increment <= choix ; increment++) fact=fact*increment;
printf("\n%d! = %.0f\n\n",choix,fact);
printf("Faites 1 pour refaire un factoriel et 2 pour revenir au menu : ");
scanf("%d",&choix);
while ( (choix < 1) || (choix > 2) )
{
printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
scanf("%d",&choix);
}
increment=1;
if (choix==2) choix=0;
if (choix==1) choix=6;
}
while (choix==7)
{
printf("\nVous voulez la table de quelle nombre ? ");
scanf("%f",&nombre1);
printf("\nVous la voulez jusqu'ou ? ");
scanf("%d",&choix);
printf("\n");
while (choix > 250)
{
printf("ERREUR : veuillez ne pas depasser 250 ! ");
scanf("%d",&choix);
}
for (increment=1 ; increment<=choix ; increment++) printf("%3d x %.3f = %.3f\n",increment,nombre1,(nombre1*increment));
printf("\n\nFaites 1 pour refaire une table de multiplication et 2 pour revenir au menu : ");
scanf("%d",&choix);
while ( (choix < 1) || (choix > 2) )
{
printf("\nERREUR : veuillez entrer 1 ou 2 ! ");
scanf("%d",&choix);
}
increment=1;
if (choix==2) choix=0;
if (choix==1) choix=7;
}
if (choix==8) increment=0;
}
}
Conclusion
Fichier Zip
Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
Télécharger le zip
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
|