20131005国庆作业例5-8,5-9

5-8

#include<stdio.h>
float cash;
int main(void)
{
    int choice;
    float value;
    void income(float number),expend(float number);

    cash=0;
    printf("Enter operate choice(0--end,1--income,2--expend):");
    scanf("%d",&choice);
    while(choice!=0){
        if(choice==1||choice==2){
            printf("Enter cash value:");
            scanf("%f",&value);
            if(choice==1)
                income(value);
            else
                expend(value);
            printf("current cash:%.2f\n",cash);
        }
        printf("Enter operate choice(0--end,1--income,2--expend):");
        scanf("%d",&choice);
    }
    return 0;
}
void income(float number)
{
    cash=cash+number;
}
void expend(float number)
{
    cash=cash-number;
}

 

5-9

#include<stdio.h>
double fact_s(int n);
int main(void)
{
    int i,n;
    printf("Input n:");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        printf("%3d!=%.0f\n",i,fact_s(i));

    return 0;
}
double fact_s(int n)
{
    static double f=1;
    f=f*n;

    return(f);
}

 

posted @ 2013-10-05 14:33  鲍。  阅读(125)  评论(0编辑  收藏  举报