//递归求数的阶乘
#include <stdio.h>
long recursion(int n);
void main()
{int n;long result;scanf("%d",&n);result=recursion(n);printf("%d!=%ld\n",n,result);}
long recursion(int n)
{long tmp_result;if(n==0 || n==1){tmp_result=n;}else if(n<0){printf("error input");}else{tmp_result=recursion(n-1)*n;}return tmp_result;
}
原文:https://www.cnblogs.com/yanweichen/p/10322275.html
2 题目内容:无线电台的RS制信号报告是由三两个部分组成的:R(Readability) 信号可辨度即清晰度.S(Strength) 信号强度即大小.其中R位于报告第一位,共分5级,用1—5数字表示.UnreadableBarely readable, occasional words distinguishableReadable with considerable difficultyReadable with practically no difficultyPerfectly readable报告第二位是S,共分九个级别,用1—9中的一位数字表示Faint signals, barely perceptib...
注:练习题目均出自《明解C语言 入门篇》一、do语句1,求多个整数的和及平均值#include<stdio.h>
int main(void)
{int sum = 0; //和 int cnt = 0; //整数个数 int retry; //判断是否继续do{int t;printf("请输入一个整数:");scanf("%d",&t);sum = sum + t;cnt = cnt + 1;printf("是否继续?<Yes...0/No...9:");scanf("%d",&retry);} while(retry == 0);printf("和为%d,平均值为%.2f。\n",sum,(double)sum / cnt);return0;
} 二...
题目:将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。 程序分析:对n进行分解质因数,应先找到一个最小的质数k,然后按下述步骤完成:
(1)如果这个质数恰等于n,则说明分解质因数的过程已经结束,打印出即可。
(2)如果n<>k,但n能被k整除,则应打印出k的值,并用n除以k的商,作为新的正整数你n, 重复执行第一步。
(3)如果n不能被k整除,则用k+1作为k的值,重复执行第一步。 1main() 2{ 3int n,i; 4 printf("\nplease ...
题目:输入三个整数i,j,k,请把这三个数由小到大输出。 1 #include<stdio.h>2 3int main(void){4int i,j,k;5 scanf("%d %d %d",&i,&j,&k);6if(i>j){7int temp=0;8 temp=i;9 i=j;
10 j=temp;
11 }
12if(i>k){
13int temp=0;
14 temp=i;
15 i=k;
16 k=temp;
17 }
1819if(j>k){
20int temp=0;
21 temp=j;
22 ...
练习2-1 Programming in C is fun! (5 分)本题要求编写程序,输出一个短句“Programming in C is fun!”。输入格式:本题目没有输入。输出格式:在一行中输出短句“Programming in C is fun!”。思路:直接格式化输出语句。代码如下: #include<stdio.h>
int main ()
{printf("Programming in C is fun!\n"); //格式化输出return 0;
}
原文:https://www.cnblogs.com/IT-Lead-The-World/p/10345485.html
练习2-13 求N分之一序列前N项和 (15 分)本题要求编写程序,计算序列 1 + 1/2 + 1/3 + ... 的前N项之和。输入格式:输入在一行中给出一个正整数N。输出格式:在一行中按照“sum = S”的格式输出部分和的值S,精确到小数点后6位。题目保证计算结果不超过双精度范围。输入样例:6
输出样例:sum = 2.450000思路:每次循环分母加一。代码如下:#include<stdio.h>
int main()
{ int i, n, denominator;double sum, a;scanf("%d",&n);sum=0...
(6)将100~200之间的素数打印出来.#include<stdio.h>
int main(){int i,j;for(i=100;i<=200;i++){for(j=2;j<i;j++){if(i%j==0)break;}if(i==j)printf("%d\n",i);}return 0;
}素数的公约数除了一就是它本身;如果这个数字在遍历二到它本身之间出现能被整除的情况就代表这个数不是素数;原文:https://www.cnblogs.com/cylf/p/10593395.html
汇集1000道C语言和C++语言的练习题 (例题、笔试题、编程题、算法设计题),由我亲自配上答案(点此查看)。 语法题我就不出了,那个没意思,看书就可以了。本贴汇集50题 (0000-0050),持续更新...0001. 抽签题
从10个数中随机抽取5个数。(相当于双色球抽签问题)0002. 插入排序
已有10个按增序排列好的整数1,3,5,7,9,11,13,15,17,19。要求把一个整数n插到数组中,保持增序排列。0003. 数学公式类计算题
已经圆柱体的底半...
/**生命游戏 1-一个细胞周围8个细胞中如果有3个细胞为生,则该细胞为生2-如果该细胞周围只有2个细胞为生,则该细胞的生死保持不变3-在其他情况下,该细胞为死
*/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <time.h>#define High_Max 100
#define Width_Max 100int High =20;
int Width =50;
int Canvas [High_Max][Width_Max];
int Breed_Num=0;void gotoxy(int x,int y)//清屏
{HANDLE handle = Ge...
main.m 文件 9#import <Foundation/Foundation.h>10#import"Pointer.h" 11////////////////Lesson 11 函数指针 课堂笔记 与 习题练习////////////12 13 14//函数指针:指向函数的指针叫做函数指针,用来存储函数的地址15//函数名代表函数的入口地址16 17 18//回调函数; 函数指针变量,存储对应的函数的地址19//给函数指针类型,取一个新的名字 typedef,修饰的新名字,不是变量20//typedef int (*PFun)(int, int);//起得新的名字...
ACboy was kidnapped!! he miss his mother very much and is very scare now.You can‘t image how dark the room he was put into is, so poor :(. As a smart ACMer, you want to get ACboy out of the monster‘s
labyrinth.But when you arrive at the gate of the maze, the monste say :"I have heard that you are very clever, but if can‘t solve my problems,
you will die with ACboy." The problems of the mons...
1. 冒泡排序简介(默认从小到大排序) 核心思想:只比较相邻的两个元素,如果满足条件就交换 5 8 2 1 6 9 4 3 7 0目标:0 1 2 3 4 5 6 7 8 9 第一次排序: 5 < 8 不交换 5 8 2 1 6 9 4 3 7 0 8 >2 满足条件 交换.... 5 2 8 1 6 9 4 3 7 0 5 2 1 8 6 9 4 3 7 0 5 2 1 6 8 9 4 3 7 0 5 2 1 6 8 9 4 3 7 0 5 2 1 6 8 4 9 3 7 0 5 2 1 6 8 4 3 9 7 0 5 2 1 6 8 4 3 7 9 0 5 2 1 6 8 ...
最近看了计科班的习题 很多都是和文件读取有关的 决定练习一下用到的函数:freopen()以下解释来源于百度百科:freopen是被包含于C标准库头文件<stdio.h>中的一个函数,用于重定向输入输出流。该函数可以在不改变代码原貌的情况下改变输入输出环境,但使用时应当保证流是可靠的。
---------------------------------------
用这个函数可以把scanf的输入重定义到文件 在测试大量数据时非常实用。#include<stdio.h>
#include<string...
直接用Xcode学习C语言,为iOS开发打基础。(1)选择OS X >>> Application >>> Command Line Tool(2)输入产品名称,公司唯一标识。应用程序唯一标识=公司唯一标识+产品名称。注意:公司唯一标识一般是域名倒过来写,如www.hellocation.com,那么写成com.hellocation。注意:选择C语言。默认是OC,所以我们在学习OC的时候没有做任何动作。(3)进入程序后,点击main.c程序源文件,有一段现成的helloworld程序,直接点击CMD+B...