C language to find the number of uppercase letters in a string, the number of words, the number of substrings and whether an integer is a palindrome number

Source: Internet
Author: User

#include <stdio.h>

#include <ctype.h>

#pragma mark counts the number of characters in each letter entered from the terminal. Use the # sign as the input end flag

int main ()

{

int num[26] = {0}, I; char c;

while ((c = GetChar ()) = = ' # ') {

if (Isupper (c)) {

num[c-65]++;

}

}

for (int i = 0; i<26; i++) {

if (Num[i]) {

printf ("%c:%d\n", i+65, Num[i]);

}

}

return 0;

}

#pragma mark counts the number of words in a line of characters

int main ()

{

Char s[81];

int I, c, num=0,word=0;

Gets (s);

for (i=0; (c=s[i])! = ' + '; i++) {

/* One: judging */

if (c = = 32) {

word++;

}else continue;

}

/* Two: judging */

if (c== ') word = 0;

else if (word==0) {word=1; num++;}

printf ("There is%d words.\n", word);

return 0;

}

#include <stdio.h>

#pragma mark counts the number of occurrences of a string of substrings

int main ()

{

int I, j, K,count;

Char str1[20],str2[20];

printf ("Zhu Chuan:");

Gets (STR1);

printf ("Zi Chuan:");

Gets (STR2);

Count = 0;

for (i=0;str1[i];i++)

for (j=i,k=0;str1[j]==str2[k];j++,k++)

if (!str2[k+1])

count++;

printf ("Chuxian cishu=%d\n", count);

}

#pragma mark asks if an integer is a palindrome number

#include <stdio.h>

int main ()

{

Long num;

int array[10];

scanf ("%ld", &num);

int n = num, k = 0;

do {

Array[k] = n%10;

k++;

n = N/10; Completed the progression of the numbers on a single digit

} while (n!=0);

int i = 0;

int flag = 0;

for (; i< (k-1)/2; i++) {

if (array[i] = = Array[k-1-i]) {flag = 1;}

}

if (flag) {

printf ("%ld is palindrome", num);

}else{

printf ("%ld is not a palindrome", num);

}

}

C language to find the number of uppercase letters in a string, the number of words, the number of substrings and whether an integer is a palindrome number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.