Glaas2

suma de numeros en cadenas

Feb 4th, 2015
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. main()
  6. {
  7.  char cad1[25], cad2[25], numa[4], numb[4], *p;
  8.  int num1, num2, i,j=0;
  9.  printf("Ingrese la cadena 1: \n");
  10.  setbuf(stdin, NULL);
  11.  gets(cad1);
  12.  printf("Ingrese la cadena 2: \n");
  13.  setbuf(stdin, NULL);
  14.  gets(cad2);
  15.  for(i=0;i<25;i++)
  16.  {
  17.   if(cad1[i] >= 48 && cad1[i] <= 57)
  18.   {
  19.    for(j=0;j<3;j++)
  20.    {
  21.    //printf("%d  ", i);
  22.    p=&cad1[i];
  23.    numa[j]=*p;
  24.    i++;
  25.    }
  26.   }
  27.   numa[3]='\0';
  28.  }
  29.  
  30.  j=0;
  31.   for(i=0;i<25;i++)
  32.  {
  33.   if(cad2[i] >= 48 && cad2[i] <= 57)
  34.   {
  35.    p=&cad2[i];
  36.    numb[j]=*p;
  37.    j++;
  38.   }
  39.   numb[3]='\0';
  40.  }
  41.  
  42.  printf("\nA: %s  B: %s", numa,numb);
  43.  num1=atoi(numa);
  44.  num2=atoi(numb);
  45.  printf("\nLa suma de los numeros es: %d \n\n", num1+num2);
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment