当前位置:网站首页>Function: calculates the number of uppercase letters in a string

Function: calculates the number of uppercase letters in a string

2022-07-06 14:35:00 |Light|

requirement

Make up a name countc function , Requirements are as follows :
Formal parameters :array The character array name of the string
function : Statistics array The number of uppercase letters in the array
Return value : The number of uppercase letters in the string

Code

#include<string.h>
/* * In this function, you can count the uppercase letters in the string  */
 int countc(char a[])
 {
    
     int sum=0;
    int i;
    for(i=0;i<100;i++)
    {
    
        if(a[i]=='\0')
        break;
        else if(a[i]>='A'&&a[i]<='Z')
        sum = sum+1;
    }
    return sum;
 }

 

test

Test input
dfaDASFA4rdfsFDGSdfsgh

Output
The number of capital letters is 9

原网站

版权声明
本文为[|Light|]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060918542910.html