How to write a C Program to Maximum count of chars, Maximum count of numbers and Maximum count of signs in C Programming Language ?
This C Program to Max count of chars, Max count of nums and Max count of signs.
Solution:
- #include <stdio.h>
- #include <conio.h>
- void main() {
- int chars=0, nums=0, mchars=0, mnums=0, signs=0, msigns = 0, i;
- char str[500];
- puts("Input string:");
- gets(str);
- for (i = 0; str[i]; i++) {
- if (str[i] >= '0' && str[i] <= '9') {
- nums++;
- if (chars > mchars) mchars = chars;
- if (signs > msigns) msigns = signs;
- chars = signs = 0;
- }
- else {
- if (nums > mnums) mnums = nums;
- nums = 0;
- if ((str[i] >= 'a' && str[i] <= 'z') ||
- (str[i] >= 'A' && str[i] <= 'Z')) {
- chars++;
- if (signs > msigns) msigns = signs;
- signs = 0;
- }
- else if (str[i] == '*' || str[i] == '+' || str[i] == '-'){
- signs++;
- if (chars > mchars) mchars = chars;
- chars = 0;
- }
- else {
- if (chars > mchars) mchars = chars;
- if (signs > msigns) msigns = signs;
- }
- }
- }
- if (nums > mnums) mnums = nums;
- if (chars > mchars) mchars = chars;
- if (signs > msigns) msigns = signs;
- printf("Max count of chars: %d\nMax count of nums: %d\nMax count of signs: %d\n", mchars, mnums, msigns);
- printf("Is chars count bigger than signs count: "); printf(mchars > msigns ? "true" : "false");
- _getch();
- }