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

Catégorie :Maths & Algorithmes Niveau : Débutant Date de création : 18/03/2002 Date de mise à jour : 07/04/2002 13:10:59 Vu / téléchargé: 2 124 / 85

Note :
1 / 10 - par 1 personne
1,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

Description

Cliquez pour voir la capture en taille normale
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

voila c'est tout  
 

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

Commentaires et avis

Aucun commentaire pour le moment.

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,343 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.