程序(循环)

来源:互联网 发布:.gs域名不能注册 编辑:程序博客网 时间:2024/05/15 07:46

1、

#include<stdio.h>
int main(void)
{
    int count,sum,max;
    count=0;
    sum=0;
    printf("Please input the max:");
    scanf("%d",&max);
    while(count++<max)
      sum=sum+count;
    printf("sum=%d\n",sum);
    return 0;
}


2、

#include<stdio.h>
#define MAX 100
int main(void)
{
    int count=MAX+1;
    while(--count>0)
    {
        printf("%d bottles of spring water on the wall,"
"%d bottles of spring water!\n",count,count);
printf("Take one down and pass it around,\n");
printf("%d bottles of spring water!\n\n",count-1);
    }
    return 0;
}

0 0
原创粉丝点击