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

C语言:基本控制结构

来源:网络收集 时间:2026-04-30
导读: 计算题 Time Limit: 1000MS Memory limit: 65536K 题目描述 一个简单的计算,你需要计算f(m,n),其定义如下: 当m=1时,f(m,n)=n; 当n=1时,f(m,n)=m; 当m>1,n>1时,f(m,n)= f(m-1,n)+ f(m,n-1) 输入 第一行包含一个整数T(1 以下T行,其中每组数据有两个

计算题

Time Limit: 1000MS Memory limit: 65536K

题目描述

一个简单的计算,你需要计算f(m,n),其定义如下: 当m=1时,f(m,n)=n; 当n=1时,f(m,n)=m;

当m>1,n>1时,f(m,n)= f(m-1,n)+ f(m,n-1) 输入

第一行包含一个整数T(1<=T<=100),表示下面的数据组数。

以下T行,其中每组数据有两个整数m,n(1<=m,n<=2000),中间用空格隔开。 输出

对每组输入数据,你需要计算出f(m,n),并输出。每个结果占一行。 示例输入 2 1 1 2 3

示例输出 1 7

#include int f(int m,int n) { if(m==1) return n; else if(n==1) return m; else return f(m-1,n)+f(m,n-1); }

void main() { int m,n,t,sum; scanf(\ while(t--) { scanf(\ sum=f(m,n); printf(\ } }

简单计算

Time Limit: 1000MS Memory limit: 65536K

题目描述

接受从键盘输入的N个整数,输出其中的最大值、最小值和平均值。 输入

第一行一个正整数N(N<=100);

第二行有N个用空格隔开的整数Ti (1<= i <=N, 0<= Ti <= 1000) ouput 输出

三个有空格隔开的整数分别为最大值、最小值和平均值。 示例输入 5

1 2 3 5 4

示例输出 5 1 3

#include void main() {

int n,a=0,b,i,j,t[100]; scanf(\ for(i=0;i<=n-1;i++) {

scanf(\ a+=t[i]; }

for(i=0;i<=n-2;i++) {

for(j=0;j<=n-i-2;j++) {

if(t[j]>t[j+1]) {

b=t[j];

t[j]=t[j+1]; t[j+1]=b; } } }

printf(\ }

IBM Minus One

Time Limit: 1000MS Memory limit: 65536K

题目描述

You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or the film of the same name by Stanley Kubrick. In it a spaceship is sent from Earth to Saturn. The crew is put into stasis for the long flight, only two men are awake, and the ship is controlled by the intelligent computer HAL. But during the flight HAL is acting more and more strangely, and even starts to kill the crew on board. We don't tell you how the story ends, in case you want to read the book for yourself :-)

After the movie was released and became very popular, there was some discussion as to what the name 'HAL' actually meant. Some thought that it might be an abbreviation for 'Heuristic ALgorithm'. But the most popular explanation is the following: if you replace every letter in the word HAL by its successor in the alphabet, you get ... IBM.

Perhaps there are even more acronyms related in this strange way! You are to write a program that may help to find this out. 输入

The input starts with the integer n on a line by itself - this is the number of strings to follow. The following n lines each contain one string of at most 50 upper-case letters. 输出

For each string in the input, first output the number of the string, as shown in the sample output. The print the string start is derived from the input string by replacing every time by the following letter in the alphabet, and replacing 'Z' by 'A'.

Print a blank line after each test case. 示例输入 2 HAL SWERC 示例输出 String #1 IBM

String #2 TXFSD

#include #include void main() {

char s[50]; int i,a,b,k=1; scanf(\ while(b--) {

scanf(\ a=strlen(s);

printf(\ for(i=0;i

if(s[i]>='A'&&s[i]<='Y') printf(\ else if(s[i]=='Z')

printf(\ }

printf(\ k++; } }

No Brainer

Time Limit: 1000MS Memory limit: 65536K

题目描述

Zombies love to eat brains. Yum. 输入

The first line contains a single integer n indicating the number of data sets.

The following n lines each represent a data set. Each data set will be formatted according to the following description:

A single data set consists of a line \eats and Y is the number of brains the zombie requires to stay alive. 输出

For each data set, there will be exactly one line of output. This line will be \BRAINS\

number of brains the zombie requires to stay alive. Otherwise, the line will be \BRAINS\示例输入 3 4 5 3 3 4 3

示例输出 NO BRAINS MMM BRAINS MMM BRAINS

#include void main() {

int n,i,k;

scanf(\ while(n--) {

scanf(\

if(i

else if(i>=k) printf(\ } }

C语言实验——交换两个整数的值(顺序结构) Time Limit: 1000MS Memory limit: 65536K

题目描述

交换两个变量的值,由终端输入两个整数给变量x、y,然后交换x和y的值后,输出x和y。 输入

从键盘输入两个整数变量x和y; 输出

在交换x、y的值后将x和y输出! 示例输入 4 6

示例输出 6 4

#include

…… 此处隐藏:1508字,全部文档内容请下载后查看。喜欢就下载吧 ……
C语言:基本控制结构.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)