教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 基础教育 >

C语言:基本控制结构(6)

来源:网络收集 时间:2026-04-30
导读: 求三角形面积 Time Limit: 1000MS Memory limit: 65536K 题目描述 已知三角形的边长a、b和c,求其面积。 输入 输入三边a、b、c。 输出 输出面积,保留3位小数。 示例输入 1 2 2.5 示例输出 0.950 #include #include

求三角形面积

Time Limit: 1000MS Memory limit: 65536K

题目描述

已知三角形的边长a、b和c,求其面积。 输入

输入三边a、b、c。 输出

输出面积,保留3位小数。 示例输入 1 2 2.5

示例输出 0.950

#include #include void main() { float a,b,c,p,area; scanf(\ p=(a+b+c)/2; area=sqrt(p*(p-a)*(p-b)*(p-c)); printf(\}

C语言实验——温度转换

Time Limit: 1000MS Memory limit: 65536K

题目描述

输入一个华氏温度,输出摄氏温度,其转换公式为:C=5(F-32)/9。 输入

输入数据只有一个实数,即华氏温度。 输出

输出数据只有一个,即摄氏温度,保留2位小数。 示例输入 32.0

示例输出 0.00

#include #include

void main() { float F,C; scanf(\ C=5*(F-32)/9; printf(\}

分段函数求值

Time Limit: 1000MS Memory limit: 65536K

题目描述 有如下分段函数

F(x) = x^2 + 1 当x> 0时; F(x) = -x 当x<0时; F(x) = 100.00 当x=0时;

编程根据输入的不同x(x为实数且|x| <= 1000),输出其对应的函数值 输入

多组输入,每组一个实数x。处理到文件结束。 输出

对于每组输入x,输出其对应的F(x),每组一行,结果保留1位有效数字。 示例输入 8.00 -5.0

示例输出 65.0 5.0

#include #include void main() { float x,f; while(scanf(\ { if(x>0) f=1+pow(x,2); else if(x<0) f=-x; else if(x==0) f=100.00; printf(\ } }

C语言实验——买糖果

Time Limit: 1000MS Memory limit: 65536K

题目描述

小瑜是个爱吃糖果的馋鬼,天天嚷着要爸爸买糖果,可是爸爸很忙,哪有时间啊,于是就让小瑜自己去了,糖果3角钱一块,爸爸给小瑜n元钱,请你告诉小瑜最多能买几块糖,还剩几角钱? 输入

输入爸爸给小瑜的钱n元,n为整数。 输出

小瑜最多能买回的糖块数以及剩下的钱(单位为:角),用空格分隔。 示例输入 2

示例输出 6 2

#include void main() { int n,r,t; scanf(\ t=10*n/3; r=(10*n)%3; printf(\}

Doubles

Time Limit: 1000MS Memory limit: 65536K

题目描述

As part of an arithmetic competency program, your students will be given randomly generated lists of from 2 to 15 unique positive integers and asked to determine how many items in each list are twice some other item in the same list. You will need a program to help you with the grading. This program should be able to scan the lists and output the correct answer for each one. For example, given the list

1 4 3 2 9 7 18 22

your program should answer 3, as 2 is twice 1, 4 is twice 2, and 18 is twice 9. 输入

The input file will consist of one or more lists of numbers. There will be one list of numbers per line. Each list will contain from 2 to 15 unique positive integers. No integer will be larger than 99. Each line will be terminated with the integer 0, which is not considered part of the list. A line with the single number -1 will mark the end of the file. The example input below shows 3 separate lists. Some lists may not contain any doubles.

输出

The output will consist of one line per input list, containing a count of the items that are double some other item. 示例输入

1 4 3 2 9 7 18 22 0 2 4 8 10 0

7 5 11 13 1 3 0 -1

示例输出 3 2

#include void main() { int n,k,j,a[99]; while(scanf(\ { int i=1,s=0; if(a[0]==-1) break; else { while(scanf(\ { i++; } for(k=0;k

素数

Time Limit: 1000MS Memory limit: 32768K

题目描述

给你一个正整数N(N<=1000),希望你求出1~N内的所有素数。 输入

只有一个正整数N。 输出

输出一个整数,即1~N内的素数个数。 示例输入 10

示例输出 4

#include #include void main() { int n,i,j,k,s=0; scanf(\ for(i=1;i<=n;i=i+2) { for(j=2;j<=sqrt(i);j++) if(i%j==0) break; if(j>sqrt(i)) s++; } printf(\}

图案打印

Time Limit: 1000MS Memory limit: 65536K

题目描述

一年一度的植树节就要到了,计算机学院学生准备在学院教学楼门前的空地上种植树木。为使树木排列得更加美观,大家决定把树木排列成菱形。现在告诉你我们所拥有的树木能排列成边长为N的菱形,请你编程输出树木所排列的图案(用*号代表树木)。 输入

一个整数N(1≤N≤10)。 输出

排列成菱形图案的*号。请注意在图案中:每行树木之间无空行,每列树木之间均有一个空列。 示例输入 …… 此处隐藏:1004字,全部文档内容请下载后查看。喜欢就下载吧 ……

C语言:基本控制结构(6).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/565726.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)