+ 1
How to convert this code into c
12 odpowiedzi
+ 9
+ 7
+ 7
And that's the problem
Adding digits is simple
Adding number is confusing
+ 7
No problem just need to make an logic which read string and when face any digit poped that into an variable, then when other digit comes that will add to that variable.
will update and get back to you in some time after launch till that time if you get solution then good else I'll edit and post that
Have some 🍎 🍎 🍎 🍎
+ 7
DishaAhuja
Thanks sis
+ 5
G.Vamshi Krishna Mohd Shahzer hi,
I didn't able to find code, ping me if you post the correct link of the code
Till that have these 🍎 🍎 🍎
+ 5
Mohd Shahzer
You want to convert it into C then you can use an shorter way
#include <stdio.h>
int main()
{
char str[80];
int count,n=0,sum=0;
printf("Enter the string");
scanf("%s",str);
for(count=0;str[count]!='\0'; count++)
{
if((str[count]>='0') && (str[count]<='9'))
{
n += 1;
sum += (str[count] - '0');
}
}
printf("NO. of Digits in the string=%d\n",n);
printf("Sum of all digits=%d\n",sum);
}
#include <stdio.h>
int SumDigits(unsigned long long n, const int base) {
int sum = 0;
for (; n; n /= base)
sum += n % base;
return sum;
}
int main() {
printf("%d %d %d %d %d\n",
SumDigits(12345, 10),
SumDigits(123045, 10),
SumDigits(0xfe, 16),
SumDigits(0xf0e, 16) );
return 0;
}
If you looking for any alternative way ping me
Have some 🍎 🍎 🍎 🍎
+ 3
G.Vamshi Krishna Mohd Shahzer here is your updated code in simple regex use
you can use regex expression to extract the digits %*[^0-9]
https://code.sololearn.com/cbE14MaLUVvC/?ref=app
Have some 🍎 🍎 🍎 🍎 🍎
+ 1
Anyone try this
+ 1
I want to add double numbers
+ 1
TS23NA10
Output
23+10=33
0
If input is
TS47S2378
Output
47 +2378 =2425