用C语言计算简单的数学题

Python028

用C语言计算简单的数学题,第1张

#include<stdio.h>

/****************************

得用[人高:人影长=树高:树影长] 可求出树高

详情请百度

******************************/

int main(int argc, char const *argv[])

{

    

    float human,humanshadow,tree,treeshadow

    printf("请输入人高\n")

    scanf("%f",&human)

    printf("请输入人影长度\n")

    scanf("%f",&humanshadow)

    printf("请输入树影长度\n")

    scanf("%f",&treeshadow)

    printf("树的高度是%f\n",human*treeshadow/humanshadow)

    return 0

}

如果一次买的数量等于50套呢?

#include <stdio.h>

int small(int a,int b)

{

if(a>b)

a=b

return a

}

int main()

{

int tops,pants,temp,sum=0

scanf("%d%d",&tops,&pants)

if(tops==pants)

{

if(tops>50)

sum=tops*80

else

sum=tops*90

}

else

{

temp=small(tops,pants)

if(temp>50)

sum=temp*80

else if(temp<50)

sum=temp*90

if(tops>pants)

sum+=(tops-pants)*60

else if(tops<pants)

sum+=(pants-tops)*45

}

printf("%d\n",sum)

return 0

}

显然需要9天,程序如下:

#include <stdio.h>

int main()

{

int i=0

double s=0.0

while(1)

{

s+=1.5

if(s>=10) break

else s -=0.5

i++

}

printf("%dday\n",i)

return 0

}