简介:C语言实现奇偶排序(奇数在前,偶数在后) 目的:输入一个数组,使得数组中奇数在前,偶数在后。 代码: #define _CRT_SECURE_NO_WARNINGS 1#include <stdio.h>int main(){int arr[10] = {0};for (int i = 0; i <= 9; i++){scanf("%d", &arr[i]); //输入数组中的各个元素}int left = ...
=0)//奇数a[odd++]=n;//先进行odd的运用,Odd=0所以a[0]=n;odd+1elsea[even--]=n;//把偶数排到右边}//此时,假如输入10,9,8,7,6,5,4,3,2,1//这个时候,a[0]=9,a[1]=7,a[2]=5,a[3]=3,a[4]=1,odd=5
#include <stdio.h> #include<string.h> int main() { char a[100]; int i,j,k,len; gets_s(a); len= strlen(a);/*计数器:遇到'\0'停止并返回计数器值*/ f
int main(){ int arr[20] = {1,4,2,3,8,7,6,5,9,10,20,19,18,17,16,15,14,13,12,11};int tmp, i, j;for(i=0; i<20; i+=2) //i+=2即可。。同样如果认为a[1]是偶数项的话从a[0]开始 for(j=i; j<20; j+=2)if(arr[i]>arr[j])tmp =arr[i], arr[i...
include<stdio.h> void main(){ int a[10],i=0,j=0;int max1=0,max2=0,tmp=0;printf("Please input numbers: ");for(i=0;i<10;i++)scanf("%d",&a[i]);for(i=0;i<10;i++)for(j=i;j<10;j++)if( a[i]>a[j] ){ tmp =a[i];a[i]=a[j];a[j]=tmp;} for...