C语言数组小程序

来源:互联网 发布:网络售彩最新消息官方 编辑:程序博客网 时间:2024/06/05 18:32

今天写了两个小程序简单的回顾一下数组概念

1.数组排序程序:


#include <stdio.h>



int main()
{
int a[5] = {0};
int i,j,tmp;

for( i= 0;i < sizeof(a) / sizeof (int);i++)
{
scanf ("%d",&a[i]);
}
   
for (i = 4 ;i > 0;i++)
{
for (j = 0;j < i;j++)
{
if(a[i] < a[j])
   { 
tmp = a[j];
a[j] = a[i];
a[i] = tmp;
   }
   }
   }

for( i= 0;i < sizeof(a) / sizeof (int);i++)
{
printf("%d",a[i]);
}

printf("\n");
return 0 ;
}


2.字符查找程序

#include <stdio.h>
#include <string.h>


void main()
{
    char str[] = "hello world";
    char *p = strchr(str, 'w');
    if ( p )
        printf("find 'w'!");
    else
        printf("not found!");
}













·
0 0
原创粉丝点击