【C语言】编写一个程序统计输入字符串中: 各个数字、空白字符、以及其他所有字符出现的次数。

#include <stdio.h>
int main()
{
	char s[20];
	char num=0;
	int num_count=0;
	int space_count=0;
	int other_count=0;
	while((num=getchar())!=‘\n‘)
	{
		 if(num>=‘0‘&&num<=‘9‘)
          {
             num_count++;
          }
          else if(num==‘ ‘)   
          {
             space_count++;
          }
          else
          {
             other_count++;
          }
	}
	printf("num_count=%d\n",num_count);
	printf("space_count=%d\n",space_count);
	printf("other_count=%d\n",other_count);
	return 0;
}
时间: 2024-08-24 05:57:17

【C语言】编写一个程序统计输入字符串中: 各个数字、空白字符、以及其他所有字符出现的次数。的相关文章

编写一个程序统计输入字符串中: 各个数字、空白字符、以及其他所有字符出现的次数

#include <stdio.h> int main() {      char a=0;     int num_count=0;     int space_count=0;     int other_count=0;                                                  //注意此处,不能写成a=getchar(),然后while(a!='\n'),这样做只能输入一行,然后进行死循环      while((a=getchar())!='\

编写一个程序统计输入字符串中:各个数字,空白字符,以及其他所有字符常出现的次数。

编写一个程序,统计输入字符串中每一个小写英文字母出现的次数

import java.util.Scanner; /** * @author:(LiberHome) * @date:Created in 2019/3/1 22:18 * @description: * @version:$ */ /*编写一个程序,统计输入字符串中每一个小写英文字母出现的次数*/ public class page0901 { public static void main(String[] args) { /*首先,输入一段字符串作为字符数组*/ System.out.p

c语言:编写一个程序,输入a,b,c三个值,输出其中最大者

程序: //编写一个程序,输入a,b,c三个值,输出其中最大者 #include<stdio.h> int main() { int a,b,c,max; printf("请输入三个数:"); scanf("%d,%d,%d",&a,&b,&c); max=a; if (max<b) { max=b; } if (max<c) { max=c; } printf("%d\n",max); retur

编写一个程序,从标准输入中读取若干string对象并查找连续重复出现的单词。所谓连续重复出现的意思是:一个单词后面紧跟着这个单词本身。要求记录连续重复出现的最大次数以及对应的单词

#include<iostream> #include<string> #include<vector> using namespace std; int main() { string maxStr,Str1,Str2; int maxNum,Num1,Num2; if(cin>>Str1) Num1=1; maxNum=0; while(cin>>Str2) { Num2=1; if(Str2==Str1) Num2=++Num1; if(N

《用C++语言编写一个程序,求PI的值》

1 //编写一个C++程序求PI的值 2 /* 3 PI=16arctan(1/5)-4arctan(1/239) 4 其中arctan用如下形式的极数计算: 5 arctan=x-(x^3/3)+(x^5/7)-(x^7/7)+... 6 */ 7 #include<iostream> 8 using namespace std; 9 double arctan(double x){ 10 double sqr = x*x; 11 double e = x; 12 double r = 0;

编写一个函数将参数字符串中的字符反向排列

编写一个函数reverse_string(char * string)(递归实现) 实现:将参数字符串中的字符反向排列. 要求:不能使用C函数库中的字符串操作函数. 注意:将参数字符串中的字符反向排列,不是反向输出. 代码如下: #include<stdio.h> #include<stdlib.h> #include<assert.h> int my_strlen(char *str)//求字符串长度 { int count=0; while(*str++) { co

编写一个程序,输入a、b、c三个值,输出其中最大值。

题目描述 输入 一行数组,分别为a b c 输出 a b c其中最大的数 样例输入 10 20 30 样例输出 30 程序:#include<stdio.h> int main(){    int arr[3],i,max=0;     for(i=0;i<3;i++)       scanf("%d",&arr[i]);    for(i=0;i<3;i++){        if(arr[i]>max)        max=arr[i];  

案例四:银行提供了整存整取定期储蓄业务,其存期分为一年、两年、三年、五年,到期凭存单支取本息。年利率如下表。试编写一个程序,输入存入的本金数目,计算假设存一年、两年、三年、五年,到期取款时,银行应支付的本息分别是多少。

年利率 存期 年利率 一年 2.25% 两年 2.7% 三年 3.24% 五年 3.6% package project_04; import java.util.Scanner; /** * 2018-9-7 21:42:25 * @author Suaron XiMen * */ public class Interest { public static void main(String[] args) { //计算银行存款本息 Scanner input=new Scanner(Syste