zoukankan      html  css  js  c++  java
  • 例3-7 统计字符

    例3-7 统计字符

    程序核心——循环语句判断语句的镶嵌

    程序

    #四则运算
    程序核心——判断语句
    ##程序
    

    include<stdio.h>

    int main()
    {
    int digit,letter,other,i;//定义三个变量统计结果
    char ch;

    digit=letter=other=0;
    
    printf("Enter 10 characters:");
    for(i=1;i<=10;i++)
    {
    	ch=getchar();
    	if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='z'))
    		letter++;
    	else if(ch<='9'&&ch>='0')
    		digit++;
    	else
    		other++; 
     } 
    printf("letter=%d,digit=%d,other=%d
    ",letter,digit,other);
    
    return 0;
    

    }```

    结果

    Enter 10 characters:lkj098、、、、
    letter=3,digit=3,other=4
    
    --------------------------------
    Process exited after 16.71 seconds with return value 0
    请按任意键继续. . .
    .
    

    分析

    重点:ch=getchar();向ch输入一个字符

  • 相关阅读:
    dfs-入门模板
    dp-状压dp
    c++ sizeof详解
    各种排序算法
    简介
    第178场周赛总结
    单调队列
    2019.10.24刷题统计
    2019.10.23刷题统计
    2019.10.22刷题统计
  • 原文地址:https://www.cnblogs.com/5236288kai/p/10582582.html
Copyright © 2011-2022 走看看