易截截图软件、单文件、免安装、纯绿色、仅160KB

C_使用switch语句

 源码:
# include <stdio.h>
 
int main()
{
    int num;
    /* 下面定义的各变量,分别代表个位,十位,百位,千位,万位,十万位以及位数 */
    int indiv, ten, hundred, thousand; 
    int ten_thousand, hundred_thousand, place;
 
    printf("请输入一个整数(0~999999):");
    scanf("%d", &num);
 
    /* 判断变量num的位数 */
    if(num > 99999)
        place = 6;
    else if(num > 9999)
        place = 5;
    else if(num > 999)
        place = 4;
    else if(num > 99)
        place = 3;
    else if(num > 9)
        place = 2;
    else
        place = 1;
    printf("place = %d\n", place);
     
    printf("每位数字为:");
 
    /* 求出num在各位上的值 */
    hundred_thousand = num/100000;
    ten_thousand = (num - hundred_thousand*100000)/10000;
    thousand = (num - hundred_thousand*100000 - ten_thousand*10000)/1000;
    hundred = (num - hundred_thousand*100000 - ten_thousand*10000 
              - thousand*1000)/100;
    ten = (num - hundred_thousand*100000 - ten_thousand*10000 
          - thousand*1000 - hundred*100)/10;
    indiv = num - hundred_thousand*100000 - ten_thousand*10000 
            - thousand*1000 - hundred*100 - ten*10;
 
    /* 判断变


相关文档:

由C数组array[

        昨天一个同学和我谈起他在测试C程序时时发现使用-1为下标来访问数组,gcc并没有报错,而且能够运行成功,这个以前我还没试过,处于好奇,今天下午抽了点时间看了一下。
     下面是我使用的测试代码,运行环境是DEV-C++4.9.9.2,编译器使用的是gcc。
&nb ......

将类成员函数用做C回调函数

提出问题:
回调函数是基于C编程的Windows SDK的技术,不是针对C++的,程序员可以将一个C函数直接作为回调函数,但是如果试图直接使用C++的成员函数作为回调函数将发生错误,甚至编译就不能通过。
分析原因:
普通的C++成员函数都隐含了一个传递函数作为参数,亦即“this”指针,C++通过传递一个指向自身的指 ......

C/C++中的Split函数

 C/C++中的Split函数是strtok()其函数原型如下:
char * strtok (char * str, const char * delimiters);
函数说明
strtok()用来将字符串分割成一个个片段。参数str指向欲分割的字符串,参数delimiters则为分割字符串,当strtok()在参数
str的字符串中发现到参数delimiters的分割字符时则会将该字符改为'\0'字符 ......

C_普通位运算

 源码:
# include <stdio.h>
 
int main()
{
    /* 定义了一个无符号字符型变量,此变量只能用来存储无符号数 */
    unsigned char result;
    
    int a, b, c, d;
    a = 2;
    b = 4; ......

C_判断语句if与else的组合使用

 源码:
# include <stdio.h>
 
int main()
{
    int x, y;
    printf("请输入自变量x:");
    scanf("%d", &x);
 
    if(x < 6)
    {
        ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号