Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <limits.h>
- int main(int argc, char **argv){
- if (argc == 2){
- if (strcmp(argv[1], "-s") == 0){
- int sum = 0;
- int num;
- while (scanf("%d", &num) != EOF){ // Ctrl+D
- sum += num;
- }
- printf("Sum = %d\n", sum);
- return EXIT_SUCCESS;
- } else if (strcmp(argv[1], "-p") == 0){
- int product = 1;
- int num;
- while (scanf("%d", &num) != EOF){ // Ctrl+D
- product *= num;
- }
- printf("Product = %d\n", product);
- return EXIT_SUCCESS;
- }
- }
- if (strcmp(argv[1], "-s") == 0){
- int sum = 0;
- for (int i = 2; i < argc; i++){
- sum += atoi(argv[i]);
- }
- printf("Sum = %d\n", sum);
- return EXIT_SUCCESS;
- } else if (strcmp(argv[1], "-p") == 0){
- int product = 1;
- for (int i = 2; i < argc; i++){
- product *= atoi(argv[i]);
- }
- printf("Product = %d\n", product);
- return EXIT_SUCCESS;
- } else if (strcmp(argv[1], "-M") == 0){
- int maxNum = INT_MIN;
- for (int i = 2; i < argc; i++){
- int num = atoi(argv[i]);
- if (num > maxNum){
- maxNum = num;
- }
- }
- printf("Max number = %d\n", maxNum);
- return EXIT_SUCCESS;
- } else if (strcmp(argv[1], "-m") == 0){
- // min number
- return EXIT_SUCCESS;
- } else {
- fprintf(stderr, "Invalid option!\n");
- return EXIT_FAILURE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement