#include using namespace std; int main(int argc, char **argv) { if (argc < 3) { cout << "Le programme a besoin de deux arguments." << endl; return 0; } int a = atoi(argv[1]); int b = atoi(argv[2]); cout << a << " + " << b << " = " << a+b << endl; return 0; } #include using namespace std; int main(int argc, char **argv) { if (argc < 3) { cout << "Le programme a besoin de deux arguments." << endl; return 0; } int a = atoi(argv[1]); int b = atoi(argv[2]); if (b == 0) { cout << "Erreur: division par 0" << endl; return 0; } cout << a << " / " << b << " = " << float(a)/b << endl; return 0; } #include using namespace std; int main(int argc, char **argv) { if (argc < 2) { cout << "Le programme a besoin d'au moins un argument." << endl; return 0; } int somme = atoi(argv[1]); cout << argv[1]; for (int i=2; i<argc; i++) { somme = somme + atoi(argv[i]); cout << " + " << argv[i]; } cout << " = " << somme << endl; return 0; }
- Sunday
- December 22nd, 2024
- Ajouter un cours