Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- // Prototype des fonctions
- int Menu();
- double OpeAri(int a, int b);
- int InitTab(int taille, int choix);
- int FormTab(int tab[], int taille);
- int main()
- {
- // Déclaration des variables
- int choix=0, tab[9], i=0,tabi[2];
- char recommencer='';
- // Code
- srand(time(NULL));
- rand();
- do{
- choix = Menu();
- switch(choix)
- {
- case 1: //Entrée des nombres, appel de la fonction OpeAri, affichage du resultat et possibilité de recommencer
- do{
- for (int j = 1; j < 3; j++) {
- do
- {
- printf("Entrez le %d",j);
- fflush(stdin);
- scanf("%d", &tabi[j - 1]);
- if (tabi[j] < 0 || tabi[j]>50) {
- printf("Erreur, le nombre doit etre compris entre 0 et 50!\n");
- }
- } while (tabi[j]<0 || tabi[j]>50);
- }
- printf("Resultat: %lf.\n", OpeAri(tabi[0], tabi[1]));
- do {
- printf("Voulez-vous recommencer ? (O)ui ou (N)on\n");
- fflush(stdin);
- scanf("%c", &recommencer);
- if (recommencer != 'O' && recommencer != 'o' && recommencer != 'N' && recommencer != 'n') {
- printf("Erreur, veuillez entrer (O)ui ou (N)on!\n");
- }
- } while (recommencer != 'O' && recommencer != 'o' && recommencer != 'N' && recommencer != 'n')
- }while(recommencer == 'O' || recommencer == 'o');
- break;
- case 2:
- printf("%d\n", InitTab(8, 0));
- system("pause");
- break;
- case 3:
- printf("%d\n", InitTab(5, 0));
- system("pause");
- break;
- case 4:
- printf("%d\n", InitTab(50, 1));
- system("pause");
- break;
- case 5:
- printf("%d\n", InitTab(33, 2));
- system("pause");
- break;
- case 6:
- for(i = 0; i < 9; i++)
- {
- tab[i] = InitTab(20, 3);
- printf("Le resultat du tableau numero %d est %d\n", i+1, tab[i]);
- }
- printf("Le resultat du tableau stockant les resultats precedents est: %d\n", FormTab(tab, 9));
- system("pause");
- break;
- default:
- break;
- }
- }while(choix != 7);
- return 0;
- }
- int Menu()
- {
- // Déclaration des variables
- int choix;
- // Code bete d'utiliser plusieurs printf surtout que tu fais des retours de chariots à chaque fois
- system("cls");
- printf("Voulez-vous:\n");
- printf("1. Effectuer une operation arithmetique ?\n");
- printf("2. Appliquer une formule sur un tableau 1x8 ?\n");
- printf("3. Appliquer une formule sur un tableau 1x5 ?\n");
- printf("4. Appliquer une formule sur un tableau 1x50 ?\n");
- printf("5. Appliquer une formule sur un tableau 1x33 ?\n");
- printf("6. Appliquer une formule sur plusieurs tableaux ?\n");
- printf("7. Quitter le programme ?\n");
- do
- {
- printf("Votre choix: "); fflush(stdin); scanf("%d", &choix);
- if (choix < 1 || choix>7) {
- printf("Choix incorrect!\n");
- }
- } while (choix<1 || choix>7);
- return choix;
- }
- double OpeAri(int a, int b){return (5 / (double)(b - 10)) + (b / (double)(a + b)) + ((double)(3 * a*b) / 2);}
- int InitTab(int taille, int choix)
- {
- // Déclaration des variables, instencie tjs tes variables
- int tab[taille], i=0;
- char conf='';
- // Code
- do{
- for(i = 0; i <= taille-1; i++)
- {
- switch(choix)
- {
- case 0:
- printf("Entrez le nombre allant dans la case: %d: \n", i); fflush(stdin); scanf("%d", &tab[i]);
- break;
- case 1:
- tab[i] = rand() % 10 + 1;
- break;
- case 2:
- tab[i] = rand() % 15 + 1;
- break;
- case 3:
- tab[i] = rand() % 21;
- break; //inutile de mettre un default si c'est toi qui l'utilise et pas l'utilisateur
- }
- }
- printf("Le tableau contient les nombres suivants: ");
- for(i = 0; i < taille; i++)
- {
- printf("%d, ", tab[i]);
- }
- do
- {
- printf("\nConfirmez-vous ces entrees ? (O)ui ou (N)on\n");
- fflush(stdin);
- scanf("%c", &conf);
- if (conf != 'O' && conf != 'o' && conf != 'N' && conf != 'n') {
- printf("Erreur, veuillez entrer (O)ui ou (N)on!\n");
- }
- } while (conf != 'O' && conf != 'o' && conf != 'N' && conf != 'n');
- }while(conf == 'N' || conf == 'n');
- return FormTab(tab, taille);
- }
- int FormTab(int tab[], int taille)
- {
- // Déclaration des variables
- int i=0, total = 0;
- int j = taille - 1;
- for(i = 0; i <= ((taille-1)/2); i++){
- if(i == j){
- total += tab[i];
- }
- else{
- total += (tab[i] * tab[j]);
- }
- j--;
- }
- return total;
- }
Advertisement
Add Comment
Please, Sign In to add comment