Write a program that accepts a sentence and calculate the number of letters and digits. Suppose the following input is supplied to the program: hello world! 123 Then, the output should be: LETTERS 10 DIGITS 3
Input Format
The input line consists of a sentence
Constraints
No Constrains
Output Format
The output line consists of number of letters and digits
Sample Input 0
hello world! 123
Sample Output 0
LETTERS 10
DIGITS 3
Explanation 0
The number of letters in the given sentence is 10 The nunber of numbers in the given sentence is 3
Program :
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
char s[1000];
int i;
int a = 0;
int b = 0;
scanf("%[^\n]%*c",s);
for(i=0;s[i];i++)
{
if((s[i]>=65&&s[i]<=90)||(s[i]>=97&&s[i]<=122))
a++;
else if(s[i]>=45&&s[i]<=57)
b++;
}
printf("LETTERS %d\n",a);
printf("DIGITS %d\n",b);
return 0;
}
0 Comments