数组
来源:互联网 发布:查看iptables开放端口 编辑:程序博客网 时间:2024/05/29 16:31
//
// main.m
// day4
//
// Created by dllo on 15/11/16.
// Copyright © 2015年 dllo. All rights reserved.
//
#import <Foundation/Foundation.h>
int main(int argc,const char * argv[]) {
//1 (**)随机产生20个10~50的正整数存放到数组中,并求数组中的多有元素最大值、最小值、平均值及各元素之和。
// int a[20]={0};
// int max=0,min=50,sum=0,ave=0;
//
// for (int i = 0; i<20; i++) {
// a[i]=arc4random()%(50-10+1)+10;
// printf("%d ",a[i]);
// }
// printf("\n");
// for (int i = 0; i<20; i++) {
// if (max<a[i ]) {
// max=a[i];
// }else if(min>a[i ]){
// min=a[i];
// }
// sum+=a[i];
//
// }
// ave=sum/20;
// printf("最大:%d最小:%d 平均值:%d 各元素之和:%d ",max,min,ave,sum);
//
//2. 编写一个程序,输入两个包含5个元素的数组,先将两个数组升序排序,然后将这两个数组合并成一个升序数组
// int a[5]={0};
// int b[5]={0};
// int c[10]={0};
// printf("a[5]请输入5个数:");
// for (int i = 0; i<5; i++) {
// scanf("%d",&a[i]);
// }
// printf("b[5]请输入5个数:");
// for (int i= 0; i<5; i++) {
// scanf("%d",&b[i]);
// }
// for (int i =0 ; i<4; i++) {
// for (int j = 0; j<4-i; j++) {
// if(a[j]>a[j+1]){
// int temp = a[j];
// a[j]=a[j+1];
// a[j+1]=temp;
// }
// }
// }
// for (int i = 0; i<5; i++) {
// printf("%d ",a[i]);
// }
// printf("\n");
// for (int i =0 ; i<4; i++) {
// for (int j = 0; j<4-i; j++) {
// if(b[j]>b[j+1]){
// int temp = b[j];
// b[j]=b[j+1];
// b[j+1]=temp;
// }
// }
// }
// for (int i = 0; i<5; i++) {
// printf("%d ",b[i]);
// }
// printf("\n");
// for (int i = 0; i<10; i++) {
// if (i<5) {
// c[i]=a[i];
// }
// else{
// c[i]=b[i-5];
// }
// }
// for (int i = 0; i<9; i++) {
// for (int j = 0; j<9-i; j++) {
// if (c[j]>c[j+1]){
// int temp = c[j];
// c[j]=c[j+1];
// c[j+1]=temp;
// }
// }
// }
// for (int i = 0; i<10; i++) {
// printf("%d ",c[i]);
// }
// printf("\n");
//
//3. (***)给定某年某月某日,输出其为这一年的第几天。(用数组做)
// int month =0,day= 0 ,year = 0,b=0;
// int a[]={31,28,31,30,31,30,31,31,30,31,30,31};
// scanf ("%d%d%d",&year,&month,&day );
//
// for (int i =0 ; i<month-1; i++) {
//
// b+=a[i];
//
//
// }
//
// if (year%400==0||year%4==0&&year%100!=0) {
// if (month>2) {
// b+=1;
// }
//
// }
//
// printf("这一年的%d天",b+day);
//
//44. 编写整型值数组排序程序(冒泡排序--升序)int a[] = {3,-9,32,77,63,-24,14,0,21,45};
// int a[] = {3,-9,32,77,63,-24,14,0,21,45};
// for (int i = 0; i<9; i++) {
// for (int j = 0; j<9-i ; j++) {
// if (a[j]>a[j+1]) {
// int temp = a[j];
// a[j]=a[j+1];
// a[j+1]=temp;
// }
// }
// }
// for (int i = 0; i<10; i++) {
// printf("%d ",a[i]);
// }
//5、(***)找出下列整型数组中最大和最小值及其所在位置i。
// int a[]={3,-9,32,77,63,-42,14,0,21,45};
// int max =-100,min =100,maxIndex=0,minIndex=0;
// for (int i = 0; i<10; i++) {
// if(max<a[i]){
// max=a[i];
// maxindex=i;
// }else if(min>a[i]){
// min=a[i];
// minindex=i;
// }
// }
// printf("max=%d在第%d位 min=%d在第%d位\n",max,maxIndex,min,maxIndex);
//
//6、(*)把str1, str2, str3合并到result数组中。
// char result[50] = {0};
// char str1[] = "Lanou ";
// char str2[] = "23_class ";
// char str3[] = " is niu best!";
// 结果:“Lanou 23_class is niu best!
//
// char result[50]={0};
// char str1[]="Lanou ";
// char str2[]="23_class ";
// char str3[]="is niu best!";
// strcat(str1, str2);
// strcat(str1, str3);
// strcat(result,str1);
// printf("%s\n",result );
//
return 0;
}
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 数组
- 15-11-16 Eclipse 操作菜单汉译之 Help [帮助]
- 为你详解安装arm-linux-gcc
- frame bounds center
- source insight 注册码
- 没有躲过的坑--string中的c_str()陷阱
- 数组
- 利用Aspose.Word控件实现Word文档的操作
- 进程间通信 SharedMemory 最后例子没看明白
- 九度oj-1042-Coincidence
- (imooc)sublime中的命令模式
- HDU3549 网络流入门题(Dinic)
- Leetcode Linked List Cycle
- toolButton
- javax.swing.Timer 的用法例程