Write a program to
count total number of alphabets, digits or special characters in a string using
loop
- #include <stdio.h>
- #include <string.h>
- void main()
- {
- char str[100];
- int alph, digit, splch;
- int len;
- alph=0;
- digit=0;
- splch=0;
- len=0;
- printf("Count total number of alphabets, digits and special characters :\n");
- printf("Input the string : ");
- gets(str);
- len=strlen(str);
- for(int i=0; i < len; i++) {
- if ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
- alph++;
- else if (str[i] >= '0' && str[i] <= '9')
- digit++;
- else
- splch++;
- }
- //Check each character of string
- printf("Number of Alphabetics in the string is : %d\n", alph);
- printf("Number of Digits in the string is : %d\n", digit);
- printf("Number of Special characters in the string is : %d\n\n", splch);
- }
একটি মন্তব্য পোস্ট করুন