搜索
查看: 745|回复: 0
打印 上一主题 下一主题

【第四章第4节】动手试一试题解

[复制链接]
跳转到指定楼层
楼主
发表于 2015-8-31 01:07:18 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 sujx 于 2015-8-31 01:08 编辑

1、求1~100所有偶数之和[mw_shl_code=c,true]#include <stdio.h>
#include <stdlib.h>
int main()
{
        int a,i;
    a=0;
    i=2;
    while(i<=100)
    {
                a=a+i;
        i=i+2;
    }
    printf("%d\n",a);
        system("pause");
        return 0;
}[/mw_shl_code]
2、输入一个整数n(1<=n<=9),求n的阶乘(未对n的大小做判断)
[mw_shl_code=c,true]#include <stdio.h>
#include <stdlib.h>
int main()
{
        int n,i;
    i=n;
    printf("Plese input a number (1<=n<=9): \n");
    scanf("%d",&n);
        if(n>=1&&n<=9)
                {
                        n=n*i;
            i--;
        }
        printf("The factorial is %d !\n",n);

        system("pause");
        return 0;
}[/mw_shl_code]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表