??xml version="1.0" encoding="utf-8" standalone="yes"?>中文在线播放一区二区,日韩国产欧美区,黄色污网站在线免费观看http://www.aygfsteel.com/BeautifulMan/category/54939.htmlzh-cnSat, 09 Jan 2016 08:32:48 GMTSat, 09 Jan 2016 08:32:48 GMT60C Primer Plus W?5?位操?复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2016/01/06/428948.html李阿昀李阿昀Wed, 06 Jan 2016 01:27:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2016/01/06/428948.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/428948.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2016/01/06/428948.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/428948.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/428948.html阅读全文

李阿昀 2016-01-06 09:27 发表评论
]]>
C Primer Plus W?4?l构和其他数据Ş?复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/12/10/428593.html李阿昀李阿昀Thu, 10 Dec 2015 08:53:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/12/10/428593.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/428593.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/12/10/428593.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/428593.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/428593.htmlstructure {    char itable;    int&nb...  阅读全文

李阿昀 2015-12-10 16:53 发表评论
]]>
C Primer Plus W?3?文g输入/输出 复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/12/07/428533.html李阿昀李阿昀Mon, 07 Dec 2015 04:02:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/12/07/428533.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/428533.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/12/07/428533.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/428533.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/428533.html/* 把多个文件的内容q加C个文件中 */#include <stdio.h>#include &...  阅读全文

李阿昀 2015-12-07 12:02 发表评论
]]>
C Primer Plus W?2?存储cR链接和内存理 复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/12/04/428522.html李阿昀李阿昀Fri, 04 Dec 2015 12:03:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/12/04/428522.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/428522.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/12/04/428522.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/428522.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/428522.html阅读全文

李阿昀 2015-12-04 20:03 发表评论
]]>
C Primer Plus W?1?字符串和字符串函?复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/11/30/428413.html李阿昀李阿昀Mon, 30 Nov 2015 01:47:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/30/428413.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/428413.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/30/428413.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/428413.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/428413.html阅读全文

李阿昀 2015-11-30 09:47 发表评论
]]>
C Primer Plus W?0?数组和指?复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/11/24/428353.html李阿昀李阿昀Tue, 24 Nov 2015 14:31:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/24/428353.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/428353.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/24/428353.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/428353.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/428353.html// 多维数组和指?include <stdio.h>int main(void){  ...  阅读全文

