![]() |
Given a string, our task is to first read this string from the user then find the sum of all the digits present in the given string. Examples Input : abc23d4 Output: 9 Input : 2a3hd5j Output: 10 Approach:
Example: C#
Output 1:Enter a string abc23d4 Sum = 9 Output 2: Enter a string 2a3hd5j Sum = 10 Explanation: In the above example, first we read the string and we will iterate each character and check if the character is an integer or not by comparing the ASCII value of the character. If the character is an integer then add the value to the sum. At the end of the iteration, the sum variable will have the total sum of digits in the string. |
Reffered: https://www.geeksforgeeks.org
C# |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 10 |