博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c语言数组那些骚事儿
阅读量:4610 次
发布时间:2019-06-09

本文共 1875 字,大约阅读时间需要 6 分钟。

找出最大和第二大值 #include 
#include
#include
int main(){ int mynum[] = {
43, 88, 56, 24, 78, 12, 8,29,57,80}; int max=0; printf("%d\n", max); int smax=0; printf("%d\n", smax); if (mynum[0] > mynum[1]) { max = mynum[0]; smax = mynum[1]; } else { max = mynum[1]; smax = mynum[0]; } for (int i = 2; i < 10; i++) { if (max < mynum[i]) { smax = max; max = mynum[i]; } else if ((mynum[i]
smax)) { smax = mynum[i]; } } printf("%d\n",max); printf("%d\n", smax); system("pause");}
  •  数组的逆序----思想是第一个和最后一个,第二个和倒数第二个
#include 
#include
#include
int main(){ int mynum[] = { 43, 88, 56, 24, 78, 12, 8, 29, 57, 80 }; int cnt = sizeof(mynum) / 4; printf("%d\n",cnt); for (int i = 0; i < cnt/2; i++) { int temp = mynum[i]; mynum[i] = mynum[cnt - i - 1]; mynum[cnt - i - 1] = temp; } for (int i = 0; i < 10; i++) { printf("%d,", mynum[i]); } system("pause"); return EXIT_SUCCESS;}
  •  字符串逆序,------目前只能应用于中间带空格的英文字符串
#include 
#include
#include
int main(){ char mywords[] = "hello world"; int cnt; cnt = sizeof(mywords)-1; printf("%d\n",cnt); for (int i = 0; i < cnt/2; i++) { if (i == 6) { } else { char temp = mywords[i]; mywords[i] = mywords[cnt - i - 1]; mywords[cnt - i - 1] = temp; } } for (int i = 0; i < sizeof(mywords); i++) { printf("%c", mywords[i]); } system("pause"); return EXIT_SUCCESS;}

 

转载于:https://www.cnblogs.com/saintdingspage/p/10338577.html

你可能感兴趣的文章
(转载)rabbitmq与springboot的安装与集成
查看>>
C2. Power Transmission (Hard Edition)(线段相交)
查看>>
STM32F0使用LL库实现SHT70通讯
查看>>
Atitit. Xss 漏洞的原理and应用xss木马
查看>>
MySQL源码 数据结构array
查看>>
(文件过多时)删除目录下全部文件
查看>>
T-SQL函数总结
查看>>
python 序列:列表
查看>>
web移动端
查看>>
pythonchallenge闯关 第13题
查看>>
linux上很方便的上传下载文件工具rz和sz使用介绍
查看>>
React之特点及常见用法
查看>>
【WEB前端经验之谈】时间一年半,或沉淀、或从零开始。
查看>>
优云软件助阵GOPS·2017全球运维大会北京站
查看>>
linux 装mysql的方法和步骤
查看>>
poj3667(线段树区间合并&区间查询)
查看>>
51nod1241(连续上升子序列)
查看>>
SqlSerch 查找不到数据
查看>>
集合相关概念
查看>>
Memcache 统计分析!
查看>>