其他分享
首页 > 其他分享> > c语言4-15 输出标准身高体重对照表

c语言4-15 输出标准身高体重对照表

作者:互联网

 

采用的计算公式 (身高 - 100)* 0.9.

 

1、while语句

#include <stdio.h>

int main(void)
{
    int start, end, gap;
    puts("please input the start, end and gap.");
    printf("start = "); scanf("%d", &start);
    printf("end = "); scanf("%d", &end);
    printf("gap = "); scanf("%d", &gap);
    
    while (start <= end)
    {
        printf("%d cm  :  %.2f kg\n", start, (start - 100) * 0.9);
        start += gap;
    }
    
    return 0;
}

 

2、for语句

#include <stdio.h>

int main(void)
{
    int start, end, gap;
    puts("please input the start, end, and gap.");
    printf("start = "); scanf("%d", &start);
    printf("end = "); scanf("%d", &end);
    printf("gap = "); scanf("%d", &gap);
    
    for (start; start <= end; start += gap)
    {
        printf("%d cm  :  %.2f kg\n", start, (start - 100) * 0.9);
    } 
    
    return 0;
}

 

3、do语句

#include <stdio.h>

int main(void)
{
    int start, end, gap;
    puts("please input the start, end and gap.");
    printf("start = "); scanf("%d", &start);
    printf("end = "); scanf("%d", &end);
    printf("gap = "); scanf("%d", &gap);
    
    do
    {
        printf("%d cm  :  %.2f kg\n", start, (start - 100) * 0.9);
        start += gap;
    }
    while (start <= end);
    
    return 0;
}

 

标签:身高体重,end,int,scanf,gap,start,printf,15,对照表
来源: https://www.cnblogs.com/liujiaxin2018/p/14678356.html