C语言课本实例
1. 将一维数组的内容倒顺
#include <stdio.h>
void func(int *s,int n)
{
int i,temp;
for(i=0;i<n/2;i++)
{
temp=s[i];
s[i]=s[n-1-i];
s[n-1-i]=temp;
}
}
void main()
{
int i,a[10];
for(i=0;i<10;i++)
a[i]=i;
func(a,10);
for(i=0;i<10;i++)
printf("%d\n",a[i]);
}
2. 数组遍历
#include <stdio.h>
#define N 5
int search(int *s,int x)//s[N]
{
int i;
for(i=0;i<N;i++) if(s[i]==x) break;
if(i<N) return 1;
else return 0;
}
void main()
{
int a[N],i,e;
printf("Enter the array:\n");
for(i=0;i<N;i++) scanf("%d",&a[i]);
printf("Enter the Element:\n");
scanf("%d",&e);
if(search(a,e)==1) printf("The element %d exists in the array.\n",e);
else printf("Can not find the element %d.\n",e);
}
3. 用选择法对数组排序
#include <stdio.h>
#define N 6
void sort(int *s,int n);
void main()
{
int a[N],i;
printf("enter the array:\n");
for(i=0;i<N;i++) scanf("%d",&a[i]);
sort(a,N);
printf("the sorted array:\n");
for(i=0;i<N;i++) printf("%d ",a[i]);
printf("\n");
}
void sort(int *s,int n)
{
int i,j,p,t;
for(i=0;i<n;i++)
{
p=i;
for(j=i+1;j<n;j++)
if(s[j]<s[p])
p=j;
t=s[p];
s[p]=s[i];
s[i]=t;
}
}
4.
C语言课本实例的更多相关文章
- MATLAB与C语言对比实例:随机数生成
MATLAB与C语言对比实例:随机数生成 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 一.整型随机数生成函数 1.C语言程序 int intrand ...
- c语言课本及pta作业中运用到的程序思维
c语言课本运用到的程序思维 我个人觉得在写程序的时候,有很多题目会用到我们学过的解决一个程序或者一个问题的方法,把这些方法运用起来,将会使自己更加灵活地解决诸多问题,为今后打下良好地基础. (因为还没 ...
- R语言入门级实例——用igragh包分析社群
R语言入门级实例——用igragh包分析社群 引入—— 本文的主要目的是初步实现R的igraph包的基础功能,包括绘制关系网络图(social relationship).利用算法进行社群发现(com ...
- c语言字符串实例
例子:涉及字符串.字符.指针.++等 例一:字符串与字符 #include <stdio.h> void reverse(char *str) { char *end=str; print ...
- c语言编程实例——小球跳动
1.预备知识 1.1 相关头文件 "#include"是c语言中用以申明所需调用的库函数或自定义函数的头文件路径及文件名.#include ""和#includ ...
- R语言学习——实例标识符
> patientID<-c(1,2,3,4)> age<-c(25,34,28,52)> diabetes<-c("Type1"," ...
- 分离链接散列表C语言实现实例
/* hash_sep.h */ #ifndef _HASH_SEP_H #define _HASH_SEP_H #define MIN_TABLE_SIZE 5 struct list_node; ...
- 在Golang中使用C语言代码实例
转自:http://www.jb51.net/article/56720.htm cgo 使得在 Golang 中可以使用 C 代码. Hello World 为了有一个较为直观的了解,我们来看一个简 ...
- C语言——杂实例
#include <stdio.h> #include <stdlib.h> #include <string.h> void f (int **p); void ...
随机推荐
- 使用新的AppleID更新Xcode
为了免下载安装Xcode,安装时使用了别人提供的Xcode.dmg安装,而非使用自己账号在AppStore下载的. 这样的安装模式会出现一个问题,更新Xcode时AppStroe会提示让你输入下载该X ...
- Grasshopper 2.0 MP Color FireWire 1394b (Sony ICX274)
相机参数如下,参见这里: Resolution 1624 x 1224 Frame Rate 30 FPS Megapixels 2.0 MP Chroma Color Sensor Name ...
- 启用VTX技术支持启动android的虚拟机 - 报错
第一次启用VTX技术支持启动android的虚拟机,启动时提示如下错误: Starting emulator for AVD 'AVD_for_Android_TV_1080p_by_Google'e ...
- linphone3.4.0代码分析
主要类型定义: 1.LinphoneCoreVTable /** * This structure holds all callbacks that the application should im ...
- 算法与数据结构题目的 PHP 实现:栈和队列 设计一个有 getMin 功能的栈
刚入手了一本<程序员代码面试指南>,书中题目的代码都是 Java 实现的,琢磨着把这些代码用 PHP 敲一遍,加深印象. 题目:设计一个有 getMin 功能的栈 —— 实现一个特殊的栈, ...
- 获取在attr.xml中声明的主题样式
在换肤时,先在attr.xml中定义Resource的属性名,再到stytle中,根据不同的主题,给属性赋值. 在布局文件中可直接以 android:background="?attr/a ...
- MVC4发布到IIS7报404错误
在MVC根目录的web.config中添加 <system.webServer> <modules runAllManagedModulesForAllRequests=" ...
- 20145317彭垚 《Java程序设计》第6周学习总结
20145317彭垚 <Java程序设计>第6周学习总结 第十章 输入/输出 10.1 InputStream与OutputStream 1.串流设计的概念 Java将输入/输出抽象化为串 ...
- hot code replace
http://wiki.eclipse.org/FAQ_What_is_hot_code_replace%3F https://social.msdn.microsoft.com/Forums/vst ...
- prototype linkage can reduce object initialization time and memory consumption
//对象是可变的键控集合, //"numbers, strings, booleans (true and false), null, and undefined" 不是对象的解释 ...