Advertisement
pabloducato

XYZ

Jan 5th, 2020
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #pragma warning(disable:4996)
  5.  
  6. int main()
  7. {
  8.     int sum = 0, sum2=0, sum3=0;
  9.     printf("A = ");
  10.     int array[1024];
  11.     int length = 0;
  12.     char buffer[1024];
  13.     char *aux;
  14.     fgets(buffer, 1023, stdin);
  15.     aux = strtok(buffer, ",");
  16.     while (aux)
  17.     {
  18.         array[length] = atoi(aux);
  19.         length++;
  20.         aux = strtok(NULL, ",");
  21.     }
  22.     for (int i = 0; i < length; i++)
  23.     {
  24.         sum = sum + (int) array[i];
  25.     }
  26.     printf("\n", sum);
  27.     printf("B = ");
  28.     int array2[1024];
  29.     int length2 = 0;
  30.     char buffer2[1024];
  31.     char *aux2;
  32.     fgets(buffer2, 1023, stdin);
  33.     aux2 = strtok(buffer2, ",");
  34.     while (aux2)
  35.     {
  36.         array2[length2] = atoi(aux2);
  37.         length2++;
  38.         aux2 = strtok(NULL, ",");
  39.     }
  40.     for (int j = 0; j < length2; j++)
  41.     {
  42.         sum2 = sum2 + (int)array2[j];
  43.     }
  44.     printf("\na = %d\n", sum);
  45.     printf("\nb = %d\n", sum2);
  46.     printf("\n\n");
  47.     printf("   %d\n", sum);
  48.     printf("+   %d\n", sum2);
  49.     sum3 = sum + sum2;
  50.     printf("-----\n");
  51.     printf("   %d\n", sum3);
  52.     system("pause");
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement