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语言课本实例的更多相关文章

  1. MATLAB与C语言对比实例:随机数生成

    MATLAB与C语言对比实例:随机数生成 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 一.整型随机数生成函数 1.C语言程序 int intrand ...

  2. c语言课本及pta作业中运用到的程序思维

    c语言课本运用到的程序思维 我个人觉得在写程序的时候,有很多题目会用到我们学过的解决一个程序或者一个问题的方法,把这些方法运用起来,将会使自己更加灵活地解决诸多问题,为今后打下良好地基础. (因为还没 ...

  3. R语言入门级实例——用igragh包分析社群

    R语言入门级实例——用igragh包分析社群 引入—— 本文的主要目的是初步实现R的igraph包的基础功能,包括绘制关系网络图(social relationship).利用算法进行社群发现(com ...

  4. c语言字符串实例

    例子:涉及字符串.字符.指针.++等 例一:字符串与字符 #include <stdio.h> void reverse(char *str) { char *end=str; print ...

  5. c语言编程实例——小球跳动

    1.预备知识 1.1 相关头文件 "#include"是c语言中用以申明所需调用的库函数或自定义函数的头文件路径及文件名.#include ""和#includ ...

  6. R语言学习——实例标识符

    > patientID<-c(1,2,3,4)> age<-c(25,34,28,52)> diabetes<-c("Type1"," ...

  7. 分离链接散列表C语言实现实例

    /* hash_sep.h */ #ifndef _HASH_SEP_H #define _HASH_SEP_H #define MIN_TABLE_SIZE 5 struct list_node; ...

  8. 在Golang中使用C语言代码实例

    转自:http://www.jb51.net/article/56720.htm cgo 使得在 Golang 中可以使用 C 代码. Hello World 为了有一个较为直观的了解,我们来看一个简 ...

  9. C语言——杂实例

    #include <stdio.h> #include <stdlib.h> #include <string.h> void f (int **p); void ...

随机推荐

  1. 用MyEclipse搭建SSH框架(Struts2 Spring Hibernate)

    1.new一个web project. 2.右键项目,为项目添加Struts支持. 点击Finish.src目录下多了struts.xml配置文件. 3.使用MyEclipse DataBase Ex ...

  2. 在vs2013中配置openGL(绝对可靠 !)

    首先要下载glut.h glut32.dll glut32.lib.(这个在glut-3.7.6-bin的包里面,可以直接下载 ) 然后: glut.h:放到 D:\vs2013\VC\include ...

  3. 移动web app开发小贴士 收藏有用

    1 创建主屏幕图标 (Creating a home screen icon ,for ios)   1 2 3 4 5 6 //57*57 <link rel="apple-touc ...

  4. smarty模板中引用常量没效果

    在thinkphp框架中使用Thinkph的模板引擎,css,js等都没问题,配置为smarty模板引擎后没效果,如图 代码为,$Smarty的s是大写,此时页面不能引入常量,改为小写后正常了. &l ...

  5. WTF,这到底是在做什么?

    1 <?php 2 $data = "<soap:Envelope>[...]</soap:Envelope>"; 3 $tuCurl = curl_ ...

  6. Angualar:指令大全

    指令: 内置渲染指令 内置事件指令 内置节点指令 自定义指令 restrict template replace属性 templateUrl属性 trnsclude priorty terminal属 ...

  7. PHP pear安装

    PHP pear安装 Posted on 2012-07-06 10:19 bug yang 阅读(5787) 评论(0) 编辑 收藏 转自:http://wangye.org/blog/archiv ...

  8. WordPress博客教程:博客赚钱

    稍有关注独立博客的人都应该知道,中文博客实现盈利非常艰难,至少对于大部分中文博客来说是这样的.但很多时候我们不得不往赚钱的方向前进,至少要交得起域名和空间的租用费吧.不过期待赚钱前,你必须思考下如何提 ...

  9. LVS的DR模式配置

    一.基本规划负载均衡调度器    192.168.1.104    默认网关    192.168.1.1    ip别名    192.168.1.233realserver1    192.168 ...

  10. Allowed memory size Out of memory ini_set('memory_limit', '-1');

    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 51 bytes) ini_set(' ...