李阿昀 2015-11-24 22:31 发表评论
]]>
C Primer Plus W??函数 复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/11/22/428322.html李阿昀李阿昀Sun, 22 Nov 2015 15:03:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/22/428322.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/428322.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/22/428322.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/428322.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/428322.html扩展L(fng)步编E练?Q?/span>
#include <stdio.h>
void to_binary(unsigned long n);
int main(void)
{
    unsigned long number;
    printf("Enter an integer (q to quit): \n");
    while(scanf("%lu", &number) == 1)
    {
        printf("Binary equivalent: ");
        to_binary(number);
        putchar('\n');
        printf("Enter an integer (q to quit): \n");
    }
    printf("Done!\n");
    return 0;
}
void to_binary(unsigned long n)
{
    int r;
    r = n % 2;
    if(n >= 2)
        to_binary(n / 2);
    putchar('0' + r);
    return;
}
复习(fn)?/span>
1、实际参数和形式参量有何不同Q?br />{:(x)
形式参量Q也被称为Ş式参敎ͼ是一个变量,它在被调函数中进行定义。实际参数是在函数调用中出现的|它被赋值给形式参量。可以把实际参数认ؓ(f)是在函数被调用时用来初始化Ş式参量的倹{?br />2、写Z面所描述的各个函数的ANSI函数头。注意:(x)只写出函数头卛_Q不需要实现?br />a.donut()接受一个intcd的参敎ͼ然后输出若干?Q输?的数目等于参数的倹{?br />b.gear()接受两个intcd的参数ƈq回intcd的倹{?br />c.stuff_it()的参数包括一个doublecd的g?qing)一个doublecd变量的地址Q功能是把第一个数值存攑ֈ指定的地址中?br />{:(x)
a.void donut(int n)
b.int gear(int n, int m)
c.void stuff_it(double n, double * d)
3、只写出下列函数的ANSI C函数_(d)不需要实现函数?br />a.n_to_char()接受一个intcd的参数ƈq回一个charcd的倹{?br />b.digits()接受的参数是一个doublecd的数值和一个intcd的数|q回值类型是int?br />c.random()不接受参敎ͼq回intcd的数倹{?br />{:(x)
a.char n_to_char(int n)
b.int digits(double n, int m)
c.int random(void)
4、设计一个实C整数相加q将l果q回的函数?br />{:(x)
int plus(int n, int m)
{
    return n + m;
}
5、假如问?中的函数实现两个doublecd的数值相加,那么应该如何修改原函敎ͼ
{:(x)
double plus(double n, double m)
{
    return n + m;
}
6、设计函数alter()Q其输入参数是两个intcd的变量x和yQ功能是分别这两个变量的数值改为它们的和以?qing)它们的差?br />{:(x)Q?span style="background-color: yellow;">注意Q下面这U写法是错误的!Q!Q?/span>
void alter(int x, int y)
{
    x = x + y;
    y = x - y;
}
正确的写法如下:(x)
void alter(int * u, int * v)
{
    int temp;

    temp = *u;
    *u = *u + *v;
    *v = temp - *v;
}
7、判断下面的函数定义是否正确?br />
void salami(num)
{
    int num, count;

    for(count = 1; count <= num; num++)
        printf("O salami mio!\n");
}
{:(x)
有错误。num应该在salami()的参数列表中而不是在花括号之后声明,而且应该是count++而不是num++?br />8、编写一个函敎ͼ使其q回3个整数参C的最大倹{?br />{:(x)
int max(int x, int y, int z)
{
    int max;
    if(x > y)
        if(x > z)
            max = x;
        else
            max = z;
    else
        if(y > z)
            max = y;
        else
            max = z;
    return max;
}
or Q?span style="background-color: yellow;">更简z一点)

int max(int x, int y, int z)
{
    int max = x;
    if(y > max)
        max = y;
    if(z > max)
        max = z;
    return max;
}
9、给定下面的输出Q?br />Please choose one of the following:
1)copy files 2)move files
3)remove files 4)quit
Enter the number of your choice:
a.用一个函数实现菜单的昄Q且该菜单有4个用数字~号的选项q要求你选择其中之一Q输出应该如题中所C)?br />b.~写一个函敎ͼ该函数接受两个intcd的参敎ͼ(x)一个上界和一个下界。在函数中,首先从输入终端读取一个整敎ͼ如果该整C在上下界规定的范围内Q则函数重新昄菜单Q用本题目a(chn)部分中的函数Q以再次提醒用户输入新倹{如果输入数值在规定的范围内Q那么函数应该将数D回给调用函数?br />c.使用本题目a(chn)和b部分中的函数~写一个最的E序。最的意思是该程序不需要实现菜单中所描述的功能;它只需要显C些选项q能获取正确的响应即可?br />{:(x)Q参考课后答案)
#include <stdio.h>
void menu(void);
int get_input(intint);
int main(void)
{
    int res;

    menu();
    while((res = get_input(1, 4)) != 4)
        printf("I like choice %d.\n", res);
    printf("Bye!\n");
    return 0;
}
void menu(void)
{
    printf("Please choose one of the following: \n");
    printf("1)copy files          2)move files\n");
    printf("3)remove files        4)quit\n");
    printf("Enter the number of your choice: \n");
}
int get_input(int min, int max)
{
    int number;

    scanf("%d", &number);
    while(number < min || number > max)
    {
        printf("%d is not a valid choice; try again.\n", number);
        menu();
        scanf("%d", &number);
    }
    return number;
}
~程l习(fn)
1?br />
#include <stdio.h>
double min(doubledouble);
int main(void)
{
    printf("One of the smaller of the two numbers is %.2f", min(23.34, 12.11));
    return 0;
}
double min(double x, double y)
{
    return x < y ? x : y;
}
2?br />
#include <stdio.h>
void chline(char ch, int i, int j);
int main(void)
{
    chline('$', 3, 5);
    return 0;
}
void chline(char ch, int i, int j)
{
    int index;

    for(index = 1; index < i; index++)
        putchar(' ');
    for(index = 1; index <= j - i + 1; index++)
        putchar(ch);
}
3?br />
#include <stdio.h>
void chline(char ch, int col, int row);
int main(void)
{
    chline('$', 3, 5);
    return 0;
}
void chline(char ch, int col, int row)
{
    int i, j;

    for(i = 0; i < row; i++)
    {
        for(j = 0; j < col; j++)
           putchar(ch);
        putchar('\n');
    }
}
4?br />
#include <stdio.h>
double computer(double a, double b);
int main(void)
{
    printf("%.2f?.2f的谐均值是Q?.3f\n", 0.3, 0.5, computer(0.3, 0.5));
    return 0;
}
double computer(double a, double b)
{
    double result;

    result = 1 / ((1/a + 1/b) / 2);
    return result;
}
5?br />
#include <stdio.h>
void larger_of(double *, double *);
int main(void)
{
    double x = 23.3;
    double y = 34.4;
    printf("Originally x = %.1f; y = %.1f\n", x, y);
    larger_of(&x, &y);
    printf("Now x = %.1f; y = %.1f\n", x, y);
    return 0;
}
void larger_of(double * u, double * v)
{
    double temp;
    temp = *u > *v ? *u : *v;
    *u = temp;
    *v = temp;
}
6、(W一ơ码的程序读取到换行W的时候也?x)打印出来,会(x)给人看不明白的感觉Q烦性按[Enter]键的时候就退出@环,不要dEOFQ?br />
#include <stdio.h>
#include <ctype.h>
void printchar(char ch);
int main(void)
{
    char ch;

    printf("误入要分析的东西:(x)\n");
    while((ch = getchar()) != EOF)
    {
        printchar(ch);
    }
    return 0;
}
void printchar(char ch)
{
    if(isalpha(ch))
    {
        printf("%c %d\n", ch, toupper(ch) % 'A' + 1);
    }
}
修改之后Q程序如下:(x)
#include <stdio.h>
#include <ctype.h>
int show_c_location(char ch);

int main(void)
{
    char ch;

    printf("Please enter some characters: \n");
    while((ch = getchar()) != '\n')
        printf("%c-%d ", ch, show_c_location(ch));
    return 0;
}
int show_c_location(char ch)
{
    int result;

    if(isalpha(ch))
        result = toupper(ch) - 'A' + 1;
    else
        result = -1;
    return result;
}
7?br />
#include <stdio.h>
double power(double n, int p);
int main(void)
{
    double x, xpow;
    int exp;

    printf("Enter a number and the positive integer power");
    printf(" to which\nthe number will be raised. Enter q");
    printf(" to quit.\n");
    while(scanf("%lf%d", &x, &exp) == 2)
    {
        xpow = power(x, exp);
        printf("%.3g to power %d is %.5g\n", x, exp, xpow);
        printf("Enter next pair of numbers or q to quit.\n");
    }
    printf("Hope you enjoyed this power trip -- bye!\n");
    return 0;
}
double power(double n, int p)
{
    int i;
    double result = 1;

    if(n != 0)
    {
        if(p > 0)
        {
            for(i = 1; i <= p; i++)
                result *= n;
        }
        else if(p < 0)
        {
            for(i = 1; i <= -p; i++)
                result *= (1 / n);
        }
        else
            result = 1;
    }
    else
    {
        if(p == 0)
            result = 1;// 0?ơ方是一个有争议的数Q本题认Z(x)得到1
        else
            result = 0;
    }
    return result;
}
8?br />
#include <stdio.h>
double power(double n, int p);
int main(void)
{
    double x, xpow;
    int exp;

    printf("Enter a number and the positive integer power");
    printf(" to which\nthe number will be raised. Enter q");
    printf(" to quit.\n");
    while(scanf("%lf%d", &x, &exp) == 2)
    {
        xpow = power(x, exp);
        printf("%.3g to power %d is %.5g\n", x, exp, xpow);
        printf("Enter next pair of numbers or q to quit.\n");
    }
    printf("Hope you enjoyed this power trip -- bye!\n");
    return 0;
}
double power(double n, int p)
{
    double result = 1;

    if(n != 0)
    {
        if(p > 0)
            result = n * power(n, p-1);
        else if(p < 0)
            result = (1/n) * power(n, p+1);
        else
            result = 1;
    }
    else
    {
        if(p == 0)
            result = 1;// 0?ơ方是一个有争议的数Q本题认Z(x)得到1
        else
            result = 0;
    }
    return result;
}
9?br />
#include <stdio.h>
void to_base_n(unsigned long n, int range);
int main(void)
{
    unsigned long number;
    int range;
    printf("误入要转换的无W号整数和所规定的进制数Q?nbsp;\n");
    while(scanf("%lu %d", &number, &range) == 2)
    {
        if(range >= 2 && range <= 10)
        {
            printf("无符h?lu转换?dq制Cؓ(f)Q?nbsp;", number, range);
            to_base_n(number, range);
            putchar('\n');
            printf("误入要转换的无W号整数和所规定的进制数Q?nbsp;\n");
        }
        else
            printf("所规定的进制数的范围是2~10Q请输入正确的数字\n");
    }
    printf("Done!\n");
    return 0;
}
void to_base_n(unsigned long n, int range)
{
    int r;

    r = n % range;
    if(n >= range)
        to_base_n(n / range, range);
    putchar('0' + r);
    return;
}
10、(题意理解不清楚,借鉴CSDN——vs9841原作者的做法Q脑子太W,实在想不出来Q?br />
#include <stdio.h>
int Fibonacci(int n);
int main(void)
{
    int n = 9;
    printf("当n?dӞ斐LU_数gؓ(f)%d", n, Fibonacci(9));
    return 0;
}
int Fibonacci(int n)
{
    int a, b, i;
    a = 0;
    b = 1;
    int sum;
    if(n == 0)
        return 0;
    if(n == 1)
        return 1;
    else
    {
        for(i = 2; i <= n; i++)
        {
            sum = a + b;
            a = b;
            b = sum;
        }
        return sum;
    }
}
ȝQM来说~程l习(fn)相对以往来说要简单了Q但W?0题没明白什么意思,所以只能借鉴别h的了Q真是天下文章一大抄Q?img src ="http://www.aygfsteel.com/BeautifulMan/aggbug/428322.html" width = "1" height = "1" />

李阿昀 2015-11-22 23:03 发表评论
]]>
C Primer Plus W??字符输入/输出和输入确? 复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/11/21/428310.html李阿昀李阿昀Sat, 21 Nov 2015 12:12:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/21/428310.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/428310.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/21/428310.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/428310.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/428310.html复习(fn)?/span>
1、putchar(getchar())是一个有效的表达式,它实C么功能?getchar(putchar())也有效吗Q?br />{:(x)
语句putchar(getchar())使程序读取下一个输入字Wƈ打印它,getchar()的返回g为putchar()的参数。getchar(putchar())则不是合法的Q因为getchar()不需要参数而putchar()需要一个参数?br />2、下面的每个语句实现什么功能?
    a.putchar('H');
    b.putchar('\007');
    c.putchar('\n');
    d.putchar('\b');
{:(x)
a. 昄字符H
b.如果pȝ使用ASCII字符~码Q则发出一声警?br />c.把光标移动到下一行的开?br />d.退后一?br />3、假设?zhn)有一个程序countQ该E序对输入的字符q行l计。用countE序设计一个命令行命o(h)Q对文gessay中的字符q行计数q将l果保存在名为essayct的文件中?br />{:(x)
count < essay > essayct
4、给定问?中的E序和文Ӟ下面哪个命o(h)是正的Q?br />{:(x)
a.essayct <essay
b.count essay
c.essay >count
{:(x)
c是正的?br />5、EOF是什么?
{:(x)
它是由getchar()和scanf()q回的信P一个特定的|Q用来表明已l到达了文g的结?br />6、对l出的输入,下面每个E序D늚输出是什么(假定ch是intcd的,q且输入是缓冲的Q?
a. 输入如下所C:(x)
    If you quit, I will.[enter]
    E序D如下所C:(x)
    while ((ch = getchar()) != 'i')
            putchar(ch);
b. 输入如下所C:(x)
    Harhar[enter]
    E序D如下所C:(x)
    while ((ch = getchar()) != '\n')
    {
               putchar(ch++);
               putchar(++ch);
    }
{:(x)
a.If you qu
b.HJacrthjacrt
7、C如何处理h不同文g和换行约定的不同计算机系l?
{:(x)
C的标准I/O库把不同的文件Ş式映ؓ(f)l一的流Q这样就可以按相同的方式对它们进行处理?br />8、在~冲pȝ中把数D入与字符输入相؜合时Q?zhn)所面(f)的潜在问题是什么?
{:(x)
数字输入跌I格和换行符Q但是字W输入ƈ不是q样。假设?zhn)~写了这L(fng)代码Q?br />
    int score;
    char grade;
    printf("Enter the score.\n");
    scanf("%d", &score);
    printf("Enter the letter grade.\n");
    grade = getchar();
假设(zhn)输入分?8Q然后按下回车键来把分数发送给E序Q?zhn)同时也发送了一个换行符Q它?x)成Z一个输入字W被d到grade中作为等U的倹{如果在字符输入之前q行了数字输入,应该添加代码以在获取字W输入之前剔除换行字W?br />~程l习(fn)
1?br />
#include <stdio.h>
int main(void)
{
    int ch;
    int count = 0;
    while((ch = getchar()) != EOF) // 包括换行W?/span>
        count++;
    printf("The number of characters is %d\n", count);
    return 0;
}
2、(觉得q题难的!Q!看了一些他人写的例子,直胡说八道!Q!不过q是完美解决了)
#include <stdio.h>
int main(void)
{
    int ch;
    int i = 0;

    while((ch = getchar()) != EOF)
    {
        if(ch >= 32)  // 可打印字W?/span>
        {
            putchar(ch);
            printf("/%d  ", ch);
            i++;
        }
        else if(ch == '\n')  // 打印换行W?/span>
        {
            printf("\\n");
            printf("/%d  ", ch);
            putchar(ch); // 清除输入~冲区里面的换行W?/span>
            = 0// i|ؓ(f)0重新开始计敎ͼ因ؓ(f)题目要求每次遇到一个换行符时就要开始打C个新?/span>
        }
        else if(ch == '\t')  // 打印制表W?/span>
        {
            printf("\\t");
            printf("/%d  ", ch);
            i++;
        }
        else // 打印控制字符
        {
            putchar('^');
            putchar(ch + 64);
            printf("/%d  ", ch);
        }
        if(i == 10)
        {
            putchar('\n');
            i = 0;
        }
    }
    return 0;
}
q行l果如下Q?br />
I love you!
I/73   /32  l/108  o/111  v/118  e/101   /32  y/121  o/111  u/117Q每行打?0个|
!/33  \n/10Q每ơ遇C个换行符时就开始一个新行)
My hello world^A
M/77  y/121   /32  h/104  e/101  l/108  l/108  o/111   /32  w/119Q每行打?0个|
o/111  r/114  l/108  d/100  ^A/1  \n/10Q每ơ遇C个换行符时就开始一个新行)
^Z
3?br />
#include <stdio.h>
#include <ctype.h>
int main(void)
{
    int ch;
    int low_count = 0, up_count = 0;

    while((ch = getchar()) != EOF)
    {
        if(islower(ch))
            low_count++;
        if(isupper(ch))
            up_count++;
    }
    printf("A number of capital letters: %d\n", up_count);
    printf("A number of lower case letters: %d\n", low_count);
    return 0;
}
4?br />
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
int main(void)
{
    char ch;
    long chars = 0L; // l计单词的字W数
    int words= 0; // 单词?/span>
    bool inword = false// 如果ch在一个单词中Q则inword为true

    printf("Enter text to be analyzed: \n");
    while((ch = getchar()) != EOF)
    {
        if(!isspace(ch) && !ispunct(ch))
            chars++;
        if(!isspace(ch) && !inword)
        {
            inword = true;
            words++;
        }
        if(isspace(ch) && inword)
            inword = false;
    }
    printf("The average number of words per word: %ld\n", chars / words);
    return 0;
}
5、(二分搜烦法W一ơ碰见,搞了大半天了Q借鉴的是CSDN-----vs9841作者的做法Q不q稍微加了下工)
#include <stdio.h>
char get_choice(void);
char get_first(void);
int main(void)
{
    int low = 1, high = 100, guess = 50;
    char ch;

    printf("Pick an integer from 1 to 100. I will try to guess it\n");
    printf("Unis your number %d?\n", guess);
    while((ch = get_choice()) != 'q')
    {
        if(ch == 'a')
        {
            printf("I knew I could do it!\n");
            break;
        }
        else if(ch == 'b')
        {
            printf("It is too small!\n");
            low = guess + 1;
        }
        else if(ch == 'c')
        {
            printf("It is too big!\n");
            high = guess - 1;
        }
        guess = (low + high) / 2;
        printf("Unis your number %d?\n", guess);
    }
    printf("Done!\n");
    return 0;
}
char get_choice(void)
{
    int ch;

    printf("Enter the letter of your choice: \n");
    printf("a. right       b. too small\n");
    printf("c. too big     q. quit\n");
    ch = get_first();
    while((ch < 'a' || ch > 'c') && ch != 'q')
    {
        printf("Please respond with a, b, c, or q.\n");
        ch = get_first();
    }
    return ch;
}
char get_first(void)
{
    int ch;

    ch = getchar();
    while(getchar() != '\n')
        continue;
    return ch;
}
6?br />
char get_first(void)
{
    int ch;

    while((ch = getchar()) == '\n')
        continue;
    while(getchar() != '\n')
        continue;
    return ch;
}
7?br />
#include <stdio.h>
#define WORK_OVERTIME 40
#define MULTIPLE 1.5
#define RATE1 0.15
#define RATE2 0.20
#define RATE3 0.25
#define BREAK1 300
#define BREAK2 450
#define BASE1 (BREAK1 * RATE1)
#define BASE2 (BASE1 + (BREAK2 - BREAK1) * RATE2)
char get_choice(void);
char get_first(void);
int main(void)
{
    int hour, choise;
    double total, tax, net_pay;
    double base_pay; // 基本工资{不能?define来定义了Q因为它要随着E序而改变了Q书上真是胡说八?/span>

    while((choise = get_choice()) != 'q')
    {
        switch(choise)
        {
        case 'a':
            base_pay = 8.15;
            break;  // break只是DE序qswitch语句Q蟩到switch之后的下一条语句!Q!
        case 'b':
            base_pay = 9.33;
            break;
        case 'c':
            base_pay = 10.00;
            break;
        case 'd':
            base_pay = 11.20;
            break;
        default:
            printf("Program error!\n");
            break;
        }
        printf("Please enter the hour used: ");
        scanf("%d", &hour); // 获取每周工作时数时没有像书上那样判断,我偷懒了Q!Q?/span>
        if(hour <= WORK_OVERTIME)
        {
            total = hour * base_pay;
            if (total <= BREAK1)
            {
                tax = total * RATE1;
                net_pay = total - tax;
            }
            else
            {
                tax = BASE1 + (total - BREAK1) * RATE2;
                net_pay = total - tax;
            }
        }
        else
        {
            total = base_pay * WORK_OVERTIME + (hour - WORK_OVERTIME) * MULTIPLE * base_pay;
            if(total <= BREAK2)
            {
                tax = BASE1 + (total - BREAK1) * RATE2;
                net_pay = total - tax;
            }
            else
            {
                tax = BASE2 + (total - BREAK2) * RATE3;
                net_pay = total - tax;
            }
        }
        printf("The total pay: %.2f; tax: %.2f; net pay: %.2f\n", total, tax, net_pay);
    }
    printf("Bye!\n");
    return 0;
}
char get_choice(void)
{
    int ch;

    printf("*****************************************************************\n");
    printf("Enter number corresponding to the desired pay rate or action:\n");
    printf("a) $8.75/hr\tb) $9.33/hr\n");
    printf("c) $10.00/hr\td) $11.20/hr\n");
    printf("q) quit\n");
    printf("*****************************************************************\n");
    printf("Please enter your choise: ");
    ch = get_first();
    while((ch < 'a' || ch > 'd') && ch != 'q')
    {
        printf("Please respond with a, b, c, d, or q.\n");
        ch = get_first();
    }
    return ch;
}
char get_first(void)
{
    int ch;

    while((ch = getchar()) == '\n')
        continue;
    while(getchar() != '\n')
        continue;
    return ch;
}
8?br />
#include <stdio.h>
char get_choice(void);
char get_first(void);
float get_float(void);
int main(void)
{
    char choise;
    float first_number, second_number;

    while((choise = get_choice()) != 'q')
    {
        printf("Enter first number: ");
        first_number = get_float();
        printf("Enter second number: ");
        second_number = get_float();
        switch(choise)
        {
        case 'a':
            printf("%.1f + %.1f = %.1f\n", first_number, second_number, first_number + second_number);
            break;
        case 's':
            printf("%.1f - %.1f = %.1f\n", first_number, second_number, first_number - second_number);
            break;
        case 'm':
            printf("%.1f * %.1f = %.1f\n", first_number, second_number, first_number * second_number);
            break;
        case 'd':
            if(second_number == 0)
            {
                printf("Enter a number other than 0: ");
                second_number = get_float();
                printf("%.1f / %.1f = %.1f\n", first_number, second_number, first_number / second_number);
            }
            else
                printf("%.1f / %.1f = %.1f\n", first_number, second_number, first_number / second_number);
            break;
        default:
            printf("Program error!\n");
            break;
        }
    }
    printf("Bye.\n");
    return 0;
}
char get_choice(void)
{
    int ch;

    printf("Enter the operation of your choice: \n");
    printf("a. add\ts. subtract\n");
    printf("m. multiply\td. divide\n");
    printf("q. quit\n");
    ch = get_first();
    while(ch != 'a' && ch != 's' && ch != 'm' && ch != 'd' && ch != 'q')
    {
        printf("Please respond with a, s, m, d, or q.\n");
        ch = get_first();
    }
    return ch;
}
char get_first(void)
{
    int ch;

    while((ch = getchar()) == '\n')
        continue;
    while(getchar() != '\n')
        continue;
    return ch;
}
float get_float(void)
{
    float input;
    char ch;

    while((scanf("%f", &input)) != 1)
    {
        while((ch = getchar()) != '\n')
            putchar(ch);
        printf(" is not a number.\nPlease enter a ");
        printf("number, such as 2.5, -1.78E8, or 3: ");
    }
    return input;
}



李阿昀 2015-11-21 20:12 发表评论
]]>
C Primer Plus W??C控制语句Q分支和跌{ 复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/11/20/428296.html李阿昀李阿昀Thu, 19 Nov 2015 16:02:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/20/428296.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/428296.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/20/428296.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/428296.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/428296.html    a.100 > 3 && 'a' >&nbs...  阅读全文

李阿昀 2015-11-20 00:02 发表评论
]]>
C Primer Plus W??C控制语句Q@?复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/11/19/428223.html李阿昀李阿昀Thu, 19 Nov 2015 06:04:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/19/428223.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/428223.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/19/428223.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/428223.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/428223.html    int quack = 2;    quack +...  阅读全文

李阿昀 2015-11-19 14:04 发表评论
]]>
C Primer Plus W??q算W、表辑ּ和语?复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/11/14/428194.html李阿昀李阿昀Sat, 14 Nov 2015 08:33:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/14/428194.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/428194.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/14/428194.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/428194.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/428194.html复习(fn)?/span>
1、假定所有的变量都是intcd。找Z面每一个变量的|(x)
a.x = (2 + 3) * 6;
b.x = (12 + 6) / 2 * 3;
c.y = x = (2 + 3) / 4;
d.y = 3 + 2 * (x = 7 / 2);
{:(x)
a.
x = 30
b.
x = 27
c.
x = 1
y = 1
d.
x = 3
y = 9
2、假定所有的变量都是intcd。找Z面每一个变量的|(x)
a.x = (int) 3.8 + 3.3;
b.x = (2 + 3) * 10.5;
c.x = 3 / 5 * 22.0;
d.x = 22.0 * 3 /5;
{:(x)
a.
x = 6
b.
x = 52
c.
x = 0
d.
x = 13
3、?zhn)怀疑下面的E序里有一些错误。?zhn)能找些错误吗Q?br />
 1 int main(void)
 2 {
 3     int i = 1,
 4     float n;
 5     printf("Watch out! Here come a bunch of fractions!\n");
 6     while(i < 30)
 7         n = 1/i;
 8         printf("%f", n);
 9     printf("That's all, folks!\n");
10     return;
11 }
{:(x)
W?行:(x)应该?include <stdio.h>?br /> W?行:(x)应该以分可不是逗号l尾?br /> W?行:(x)while语句建立一个无限@环。因为i的g持ؓ(f)1Q所以它L于30。推一下它的意思大概是要写成while(i++ < 30)?br /> W??行:(x)q样的羃排说明我们想要ɽW?行和8行组成一个代码块Q但是缺了花括号会(x)使while循环只包括第7行。应该添加花括号?br /> W?行:(x)因ؓ(f)1和i都是整数Q所以当i?旉法运的l果?x)?Q而当i为更大的数时l果?。用n = 1.0/iQ会(x)使i在进行除法运之前先转换为QҎ(gu)Q这样就?x)生?的答案?br /> W?行:(x)我们在控制语句中漏掉了换行符Q\nQ,q会(x)使数字只要可能就在一行中打印?br /> W?0行:(x)应该是return 0;?br /> 下面是一个正的版本Q?br />
 1 #include <stdio.h>
 2 int main(void)
 3 {
 4     int i = 1;
 5     float n;
 6     printf("Watch out! Here come a bunch of fractions!\n");
 7     while(i++ < 30)
 8     {
 9         n = 1.0/i;
10         printf("%f\n", n);
11     }
12     printf("That's all, folks!\n");
13     return 0;
14 }
4、这是程序清?.9的其他一U设计方法。表面上看,它用了一个scanf()函数替代了程序清?.9中的两个scanf()。但是该E序不o(h)人满意。和E序清单5.9相比Q它有什么缺点?
 1 #include <stdio.h>
 2 #define S_TO_M 60
 3 int main(void)
 4 {
 5     int sec, min, left;
 6     printf("This program converts seconds to minutes and ");
 7     printf("seconds.\n");
 8     printf("Just enter the number of seconds.\n");
 9     printf("Enter 0 to end the program.\n");
10     while(sec > 0)
11     {
12         scanf("%d", &sec);
13         min = sec / S_TO_M;
14         left = sec % S_TO_M;
15         printf("%d sec is %d min, %d sec.\n", sec, min, left);
16         printf("Next input?\n");
17     }
18     printf("Bye!\n");
19     return 0;
20 }
{:(x)Q参考课后答案)
主要问题在于判断语句Qsec是否大于0Q)和获取sec值的scanf()语句之间的关pR具体地_(d)W一ơ进行判断时Q程序还没有Z(x)来获得sec的|q样׃(x)对碰巧处在那个内存位|的一个垃圑րD行比较。一个比较笨拙的解决Ҏ(gu)是对secq行初始化,比如把它初始化ؓ(f)1Q这样就可以通过W一ơ判断。但是还有一个问题,当最后输?来停止程序时Q在循环l束之前不会(x)查secQ因?U的l果也被打印出来。更好的Ҏ(gu)是scanf()语句在进行while判断之前执行。可以通过像下面这h变程序的d部分来做到这一点:(x)
1 scanf("%d", &sec);
2 while(sec > 0)
3 {
4      min = sec / S_TO_M;
5      left = sec % S_TO_M;
6      printf("%d sec is %d min, %d sec.\n", sec, min, left);
7      printf("Next input?\n");
8      scanf("%d", &sec);
9 }
W一ơ获取输入用@环外部的scanf()Q以后就使用在@环结֤Q也卛_循环再次执行之前Q的scanf()语句。这是处理这c问题的一个常用方法?br /> 5、下面的E序打C么?
 1 #include <stdio.h>
 2 #define FORMAT "%s! C is cool!\n"
 3 int main(void)
 4 {
 5     int num = 10;
 6 
 7     printf(FORMAT, FORMAT);
 8     printf("%d\n", ++num);
 9     printf("%d\n", num++);
10     printf("%d\n", num--);
11     printf("%d\n", num);
12     return 0;
13 }
{:(x)
%s! C is cool!
! C is cool!
11
11
12
11
6、下面的E序打C么?
 1 #include <stdio.h>
 2 int main(void)
 3 {
 4     char c1, c2;
 5     int diff;
 6     float num;
 7 
 8     c1 = 'S';
 9     c2 = 'O';
10     diff = c1 - c2;
11     num = diff;
12     printf("%c%c%c: %d %3.2f\n", c1, c2,c1, diff, num);
13     return 0;
14 }
{:(x)
SOS: 4 4.00
7、下面的E序打印出什么?
 1 #include <stdio.h>
 2 #define TEN 10
 3 int main(void)
 4 {
 5     int n = 0;
 6     while(n++ < TEN)
 7         printf("%5d", n);
 8     printf("\n");
 9     return 0;
10 }
{:(x)
   1   2   3   4   5   6   7   8   9   10Q?span style="background-color: yellow;">注意Q每个数字占?列的宽度Q? 
8、修改上一个程序,让它打印从a到g的字母?br /> {:(x)
 1 #include <stdio.h>
 2 #define CHARACTER 'g'
 3 int main(void)
 4 {
 5     char ch = 'a' - 1;
 6     while(ch++ < CHARACTER)
 7         printf("%3c", ch);
 8     printf("\n");
 9     return 0;
10 }
9、如果下面的片段是一个完整程序的一部分Q它们将打印Z么?
a.
1 int x = 0;
2 while(++x < 3)
3    printf("%4d", x);
b.(注意QɽW二个printf()语句~进q不能它成为while循环的一部分。因此它只是在while循环l束之后被调用一ơ,我看成一个代码块?
1 int x = 100;
2 
3 while(x++ < 103)
4    printf("%4d\n", x);
5    printf("%4d\n", x);
c.
1 char ch = 's';
2 
3 while(ch < 'w')
4 {
5     printf("%c", ch);
6     ch++;
7 }
8 printf("%c\n", ch);
{:(x)
a.
   1   2
b.
 101
 102
 103
 104
c.
stuvw
10、下面的E序打C么?
 1 #define MESG "COMPUTER BYTES DOG"
 2 #include <stdio.h>
 3 int main(void)
 4 {
 5     int n = 0;
 6 
 7     while(n < 5)
 8         printf("%s\n", MESG);
 9         n++;
10     printf("That's all.\n");
11     return 0;
12 }
{:(x)
q是一个构造有~陷的程序。因为while语句没有使用花括P只有printf()语句作ؓ(f)循环的一部分Q所以程序无休止地打印消息COMPUTER BYTES DOG直到(zhn)强行关闭程序ؓ(f)止?br /> 11、构造完成下面功能(或者用一个术语来_(d)有下面的副作用)的语句:(x)
a.把变量x的值增?0
b.把变量x的值增?
c.?span>a与b之和的两倍赋lc
d.a与两倍的b之和赋给c
{:(x)
a.x = x + 10;
b.x++; or ++x; or x = x + 1;
c.c = (a + b) * 2;
d.c = a + 2 * b;
12、构造具有下面功能的语句Q?br />a.把变量x的值减1
b.把n除以k所得的余数赋给m
c.用b减去a的差去除qQƈ结果赋lp
d.用a与b的和除以c与d的乘U,q将l果赋给x
{:(x)
a.x--; or --x; or x = x - 1;
b.m = n % k;
c.p = q / (b - a);
d.x = (a + b) / (c * d);
~程l习(fn)
1?br />
 1 #include <stdio.h>
 2 const int PARAM = 60;
 3 int main(void)
 4 {
 5     int min, hour, left;
 6 
 7     printf("Convert minutes to hours and minutes!\n");
 8     printf("Enter the number of minutes (<=0 to quit):\n");
 9     scanf("%d", &min);
10     while(min > 0)
11     {
12         hour = min / PARAM;
13         left = min % PARAM;
14         printf("%d minutes is %d hours, %d minutes.\n", min, hour, left);
15         printf("Enter next value (<=0 to quit): \n");
16         scanf("%d", &min);
17     }
18     printf("Done!\n");
19     return 0;
20 }
2?br />
 1 #include <stdio.h>
 2 int main(void)
 3 {
 4     int number, maxnum;
 5     printf("Please enter a int number:\n");
 6     scanf("%d", &number);
 7     maxnum = number + 10;
 8     while(number <= maxnum)
 9     {
10         printf("%5d", number++);
11     }
12     printf("\n");
13     return 0;
14 }
3、(与题?cMQ?/span>
 1  #include <stdio.h>
 2  const int PARAM = 7;
 3  int main(void)
 4  {
 5      int day, week, left;
 6 
 7      printf("Convert days to weeks and days!\n");
 8      printf("Enter the number of days (<=0 to quit):\n");
 9      scanf("%d", &day);
10      while(day > 0)
11      {
12          week = day / PARAM;
13          left = day % PARAM;
14          printf("%d days are %d weeks, %d days.\n", day, week, left);
15          printf("Enter next value (<=0 to quit): \n");
16          scanf("%d", &day);
17      }
18      printf("Done!\n");
19      return 0;
20 }
4?br />
 1  #include <stdio.h>
 2  #define CM_PER_INCH 0.3937
 3  #define FEET_PER_INCH 12
 4  int main(void)
 5  {
 6      float cm, inch, left;
 7      int feet;
 8 
 9      printf("Enter a height in centimeters: ");
10      scanf("%f", &cm);
11      while(cm > 0)
12      {
13          inch = cm * CM_PER_INCH;
14          feet = inch / FEET_PER_INCH;
15          left = (inch / FEET_PER_INCH - feet) * FEET_PER_INCH ;
16          printf("%.1f cm = %d feet, %.1f inches.\n", cm, feet, left);
17          printf("Enter a height in centimeters (<=0 to quit): ");
18          scanf("%f", &cm);
19      }
20      printf("bye\n");
21      return 0;
22 }
5?br />
 1 #include <stdio.h>
 2 int main(void)
 3 {
 4     int count, sum, limit;
 5     count = 0;
 6     sum = 0;
 7 
 8     printf("Please enter a limit number: ");
 9     scanf("%d", &limit);
10     while(count++ < limit)
11     {
12         sum = sum + count;
13     }
14     printf("sum = %d\n", sum);
15     return 0;
16 }
6?br />
 1 #include <stdio.h>
 2 int main(void)
 3 {
 4     int count, sum, limit;
 5     count = 0;
 6     sum = 0;
 7 
 8     printf("Please enter a limit number: ");
 9     scanf("%d", &limit);
10     while(count++ < limit)
11     {
12         sum = sum + count * count;
13     }
14     printf("sum = %d\n", sum);
15     return 0;
16 }
7?br />
 1 #include <stdio.h>
 2 float cube(float num);
 3 int main(void)
 4 {
 5     float number;
 6     printf("Please enter a number: ");
 7     scanf("%f", &number);
 8     printf("The cube of the %.2f is %.2f", number, cube(number));
 9     return 0;
10 }
11 float cube(float num)
12 {
13     return num * num * num;
14 }
8、(注意Q我用到?lt;string.h>头文件中?/span>getchar()函数Q还是用目前的知识弄不出来,啊!Q?br />
 1 #include <stdio.h>
 2 #include <string.h>
 3 const float ONE_PARAM = 1.8;
 4 const float TWO_PARAM = 32.0;
 5 const float THREE_PARAM = 273.16;
 6 void temperatures(double fahrenheit);
 7 int main(void)
 8 {
 9     float number;
10     while(1==1)
11     {
12         printf("Please again enter a fahrenheit's temperature: ");
13         scanf("%f", &number);
14         if(getchar() == 'q')
15         {
16             break;
17         }
18         temperatures(number);
19     }
20     printf("Done!\n");
21     return 0;
22 }
23 void temperatures(double fahrenheit)
24 {
25     float celsius, kelvin;
26     celsius = ONE_PARAM * fahrenheit + 32.0;
27     kelvin = celsius + 273.16;
28     printf("fahrenheit is %.2f, celsius is %.2f, kelvin is %.2f.\n", fahrenheit, celsius, kelvin);
29 }
今天看到W??循环部分Q原来可以这样做Q是我读书太不用心了Q?br />
 1  #include <stdio.h>
 2  #include <string.h>
 3  const float ONE_PARAM = 1.8;
 4  const float TWO_PARAM = 32.0;
 5  const float THREE_PARAM = 273.16;
 6  void temperatures(double fahrenheit);
 7  int main(void)
 8  {
 9     float number;
10 
11     printf("Please again enter a fahrenheit's temperature: ");
12     while(scanf("%f", &number) == 1)
13     {
14         temperatures(number);
15         printf("Please again enter a fahrenheit's temperature: ");
16     }
17     printf("Done!\n");
18     return 0;
19 }
20 void temperatures(double fahrenheit)
21 {
22     float celsius, kelvin;
23     celsius = ONE_PARAM * fahrenheit + 32.0;
24     kelvin = celsius + 273.16;
25     printf("fahrenheit is %.2f, celsius is %.2f, kelvin is %.2f.\n", fahrenheit, celsius, kelvin);
26 }


李阿昀 2015-11-14 16:33 发表评论
]]>
C Primer Plus W??字符串和格式化输?输出 复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/11/14/428191.html李阿昀李阿昀Fri, 13 Nov 2015 18:01:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/14/428191.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/428191.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/11/14/428191.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/428191.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/428191.html复习(fn)?/span>
1、再ơ运行程序清?.1Q但是在要求(zhn)输入名字时Q请输入(zhn)的名字和姓氏。发生了什么?Z么?
{:(x)
 1 #include <stdio.h>
 2 #include <string.h>
 3 #define DENSITY 62.4
 4 int main(void)
 5 {
 6     float weight, volume;
 7     int size, letters;
 8     char name[40]; // name是一个有40个字W的数组
 9 
10     printf("Hi! What's your first name?\n");
11     scanf("%s", name);
12     printf("%s, what's your weight in pounds?\n", name);
13     scanf("%f", &weight);
14     size = sizeof(name);
15     letters = strlen(name);
16     volume = weight / DENSITY;
17     printf("Well, %s, your volume is %2.2f cubic feet.\n", name, volume);
18     printf("Also, your first name has %d letters, \n", letters);
19     printf("and we have %d bytes to store it in.\n", size);
20     return 0;
21 }
如果输入名字和姓氏,?x)输出如下结果?x)
Hi! What's your first name?
Li Ayun
Li, what's your weight in pounds?
Well, Li, your volume is 0.00 cubic feet.
Also, your first name has 2 letters,
and we have 40 bytes to store it in.
原因Q(参考课后答案)E序不能正常工作。第一个scanf()语句只是d(zhn)的名而没有读入?zhn)的姓Q?zhn)的姓依然存储在输?#8220;~冲?#8221;Q缓冲区只是一块用来存放输入的临时存储区域Q中。当下一个scanf()语句惌d(zhn)的体重Ӟ它从上次dl束的地方开始,q样p图把(zhn)的姓作Z重来d。这?x)scanf()p|。一斚wQ如果?zhn)对姓名请求做出像Li 123q样的响应,E序?x)?23作ؓ(f)(zhn)的体重Q虽然?zhn)是在E序h体重之前输入123的?br />2、假定下列每个示例都是某个完整程序的一部分。它们的打印l果分别是什么?
a.printf("He sold the painting for $%2.2f.\n", 2.345e2);
b.printf("%c%c%c\n", 'H', 105, '\41');
c.#define Q "His Hamlet was funny without being vulgar. "
         printf("%s\nhas %d characters.\n", Q, strlen(Q));
d.printf("Is %2.2e the same as %2.2f?\n", 1201.0, 1201.0);
{:(x)
a.He sold the painting for $234.50.
b.Hi!
c.His Hamlet was funny without being vulgar. Q注意,与课后答案不一P是因为细看题目的话,此句末尾有一个空|strlen()函数输出字符串中字符Q包括空格和标点W号Q的准确数目Q?/span>
   has 43 characters.
d.Is 1.20e+003 the same as 1201.00?
3、在问题2c中,应进行哪些修改以使字W串Q引在双引号中输出Q?br />{:(x)
使用\"。示例如下:(x)
printf("\"%s\"\nhas %d characters.\n", Q, strlen(Q));
4、找Z列程序中的错误?br />
 1 define B booboo
 2 define X 10
 3 main(int)
 4 {
 5     int age;
 6     char name;
 7 
 8     printf("Please enter your first name. ");
 9     scanf("%s", name);
10     printf("All right, %c, what's your age?\n", name);
11     scanf("%f", age);
12     xp = age + X;
13     printf("That's a %s! You must be at least %d.\n", B, xp);
14     rerun 0;
15 }
{:(x)
下面是一个正的版本Q?br />
 1 #include <stdio.h>
 2 #include <string.h>
 3 #define B "booboo"
 4 #define X 10
 5 int main(void)
 6 {
 7     int age;
 8     int xp;
 9 
10     char name[40];
11 
12     printf("Please enter your first name. \n");
13     scanf("%s", name);
14     printf("All right, %s, what's your age?\n", name);
15     scanf("%d", &age);
16     xp = age + X;
17     printf("That's a %s! You must be at least %d.\n", B, xp);
18     return 0;
19 }
5、假设一个程序这样开始:(x)
1 #define BOOK "War and Peace"
2 int main(void)
3 {
4     float cost = 12.99;
5     float precent = 80.0;
h造一个printf()语句Q用BOOK、cost和percent打印下列内容Q?br />
This copy of "War and Peace" sells for $12.99.
That is 80% of list.
{:(x)
printf("This copy of \"%s\" sells for $%.2f.\nThat is %.0f%% of list.", BOOK, cost, percent);
6、?zhn)会(x)用什么{换说明来打印下列各项内容Q?br />a.一个字D宽度等于数字位数的十进制整数?br />b.一个Ş?A、字D宽度ؓ(f)4的十六进制整数?br />c.一个Ş?32.346、字D宽度ؓ(f)10的QҎ(gu)?br />d.一个Ş?.33e+002、字D宽度ؓ(f)12的QҎ(gu)?br />e.一个字D宽度ؓ(f)30、左寚w的字W串?br />{:(x)
a.%d
b.%4X
c.%10.3f
d.%12.2e
e.%-30s
对于点数来_(d)字段宽度包含了小数点双的数字的数目
7、?zhn)会(x)用哪个{换说明来打印下列各项内容Q?br />a.一个字D宽度ؓ(f)15的unsigned long整数
b.一个Ş?x8a、字D宽度ؓ(f)4的十六进制整?br />c.一个Ş?.33E+02、字D宽度ؓ(f)12、左寚w的QҎ(gu)
d.一个Ş?232.346、字D宽度ؓ(f)10的QҎ(gu)
e.一个字W串的前8个字W,字段宽度?字符
{:(x)
a.%15lu
b.%#4xQ?span style="background-color: yellow;">字段宽度应放?和x之间Q?/span>
c.%-12.2EQ?-"修饰Wɋ点数左寚w输出Q?br />d.%+10.3f
e.%-8.8sQ?-"修饰W文本左对齐输出)
8、?zhn)会(x)用什么{换说明来打印下列各项内容Q?br />a.一个字D宽度ؓ(f)6、最有4位数字的十进制整?br />b.一个字D宽度在参数列表中给定的八进制整?br />c.一个字D宽度ؓ(f)2的字W?br />d.一个Ş?3.13、字D宽度等于数字中字符个数的QҎ(gu)
e.一个字W串的前5个字W,字段宽度?、左寚w
{:(x)
a.%6.4d
b.%*oQ?span style="background-color: yellow;">此处为小写字母oQ而不是数?Q?/span>
c.%2c
d.%+.2f
e.%-7.5s
9、ؓ(f)下列每个输入行提供一个对其进行读取的scanf()语句Qƈ声明语句中用到的所有变量或数组?br />a.101
b.22.32 8.34E-09
c.linguini
d.catch 22
e.catch 22(但是跌catch)
{:(x)
a.
1 int num;
2 scanf("%d", &num);
b.
1 float kgs, share;
2 scanf("%f%f", &kgs, &share);
c.
1 char str[40];
2 scanf("%s", str);
d.
1 char str[40];
2 int number;
3 scanf("%s %d", str,&number);
e.
1 char str[40];
2 int number;
3 scanf("%s %d", str, &number);
10、什么是I白字符Q?br />{:(x)
I白字符包括I格、制表符和换行符。C使用I白字符分隔各个语言W号Qscanf()使用I白字符分隔盔R的输入项?br />11、假设?zhn)惛_E序中用圆括号代替花括受以下方法可以吗Q?br />#define ( {
#define ) }
{:(x)
?x)发生替换。但不幸的是Q预处理器不能区别哪些圆括号应该被替换成花括P哪些圆括号不应该被替换成花括受因此:(x)
1 #include <stdio.h>
2 #define ( {
3 #define ) }
4 int main(void)
5 (
6     printf("Hello World!\n");
7     return 0;
8 )
?x)变为?x)
1 #include <stdio.h>
2 int main{void}
3 {
4     printf{"Hello World!\n"};
5     return 0;
6 }
所有圆括号都要替换括号?br />~程l习(fn)
1?br />
 1 #include <stdio.h>
 2 int main(void)
 3 {
 4     char name[40]; // 名字
 5     char surname[40]; // 姓氏
 6 
 7     printf("Please enter your name and surname: \n");
 8     scanf("%s%s", name, surname);
 9     printf("%s,%s", surname, name);
10     return 0;
11 }
2?br />
 1 #include <stdio.h>
 2 #include <string.h>
 3 int main(void)
 4 {
 5     char name[40]; // 名字
 6 
 7     printf("Please enter your name: \n");
 8     scanf("%s", name);
 9     printf("\"%s\"\n", name);
10     printf("\"%20s\"\n", name);
11     printf("\"%-20s\"\n", name);
12     printf("%*s\n", strlen(name)+3, name);
13     return 0;
14 }
3?br />
 1 #include <stdio.h>
 2 int main(void)
 3 {
 4     float number;
 5 
 6     printf("Please enter a float number: \n");
 7     scanf("%f", &number);
 8     printf("The input is %.1f or %.1e\n", number, number);
 9     printf("The input is %+.3f or %.3E\n", number, number);
10     return 0;
11 }
4?br />
 1 #include <stdio.h>
 2 int main(void)
 3 {
 4     /* 以厘cؓ(f)单位输入w高Qƈ以米为单位进行显C?nbsp;*/
 5     float weight;
 6     char name[40];
 7 
 8     printf("Please enter your weight(cm): \n");
 9     scanf("%f", &weight);
10     printf("Please enter your name: \n");
11     scanf("%s", name);
12     printf("%s, you are %.2f meter tall\n", name, weight/100);
13     return 0;
14 }
5?br />
 1 #include <stdio.h>
 2 #include <string.h>
 3 int main(void)
 4 {
 5     char name[40]; // 名字
 6     char surname[40]; // 姓氏
 7 
 8     printf("Please enter your name: \n");
 9     scanf("%s", name);
10     printf("Please enter your surname: \n");
11     scanf("%s", surname);
12     printf("%10s %10s\n", surname, name);
13     printf("%10d %10d\n", strlen(surname), strlen(name));
14     printf("%-10s %-10s\n", surname, name);
15     printf("%-10d %-10d\n", strlen(surname), strlen(name));
16     return 0;
17 }
l果为:(x)Q看h有一Ҏ(gu)啊Q!Q)
Please enter your name:
Ayun
Please enter your surname:
li
        li       Ayun
         2           4
li         Ayun
2         4
6?/div>
 1 #include <stdio.h>
 2 #include <float.h>
 3 int main(void)
 4 {
 5     double dblnum = 1.0/3.0;
 6     float fltnum = 1.0/3.0;
 7 
 8     printf("%.4f\n", dblnum);
 9     printf("%.12f\n", dblnum);
10     printf("%.16f\n", dblnum);
11     printf("%.4f\n", fltnum);
12     printf("%.12f\n", fltnum);
13     printf("%.16f\n", fltnum);
14     printf("double precision = %d digits\n", DBL_DIG);
15     printf("float precision = %d digits\n", FLT_DIG);
16     return 0;
17 }
7、(定义点cd的时候是使用floatQ还是double好?Q?Q?/span>
 1 #include <stdio.h>
 2 #define LITRE 3.785
 3 #define KM 1.609
 4 int main(void)
 5 {
 6     float mile; // 英里?/span>
 7     float gallon; // 加仑?/span>
 8 
 9     printf("Please enter your mile: \n");
10     scanf("%f", &mile);
11     printf("Please enter your gallon: \n");
12     scanf("%f", &gallon);
13     printf("Miles per gallon of gasoline: %.1f\n", mile/gallon);
14     printf("Liters per 100 kilometers: %.1f\n", gallon*LITRE*100/(mile*KM));
15     return 0;
16 }


李阿昀 2015-11-14 02:01 发表评论
]]>C Primer Plus W??数据和C 复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/10/31/428003.html李阿昀李阿昀Sat, 31 Oct 2015 14:22:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/10/31/428003.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/428003.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/10/31/428003.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/428003.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/428003.html复习(fn)?br />1、对下面的各U数据用合适的数据cdQ?br />     a.East Simpleton的h?br />     b.DVDq的h(hun)?br />     c.本章出现ơ数最多的字母
     d.q个字母出现的次?br />{:(x)a.intcdQ可以是short、unsigned或unsigned shortQh口数是一个整数?br />      b.floatcdQh(hun)g太可能正好是一个整敎ͼ(zhn)也可以使用doubleQ但实际上ƈ不需要那么高的精度)?br />      c.charcd?br />      d.intcdQ可以是unsigned?br />2、需要用longcd变量代替intcd变量的原因是什么?
{:(x)一个原因是在?zhn)的系l中long可以容纳比intcd更大的数Q一个原因是如果(zhn)确实需要处理更大的|那么使用一U在所有系l上都能保证臛_?2位的cd?x)ɽE序的可UL性更好?br />3、获得一?2位的有符h敎ͼ可以使用哪些可移植的数据cdQ每U选择的原因是什么?
{:(x)要获得正好是32位的敎ͼ(zhn)可以用int32_tQ如果在(zhn)的pȝ上有q一定义的话Q。要获得可存储至?2位的最类型,可以使用int_least32_t。如果要?2位的cd中获得提供最快计速度的类型,可以选择int_fast32_t。(参?/span>3.4.5  可移植的cdQinttypes.hQ理解的不是很清楚!Q!Q?br />4、指Z列常量的cd和意义(如果有的话)Q?br />     a.'\b'
     b.1066
     c.99.44
     d.0XAA
     e.2.0e30
{:(x)a.char帔RQ但以intcd存储Q?br />      b.int帔R
      c.double帔R
      d.unsigned int帔RQ十六进制格?br />      e.double帔R
5、Dottie Cawm写的下面q个E序中有很多错误Q找些错误?br />
1 include <stdio.h>
2 main
3 (
4     float g; h;
5     float tax, rate;
6 
7     g = e21;
8     tax = rate * g;
9 )
{:(x)W?行:(x)应该?/span>#include <stdio.h>
      W?行:(x)应该?/span>int main(void)
      W?行:(x)使用{Q而不?
      W?行:(x)在g和h之间应该是逗号而不是分?br />      W?行:(x)无错?br />      W?行:(x)Q空行)无错?br />      W?行:(x)在e之前应该臛_有一个数字,.1e21?.e21都是正确的,管q个数有点大?br />      W?行:(x)无错误,臛_在语法上没有
      W?行:(x)使用}Q而不?
~少的行Q首先,rate没有被赋倹{其ơ,变量h从来没有被用。而且E序永远不会(x)把它的计结果通知l?zhn)。这些错误都不会(x)LE序的运行(管可能?x)向?zhn)出CZ个警告以说明变量没有被用)Q但是它们确实减׃E序本来׃多的功能。而且在结֤应该有一个return语句?br />   下面是正版本之一Q?nbsp; 
 
 1 #include <stdio.h>
 2
 int main(void)
 3 {
 4     float g, h;
 5     float tax, rate;
 6     rate = 0.08;
 7     g = 1.0e5;
 8 
 9     tax = rate * g;
10     h = g + tax;
11     printf("You owe $%f plus $%f in taxes for a total of $%f.\n", g, tax, h);
12     return 0;
13 }
6、指Z表中各常量的数据cdQ在声明语句中用的数据cdQ及(qing)其在printf()中的格式说明W?br />
          帔R         cd        说明W?    

12

0x3
  'C'  
  2.34E07  
 '\040'   
 7.0   
 6L   
 6.0f   













{:(x)
          帔R           cd           说明W?    

12int%d

0x3unsigned int%#x
  'C'char %c 
  2.34E07double  %f
 '\040' char  %c
 7.0 double  %f
 6L long  %ld
 6.0f float %e 












7?/span>
指出下表中各帔R的数据类型(在声明语句中使用的数据类型)?qing)其在printf()中的格式说明W,假设intcd?6位长?br />
          帔R         cd        说明W?    

012

2.9e05L
  's'  
  100000  
 '\n'   
 20.0f   
 0x44   
















{:(x)
          帔R           cd           说明W?    

012int%#0

2.9e05Llong double%Le
  's'char %c 
  100000long %ld 
 '\n' char%c 
 20.0f float %f 
 0x44 unsigned int %#x 
















8、假设一个程序开始处有如下的声明Q?br />
1 int imate = 2;
2 long shot = 53456;
3 char grade = 'A';
4 float log = 2.71828;
在下面printf()语句中添上合适的cd说明W:(x)
1 printf("The odds against the %___ were %___ to 1.\n", imate, shot);
2 printf("A score of %___ is not an %___ grade.\n", log, grade);
{:(x)
1 printf("The odds against the %d were %ld to 1.\n", imate, shot);
2 printf("A score of %f is not an %c grade.\n", log, grade);
9、假设ch为charcd变量。用{义序列、十q制倹{八q制字符帔R以及(qing)十六q制字符帔R{方法将其赋gؓ(f)回RW(假设使用ASCII~码Q?br />{:(x)
1 char ch = '\r';
2 char ch = 13;
3 char ch = '\015';
4 char ch = '\xd';
10、改正下面程序(在C?表示除法Q?br />
1 void main(int) / this progarm is perfect /
2 {
3    cows, legs integer;
4    printf("How many cow legs did you count?\n);
5    scanf("%c", legs);
6    cows = legs / 4;
7    printf("That implies there are %f cows.\n", cows)
8 }
{:(x)
 1 #include <stdio.h>
 2 int main(void/* this progarm is perfect */
 3 {
 4    int cows, legs;
 5    printf("How many cow legs did you count?\n");
 6    scanf("%d", &legs);
 7    cows = legs / 4;
 8    printf("That implies there are %d cows.\n", cows);
 9    return 0;
10 }
11、指Z列{义字W的含义Q?br />
1 a.\n
2 b.\\
3 c.\"
4 d.\t
{:(x)a.换行字符
      b.反斜U字W?br />      c.双引号字W?br />      d.制表字符
~程l习(fn)Q如有错误,希望指正Q!Q)
1?br />
 1 /* 整数上溢*/
 2 #include <stdio.h>
 3 int main(void)
 4 {
 5     int i = 2147483647;
 6     unsigned int j = 4294967295;
 7 
 8     /*
 9         无符h数j像一个汽车里E指CQŞ容的太好了,可参考《计机U学D》第3?nbsp;数据存储Q有图)Q?br />10        当达到最大值时Q它?yu)溢出到起始炏V整数i也是同样。它们的主要区别是unsigned int变量j的v始点?Q正像里E?br />11        指示表那PQ而int变量i的v始点则是-2147483648?#8212;—参考《C Primer Plus?br />12     */
13     printf("%d %d %d\n", i, i+1, i+2);
14     printf("%u %u %u\n", j, j+1, j+2);
15     return 0;
16 }
q行l果Q?br />
2147483647 -2147483648 -2147483647
4294967295 0 1
点数的上溢和下溢?Q?Q?span style="background-color: yellow;">理解的不是很清楚Q回头再来写Q?/span>
2?br />
1 #include <stdio.h>
2 int main(void)
3 {
4     int asc;
5     printf("Please enter an ASCII value: ");
6     scanf("%d", &asc);
7     printf("The code is %c.\n", asc);
8     return 0;
9 }
3?br />
1 #include <stdio.h>
2 int main(void)
3 {
4     printf("\aStartled by the sudden sound, Sally shouted, ");
5     printf("\"By the Great Pumpkin,what was that!\"\n");
6     return 0;
7 }
4?br />
1 #include <stdio.h>
2 int main(void)
3 {
4     float number;
5     printf("Please enter a float value: ");
6     scanf("%f", &number);
7     printf("The input is %f or %e", number, number);
8     return 0;
9 }
5?br />
1 #include <stdio.h>
2 int main(void)
3 {
4     int age;
5     printf("Please enter your age: ");
6     scanf("%d", &age);
7     printf("Your age has %e s", age*3.156e7);
8     return 0;
9 }
6?br />
1 #include <stdio.h>
2 int main(void)
3 {
4     int num; // 夸脱数应该ؓ(f)整数吧!Q?/span>
5     printf("Please enter water: ");
6     scanf("%d", &num);
7     printf("The water has %e ", num*950/3.0e-23);
8     return 0;
9 }
7?br />
1 #include <stdio.h>
2 int main(void)
3 {
4     float height;
5     printf("Please enter your height: ");
6     scanf("%f", &height);
7     printf("Your height is %.2f cm.\n", height*2.54);
8     return 0;
9 }


李阿昀 2015-10-31 22:22 发表评论
]]>
C Primer Plus W?? C语言概述 复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/10/28/427955.html李阿昀李阿昀Wed, 28 Oct 2015 12:22:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/10/28/427955.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/427955.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/10/28/427955.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/427955.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/427955.html 复习(fn)?/span>
1、如何称呼CE序的基本模块?
{:(x)它们被称为函数?br /> 2、什么是语法错误Q给出它的一个英语例子和C语言例子?nbsp;
{:(x)C的语法错误是指把正确的CW号攑֜了错误的位置。这是英语中的一个例子:(x)"Me speak English good."Q这是C语言的一个例子:(x)printf "Where are the parentheses?";
3、什么是语义错误Q给出它的一个英语例子和C语言例子?br /> {:(x)语义错误是在意思上的错误。这是英语中的一个例子:(x)"The sentence is excellent Italian."Q这是C语言中的一个例子:(x)thrice_n = 3 + n;
4、Indiana Sloth 已经~好了下面的E序Qƈ惛_求你的意见。请帮助他评定?br />
1 include studio.h
int main{void/*该程序可昄Zq中有多周/*
3 (
4 int s

6 s: = 56;
7 print(There are s weeks in a year.);
8 return 0;
{:(x)W?行:(x)以一?开始,拼写出文件名stdio.hQ然后把文g名放在一对尖括号中?br />     W?行:(x)使用()Q而不是用{}Q?/来结束注释,而不是?*?br />     W?行:(x)使用{Q而不??br />     W?行:(x)使用分号来结束语句?br />     W?行:(x)Indiana使这一行(I白行)正确Q?br />     W?行:(x)使用=Q而不是用:(x)=q行赋|昄QIndiana 了解一些PascalQ。每q有52周而不?6周?br />     W?行:(x)应该?span style="font-size: 13px; background-color: #eeeeee;">printf(
"There are %d weeks in a year.\n",s);
     W?行:(x)源程序没有第9行,但是应该有,它应该包含一个结束花括号}?br />在进行这些修改之后,代码如下Q?br />
1 #include<stdio.h>
int main(void/*该程序可昄Zq中有多周/*
3 {
4 int s;

6 s = 52;
7 printf("There are %d weeks in a year.\n",s);
8 return 0;
9 }
5、假设下面的每一个例子都是某个完整程序的一部分Q它们每个将输出什么结果?
a.printf("Baa Baa Black Sheep.");
   printf("Have you any wool?\n");
b.printf("Begone!\n0 creature of lard!");
c.printf("What?\nNo/nBonzo?\n");
d.int num;

  num = 2;
  printf("%d + %d = %d",num,num,num + num);
{:(x)a.Baa Baa Black Sheep.Have you any wool?Q注意:(x)在句号之后没有空根{)
     b.Begone!
        0 creature of lard!Q注意光标仍留在W?行结束处。)
     c.What?
        No/nBonzo?Q注意斜U符?#8221;/“没有反斜U符?#8221;\“所h的作用,它只是简单地作ؓ(f)斜线W号被打印出来。)
     d.2 + 2 = 4
6、下面哪几个是C的关键字Qmain,int,function,char,=
{:(x)int,charQ注?span style="color: #ff6600;">main只是一个函数名Q函数是C中的一个技术术?/span>?是一个运符Q?br />7、如何以下面的格式输出words和lines的|(x)"There were 3020 words and 350 lines"Q这里,3020?50代表两个变量的倹{?br />{:(x) 
 1 #include <stdio.h>
 2
 int main(void)
 3 {
 4     int num1,num2;
 5     num1 = 3020;
 6     num2 = 350;
 7 
 8     printf("There were %d words and %d lines\n",num1,num2);
 9     return 0;
10 }
8、考虑下面的程序:(x)
 1 #include <stdio.h>
 2 int main(void)
 3 {
 4     int a, b;
 5 
 6     a = 5;
 7     b = 2; /*W??/span>*/
 8     b = a; /*W??/span>*/
 9     a = b; /*W??/span>*/
10     printf("%d %d\n", b, a);
11     return 0;
12 }
请问在第7行、第8行和W?行之后程序的状态分别是什么?
{:(x)W?行之后,a?Qb?。第8行之后,a?Qb?。第9行之后,a?Qb??br />~程l习(fn)Q新手初学,仅供参考!Q!Q?/span>
1?br />
1 #include <stdio.h>
2 int main(void)
3 {
4     printf("Li Ayun\n");
5     printf("Li\nAyun\n");
6     printf("Li ");
7     printf("Ayun\n");
8     return 0;
9 }
2?br />
1 #include <stdio.h>
2 int main(void)
3 {
4     printf("My name is Li Ayun!\n");
5     printf("I live in BeiJing now!\n");
6     return 0;
7 }
3?br />
1 #include <stdio.h>
2 int main(void)
3 {
4     int age;
5     age = 23;
6     printf("age = %d, days = %d\n", age, age * 365);
7     return 0;
8 }
4?br />
 1 #include <stdio.h>
 2 void show(void);
 3 void end(void);
 4 int main(void)
 5 {
 6     show();
 7     show();
 8     show();
 9     end();
10     return 0;
11 }
12 void show(void)
13 {
14    printf("For he's a jolly good fellow!\n");
15 }
16 void end(void)
17 {
18     printf("Which nobody can deny!\n");
19 }
5?br />
1 #include <stdio.h>
2 int main(void)
3 {
4     int toes;
5     toes = 10;
6 
7     printf("toes = %d\ntoes + toes = %d\ntoes * toes = %d", toes, toes + toes, toes * toes);
8     return 0;
9 }
6?br />
 1 #include <stdio.h>
 2 void showSmile(void);
 3 int main(void)
 4 {
 5     showSmile();
 6     showSmile();
 7     showSmile();
 8     printf("\n");
 9     showSmile();
10     showSmile();
11     printf("\n");
12     showSmile();
13     return 0;
14 }
15 void showSmile(void)
16 {
17     printf("Smile!");
18 }
7?br />
 1 #include <stdio.h>
 2 void one_three(void);
 3 void two(void);
 4 int main(void)
 5 {
 6     printf("starting now:\n");
 7     one_three();
 8     two();
 9     printf("done!");
10     return 0;
11 }
12 void one_three(void)
13 {
14     printf("one\n");
15 }
16 void two(void)
17 {
18     printf("two\nthree\n");
19 }



李阿昀 2015-10-28 20:22 发表评论
]]>
C Primer Plus W?? 概览 复习(fn)题与~程l习(fn)http://www.aygfsteel.com/BeautifulMan/archive/2015/10/28/427954.html李阿昀李阿昀Wed, 28 Oct 2015 11:39:00 GMThttp://www.aygfsteel.com/BeautifulMan/archive/2015/10/28/427954.htmlhttp://www.aygfsteel.com/BeautifulMan/comments/427954.htmlhttp://www.aygfsteel.com/BeautifulMan/archive/2015/10/28/427954.html#Feedback0http://www.aygfsteel.com/BeautifulMan/comments/commentRss/427954.htmlhttp://www.aygfsteel.com/BeautifulMan/services/trackbacks/427954.html   复习(fn)?/span>
   1、就~程而言Q可UL性表CZ么?
   {:(x)可移植性意味着在一个系l上~写的CE序l过很少改动或不l修改就可以在其他系l上q行。如果修Ҏ(gu)必要的,则通常只须改变伴随ȝ序的一个头文gQheaderQ中的几内容即可?br />    2、解释源代码文g、目标代码文件和可执行文件之间的区别?br />    {:(x)源代码文件中包含着E序员用Q何语a~写的代码。目标代码文件包含着机器语言代码Q它q不需要是完整的程序代码。可执行文g包含着l成可执行程序的全部机器语言代码?br />    3、编E的7个主要步骤是什么?
   {:(x)W?步:(x)定义E序目标
         W?步:(x)设计E序
         W?步:(x)~写代码
         W?步:(x)~译
         W?步:(x)q行E序
         W?步:(x)调试 
         W?步:(x)l护和修改程?br />   4、编译器的Q务是什么?
   {:(x)~译器把源代码(例如Q用C语言写成的代码)转换成机器语a代码Q也U?span style="color: #993366;">对象代码?/span>
   5、链接器的Q务是什么?
   {:(x)链接器把多个来源Q例如,已编写的源代码、库代码和启动代码)的目标代码连接成一个单独的可执行程序?br />   ~程l习(fn)
   1?/span>
 1 #include <stdio.h>
 2
 int main(void)
 3 {
 4     float feet,cm;
 5 
 6     printf("Please enter your feet:");
 7     scanf("%f",&feet);
 8     cm = feet * 2.54;
 9     printf("So you have %.2f cm!\n",cm);
10    return 0;
11 }


李阿昀 2015-10-28 19:39 发表评论
]]>
վ֩ģ壺 մ| | Ž| ½| ˮ| ն| ˷| | | Դ| ¤| ͨ| | | | | | | ³ƶ| ϳ| | Ȩ| פ| Ҧ| | Ȫ| Ӵ| | Ӫɽ| | ¬| ٳ| | ʡ| | | ͨɽ| Ƽ| ƽ| | ̨|