C语言如何查找重负向并显示其位置,c语言复习题答案(49题)讲解.doc

一、 顺序结构程序设计========================================1 已知三角形的三边长为a,b,c,计算三角形面积的公式为:area = ,s=要求编写程序,从键盘输入a,b,c的值,计算并输出三角形的面积。

#include#includevoid main(){ float a,b,c,s,area; scanf("%f,%f,%f",&a,&b,&c); s=1.0/2*(a+b+c); area=sqrt(s*(s-a)*(s-b)*(s-c)); printf("a=%7.2f, b=%7.2f, c=%7.2f, s=%7.2f\n",a,b,c,s); printf("area=%7.2f\n",area);}

2 编程从键盘输入圆的半径r,计算并输出圆的周长和面积。#include "stdio.h"#define Pi 3.14void main(){float r,c,area;printf("请输入圆的半径:");scanf("%f",&r);c=2*Pi*r;area=Pi*r*r;printf("该圆的周长是%.2f,面积是%.2f\n",c,area);}

二、 选择结构程序设计========================================== 1 从键盘任意输入一个年号,判断它是否是闰年。若是闰年,输出“Yes”,否则输出“No”。已??符合下列条件之一者是闰年:能被4整除,但不能被100整除。能被400整除。#include main(){int year, flag;

printf("Enter year:");scanf("%d",&year );

if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)){ flag = 1; /*如果year是闰年,则标志变量flag置1*/}else{flag = 0; /*否则,标志变量flag置0*/}

if (flag){ printf("%d is a leap year!\n",year); /*打印“是闰年”*/}else{printf("%d is not a leap year!\n",year); /* 打印“不是闰年”*/}}

2 通过键盘输入一个字符,判断该字符是数字字符、大写字母、小写字母、空格还是其他字符。#include main(){char ch;

scanf("%c",ch);

if ((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 98)){printf("It is an English character!\n");}else if (ch <= 57 && ch >= 48){ printf("It is a digit character!\n");}else if (ch == 95){ printf("It is a space character!\n");}else{printf("It is other character!\n");}}

3 华氏和摄氏温度的转换公式为C=5/9×(F-32)。其中,C表示摄氏温度,F表示华氏温度。要求:华氏0℉~300℉,每隔20℉输出一个华氏温度对应的摄氏温度值。#include #include main(){int upper,step;float fahr = 0,celsius;

upper = 300;step = 20;while ( fahr< upper){ celsius = 5.0 / 9 * (fahr - 32); printf("%4.0f\t%6.1f\n", fahr, celsius); fahr = fahr + step;}}

4 编程判断输入整数的正负性和奇偶性。 #include main(){int m;

printf("Input m: ");scanf("%d", &m);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值