#include <stdio.h>
void main()
{
char string[80];
int count,nc=0,sum=0;
printf(“Enter the string containing both digits and alphabet\n”);
scanf(“%s”,string);
for(count=0;string[count]!=’\0′; count++)
{
if((string[count]>=’0′) && (string[count]<=’9′))
{
nc += 1;
sum += (string[count] – ’0′);
} /* End of if */
} /* End of For */
printf(“NO. of Digits in the string=%d\n”,nc);
printf(“Sum of all digits=%d\n”,sum);
} /* End of main() */
/*—————————————————–
Output
Enter the string containing both digits and alphabet
goodmorning25
NO. of Digits in the string=2
Sum of all digits=7
——————————————————–*/
Not Satisfied ? Just search & get the result
Related posts:
- C program to find the number of integers divisible by 5 between the given range N1 and N2, where N1 < N2 and are integers. Also find the sum of all these integer numbers that divisible by 5 and output the computed results
- C program to accept a string and find the number of times the word ‘the’ appears in it
- C Program to accept two strings and concatenate them i.e.The second string is appended to the end of the first string
- C program to accept a string and a substring and check if the substring is present in the given string
- C program to read N integers (zero, +ve and -ve) into an array A and to a) Find the sum of negative numbers b) Find the sum of positive numbers and c) Find the average of all input numbers Output the various results computed with proper headings
