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. CentOS mysql硬盘满了挂载阿里云硬盘

    前提,昨天晚上导入数据库到本地时候发现硬盘满了,出了,好多错,这边在目录下新建了一个/mysql这样的数据库目录,再将/etc/my.cnf 下的datadir 指向到/mysql下,就可以了 阿里云 ...

  2. jsp中如何取得当前页面完整的URL

    JSP页面 <% String url = request.getScheme()+"://"+ request.getServerName()+request.getReq ...

  3. Js操作Select大全

    判断select选项中 是否存在Value="paraValue"的Item 向select选项中 加入一个Item 从select选项中 删除一个Item 删除select中选中 ...

  4. meta标签的用法

    meta是用来在HTML文档中模拟HTTP协议的响应头报文.meta 标签用于网页的<head>与</head>中,meta 标签的用处很多.meta 的属性有两种:name和 ...

  5. shell 循环

    for循环: 批量删除.gz结尾的文件: 循环打包文件并备份到一个目录下面: find ./ -maxdepth 1 -name "*.gz" find ./ -maxdepth ...

  6. WSUS更新服务器

    http://windowsupdate.microsoft.com http://*.windowsupdate.microsoft.com   https://*.windowsupdate.mi ...

  7. 项目部署到Tomat报错:jar not loaded.See Servlet Spec 2.3, section 9.7.2. Offending

    项目部署到Tomcat报这样的异常: Java代码   jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: ja ...

  8. try...except 抛出错误

  9. FloodLight使用感受

    一个使用java语言编写的基于Openflow协议的SDN控制器. 基本架构同webserver一样,有一个维护交换机连接信息的底层模块,当有交换机同控制器连接时,floodlight会将此连接保存到 ...

  10. P1010 幂次方

    这么难得题,居然普及-?做了好久 #include <bits/stdc++.h> using namespace std; int fact[21]; void solve(int n) ...