Math, asked by velly6524, 2 months ago

Given a string input 1 having alphabets or digits or both.Find the sum of digits or extract only the characters depending on input 2.​

Answers

Answered by krishna210398
0

Answer:

the sum of digits or extract only the characters depending on input 2.​

Step-by-step explanation:

#include <stdio.h>

#include <string.h>

int main() {

   //code

int t,j;

char a[100000];

scanf("%d",&t);

while(t--)

{  

   int sum=0,rev=0,i=0,l;

   scanf("%s",a);

   l=strlen(a);

   for(i=0;i<l;i++)

   {

         if (isdigit(a[i])){

            while(isdigit(a[i])){

              rev = rev *10 + (a[i]-48);

              i++;

            }

         }

       sum+=rev;

       rev=0;        

   }

   printf("%d\n",sum);

}

   return 0;

}

#SPJ2

Answered by ravilaccs
0

Answer:

the sum of digits or extract only the characters depending on input 2.​

Step-by-step explanation:

#include <stdio.h>

#include <string.h>

int main() {

  //code

int t,j;

char a[100000];

scanf("%d",&t);

while(t--)

{  

  int sum=0,rev=0,i=0,l;

  scanf("%s",a);

  l=strlen(a);

  for(i=0;i<l;i++)

  {

        if (isdigit(a[i])){

           while(isdigit(a[i])){

             rev = rev *10 + (a[i]-48);

             i++;

           }

        }

      sum+=rev;

      rev=0;        

  }

  printf("%d\n",sum);

}

  return 0;

}

Similar questions