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. Struts1与Struts2的12点区别

    Struts1与Struts2的12点区别  1) 在Action实现类方面的对比:Struts 1要求Action类继承一个抽象基类:Struts 1的一个具体问题是使用抽象类编程而不是接口.Str ...

  2. java web工程之Hibernate

    java web添加structs特性后再添加Hibernate特性,这可以通过右键工程->my eclipse出现工具条选中相应的条目,添加相应的属性, 添加完Hibernate后建立与数据库 ...

  3. bootstrap-table 原来bootstrap还有这么强大的表格插件

    http://issues.wenzhixin.net.cn/bootstrap-table/index.html

  4. Lucene搜索方法总结

    转自:summerbell http://www.iteye.com/topic/569358 1.多字段搜索 使用 multifieldqueryparser 可以指定多个搜索字段. query q ...

  5. 使用CodeDOM实现代码生成及动态编译

    参考资料: http://www.cnblogs.com/lichdr/category/12610.html http://www.cnblogs.com/whitewolf/category/25 ...

  6. commandname+commandargument

    (一) CommandName:其实可以设置成一种动作,比如Select,Update,Delete,等操作.就是说CommandName是确定他到底引发的是哪一事件,如果CommandName的名字 ...

  7. Xamarin学习资源收集

    推荐入门视频 跨行動平台App開發概觀- 使用Xamarin+Visual Studio https://www.youtube.com/watch?v=ELuFTTn1gS4 中文产品介绍http: ...

  8. C#winform中DataGridView常用的属性

    1.AllowUserToAddRows属性:指示是否向用户显示添加行的选项 AllowUserToOrderColumns属性:指示是否允许通过手动对列重新定位 AllowUserToResizeC ...

  9. Oracle数据库--SQL

    1.事务(Transaction ) 1)命名事务 set transaction name ‘transaction_name ’; 2)查看事务是否存在 select name from v$tr ...

  10. centos 6.X 安装scrapy-原创

    特别注意[坑]: python版本一定大于 2.7.5,scrapy python 必须2.7以上centos 6.X系列 系统默认安装的python是2.6.6 ,本人折腾了很久2.7.3 在这里升 ...