冒泡排序:很简单就不细说了:
#include <stdio.h> void bubbleSort(int num[],int len) { int i = 0; int j = 0; int temp = 0; for(j = 0;j<len-1;j++) { for(i = 0;i < len - j-1;i++) { if(num[i] > num[i+1]) { temp = num[i+1]; num[i+1] = num[i]; num[i] = temp; } } } } int main() { int i = 0; int num[] = {88,76,98,53,45,7,86,12,55,}; bubbleSort(num,sizeof(num)/sizeof(num[0])); for(i = 0;i<sizeof(num)/sizeof(num[0]);i++) { printf("%d ",num[i]); } return 0; }
回文判断,判断字符串和数字的,分别奥:
#include <stdio.h> #include <string.h> #include <math.h> int PalindromicNumber(int num) { int count = 0; int nst = 0; int ned = 0; int cnum = num; while(cnum) { count++; cnum = cnum/10; } if(0 != num) { nst = num/pow(10,count-1); ned = num%10; if(nst != ned) { return 0; } PalindromicNumber(num-pow(10,count-1)-ned); } return 1; } int PalindromicString(char *p, int len) { char *pst =(char*) p; char *ped = (char*)p +len; while(pst < ped) { if(*pst!=*ped) return 0; pst++; ped--; } return 1; } int main() { int num = 1234321; int num1 = 1234567; char *p = "abcdcbaa"; if(PalindromicNumber(num1)) { printf("是回文数"); } else { printf("不是回文数"); } if(PalindromicString(p, strlen(p)-1)) { printf("是回文数"); } else { printf("不是回文数"); } return 0; }
本文出自 “剩蛋君” 博客,请务必保留此出处http://memory73.blog.51cto.com/10530560/1682915
原文地址:http://memory73.blog.51cto.com/10530560/1682915