#include<stdio.h>#include<math.h>intOtoD(int n){int sum =0;int i =0;while(n){
sum +=(n%10)*pow(8,i++);
n /=10;}return sum;}intmain(void){int n;printf("请输入一个8进制数:\n");scanf("%d",&n);printf("刚输入的8进制数转化为十进制为\n");printf("%d",OtoD(n));}
#include<stdio.h>#include<math.h>intIsPrime(int n){int i;if(n ==1)return0;for(i =2; i <=sqrt(n); i++)if(n%i ==0)return0;return1;}voiddivide_even(int even,int*a,int*b){int i;for(i =2; i < even; i++){if(IsPrime(i)&&IsPrime(even - i))break;}*a = i;*b = even - i;}intmain(void){int n,a,b;printf("请输入一个偶数:\n");scanf("%d",&n);divide_even(n,&a,&b);printf("偶数%d可以分解成%d和%d两个素数的和",n,a,b);}
#include<stdio.h>longmod_prime(int n,int*count){long i =9;while(i%n !=0){
i = i*10+9;(*count)++;}return i;}intmain(void){int prime,count =1;long ret;printf("请输入一个素数:\n");scanf("%d",&prime);
ret =mod_prime(prime,&count);printf("素数%d能整除%d个9组成的数%ld",prime,count,ret);return0;}
#include<stdio.h>voidPrint(int n){for(int i =0; i < n; i++)printf("*");printf("\n");}intmain(void){int n;for(int i =0; i <7; i++){scanf("%d",&n);Print(n);}return0;}
#include<stdio.h>voidswap(int*a,int*b){int temp =*a;*a =*b;*b = temp;}intmain(void){int a[4]={0};int n, i =3;printf("请输入四位数字:");scanf("%d",&n);while(n){
a[i]= n%10;
a[i]+=5;
a[i--]%=10;
n /=10;}swap(&a[0],&a[3]);swap(&a[1],&a[2]);printf("加密后的数字:");for(i =0;i <4;i++)printf("%d",a[i]);return0;}
此文为本人在练习菜鸟教程C语言经典100例时所写的部分代码记录(81~100)网址为: http://www.runoob.com/cprogramming/c-100-examples.html#include&lt;stdio.h&gt;#include&lt;math.h&gt;int OtoD(int n){ int sum = 0; int i = ...