============================================# include <stdio.h>void f(void); //函数的声明 ,分号不能少。int main(void){ f(); return 0;}void f(void){ printf("abcd\n");}======================================================# include <stdio.h>//void f(void); //不能省略void g(void){ f(); //函数f()的定义放在了调用f()后面,出错,解决方法省委第二行函数前置声明}void f(void){ printf("abcd\n");}int main(void){ f(); return 0;}======================================================# include <stdio.h>bool IsPrime(int val) //C++中才有bool类型,C中没有,要把.c换成.cpp{ int i; for (i=2; i<val; i++) { if (val%i == 0) break; } if (i == val) return true; else return false; //return终止函数}int main(void){ int m; scanf("%d",&m); if (IsPrime(m)) printf("YES\n"); else printf("NO\n"); return 0;}=========================================================================# include <stdio.h>int main(void){ int val; printf("请输入你要进的楼层:"); scanf("%d",&val); switch (val) { case 1: printf("one\n"); //break; case 2: printf("two\n"); break; case 3: printf("three\n"); break; case 4: printf("four\n"); break; case 5: printf("five\n"); break; default: printf("error!\n"); break; }}//switch后面的值为程序的入口,没有break后,一直执行。=======================================================# include <stdio.h>int main(){ int i, j; for(i=0; i<3; i++) { for (j=0; j<4; j++) break;//跳出最近的一个循环 printf("what?\n"); }}=========================================================# include <stdio.h>int f(){ return 10.3;}int main(void){ int i = 89; double x = 2.2; x = f();//函数返回值类型为int printf("%lf\n",x); }======================================================# include <stdio.h>void f(void){ int i; for (i=0; i<5; i++) { printf("物价太高了\n"); break; //break终止循环,用于终止switch和循环 } printf("哎!\n");}int main(void){ f(); return 0;}==========================================================# include <stdio.h>void f(void){ int i; for (i=0; i<5; i++) { printf("物价太高了\n"); return; //return用于终止函数 } printf("哎!\n");}int main(void){ f(); return 0;}=============================================================# include <stdio.h>int main(void){ int val; int i; scanf("%d",&val); for (i=2; i<val; i++) { if (val%i == 0) break; } if (i == val) printf("yes\n"); else printf("no\n");//判断一个数是否为素数 return 0;}=================================================================# include <stdio.h>int main(){ int i; int sum = 0; int cnt = 0; float avg; for(i=1; i<101; i++) { if(i % 2 ==1) { sum += i; cnt++; } } avg = 1.0*sum / cnt;//1警告,1.0默认是double类型,可能会丢失精度 printf("cnt = %d\n",cnt); printf("sum = %d\n",sum); printf("avg = %f\n",avg);}//for和if默认只控制下一条语句==================================================================================================# include <stdio.h>main(){ int i = 032;//是零,不是O int j = 0x32;//是零,不是O printf("i = %d, j = %d\n",i,j);}================================#include<stdio.h>#include<math.h>main(){ int a = 1; int b = 5; int c = 6; double num; double x1; double x2; num = b*b - 4*a*c; if( num > 0 ) { x1 = ((-b)+sqrt(num)) / (2*a); x2 = ((-b)-sqrt(num)) / (2*a); printf("x1 = %f , x2 = %f\n",x1,x2); } else if(num = 0) { x1 = ((-b)+sqrt(num)) / (2*a); x2 = x1; printf("x1 = %f , x2 = %f\n",x1,x2); } else { printf("erro: rno answer!\n"); }}//解一元二次方程组。注意格式,书写要规范。===============================================================#include<stdio.h>main(){ int i,j,s=0; for(i=0;i<2;i++) { for(j=0;j<3;j++) { s=i+j; continue; s=10; } } printf("%d\n",s);}//两个for里面的continue跳到最近的一个for循环==============================================================#include<stdio.h>main(){ int a[3][5]={1,3,5,7,9,11,13,15,17,19,21,23,25,27,29}; printf("a:%d\n",a); printf("a+2:%d\n",a+2); printf("&a[0]:%d\n",&a[0]); printf("a[0]+3:%d\n",a[0]+3); printf("*(a+1):%d\n",*(a+1)); printf("*(a+2)+1:%d\n",*(a+2)+1); printf("*(a[1]+2):%d\n",*(a[1]+2)); printf("&a[0][2]:%d\n",&a[0][2]); printf("*(&a[0][2]):%d\n",*(&a[0][2])); printf("*(*(a+2)+1):%d\n",*(*(a+2)+1)); printf("a[1][3]:%d\n",a[1][3]); printf("a[0]:%d\n",a[0]); }//数组==================================================# include <stdio.h>main(){ int a[6]; int i,j,temp; printf("输入六个数:\n"); for(i=0;i<6;i++) { scanf("%d",&a[i]); } for(i=0;i<5;i++) { for(j=0;j<6-i-1;j++) { if(a[j]>a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } //冒泡排序 printf("冒泡排序:\n"); for(i=0;i<6;i++) { printf("%6d",a[i]); } printf("\n"); for(i=0;i<6;i++) { for(j=i+1;j<6;j++) { if(a[i]<a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } }//选择排序 printf("选择排序:\n"); for(i=0;i<6;i++) { printf("%6d",a[i]); } printf("\n");}//用冒泡和选择排序两种方式来对输入的数组进行排序。================================================================================#include<stdio.h>main(){ int i,j,a[11]; int temp,k; printf("请输入数据:\n"); for(i=0;i<10;i++) { scanf("%d",&a[i]); } printf("输入的数据为:\n"); for(i=0;i<10;i++) { printf("%4d",a[i]); } for(i=0;i<10;i++) { for(j=i+1;j<10;j++) { if(a[i]<a[j]) { temp=a[j]; a[j]=a[i]; a[i]=temp; } } } printf("排序的的数据为:\n"); for(i=0;i<10;i++) { printf("%4d",a[i]); } printf("\n"); printf("请输入一个数:\n"); scanf("%d",&k); for(i=0;i<10;i++) { if(k<a[i] && k>a[i+1]) { for(j=10;j>i+1;j--) { a[j]=a[j-1]; } a[i+1]=k; } } printf("更新后的数据为:\n"); for(i=0;i<11;i++) { printf("%4d",a[i]); } printf("\n");}//对一个一维数组进行排序,并插入一个数,并有序排列输出。============================================================================================#include<stdio.h>#define N 3#define M 4void fins(int a[][N],int b[][M]){ int i,j,k1,k2,(*p1)[N]=a; int*p2=*b; int temp; for(i=0;i<M;i++) { for(j=0;j<N;j++) { *(p2+j*M+i)=*(*(p1+i)+j); } } for(k1=0,k2=M-1;k1<k2;k1++,k2--) { for(i=0;i<N;i++) { temp=*(p2+i*M+k1); *(p2+i*M+k1)=*(p2+i*M+k2); *(p2+i*M+k2)=temp; } }}main(){ int i,j,a[][N]={1,2,3,4,5,6,7,8,9,10,11,12}; int b[N][M],(*p1)[M]=b; printf("原始数据为:\n"); for(i=0;i<M;i++) { for(j=0;j<N;j++) { printf("%6d",a[i][j]); } printf("\n"); } fins(a,b); printf("处理后(顺时针旋转90度)的数据为:\n"); for(i=0;i<N;i++) { for(j=0;j<M;j++) { printf("%6d",*(*(p1+i)+j)); } printf("\n"); } printf("\n");}//将一个二维数组中的数据顺时针旋转90度=================================================================#include<stdio.h>main(){ int a[2][4],b[4][2]; int i,j; printf("请输入8个整数:\n"); for(i=0;i<2;i++) { for(j=0;j<4;j++) scanf("%d",&a[i][j]); } printf("交换前:\n"); for(i=0;i<2;i++) { for(j=0;j<4;j++) { printf("%4d",a[i][j]);//output the number in a[][]. b[j][i]=a[i][j];//exchange to a[][] } printf("\n"); } printf("交换后:\n"); for(i=0;i<4;i++) { for(j=0;j<2;j++) { printf("%4d",b[i][j]);//output the number in b[][]. } printf("\n"); }}//将两维数组的行和列的数组互换。收获:以后用for语句必须要用大括号来理清思路。===============================================================================#include<stdio.h>main(){ int a[10],b[3]; int i,j,*p1,*p2; p1=a,p2=b; for(i=0;i<10;i++) { scanf("%d",&a[i]); } for(j=0;j<3;j++) { scanf("%d",&b[j]); } for(i=0;i<8;i++) { if(*(p1+i)==*(p2) && *(p1+i+1)==*(p2+1) && *(p1+i+2)==*(p2+2))//起初错写了多余的j变量 { *(p1+i)=0; *(p1+i+1)=0; *(p1+i+2)=0; } } for(i=0;i<10;i++) { printf("%d ",*(p1+i)); }}//输入两个数组,在第一个数组中将两个数组中连续三个相同的数给替换为0,并输出。 =========================================================================================================#include<stdio.h>void sort(int a[],int n){ int i,j,*p,t; for(i=0;i<n-1;i++) { p=a+i; for(j=i;j<n;j++) if (*p>*(a+j)) { p=a+j; } if(p!=a+i) { t=*(a+i); *(a+i)=*p; *p=t; } }}void addins(int a[],int b[],int c[],int n){ int x,y,z,i,*p1,*p2,*p3; x=y=z=0; p1=a,p2=b,p3=c; while(x<n && y<n) { if(*(p1+x)<=*(p2+y)) { *(p3+z)=*(p1+x); x++;} else {*(p3+z)=*(p2+y); y++;} z++; } if(x==n) { for(i=y;i<=n;i++) { *(p3+z)=*(p2+i); z++; } } else { for(i=x;i<=n;i++) { *(p3+z)=*(p1+x); z++; } }}main(){ int a[]={72,34,52,52,43},b[]={1453,22,11,42,53},c[10]; int *p1=a,*p2=b,*p3=c; int i; sort(a,5); for(i=0;i<5;i++) { printf("%d ",*(p1+i)); } printf("\n"); sort(b,5); for(i=0;i<5;i++) { printf("%d ",*(p2+i)); } printf("\n"); addins(a,b,c,5); for(i=0;i<10;i++) { printf("%d ",*(p3+i)); } printf("\n");}//将两个数组中的数据进行从小到大的排序,并将所有数值有序地放到另一个数组中=================================================================================================#include<stdio.h>void ain(char *,int);void about(char *,int);main(){ char a[]={'a','b','c','d','e'}; ain(&a[2],3);//from a[2] begin!!!! about(a,5);//output a[] printf("\n");}void ain(char *b,int len){ int i; for(i=0;i<len;i++) *(b+i)='@';}void about(char *b,int k){ int i; for(i=0;i<k;i++) printf("%c",*(b+i));}======================================================#include <stdio.h>#define N 50void about(int *,int);int ain(int *);main(){ int a[N],i; i=ain(a); about(a, i); printf("\n");} int ain(int *b) { int k,y; k=0; scanf("%d",&y); while(y>=5) { *(b+k)=y; k++; scanf("%d",&y); } return k; } void about(int *b,int c) { int i; for(i=0;i<c;i++) printf("%4d",*(b+i)); }=======================================#include<stdio.h>main(){ int a[5]={1,2,3,5,6}; int i,*p; for(p=a,i=0;i<=4;i++) { printf("%4d",*p); p++; } printf("\n");}===================================================#include<stdio.h>main(){ int a[5]={1,2,3,5,6}; int i; for(i=4;i>=0;i--) { printf("%4d",*(a+i)); } printf("\n");}======================================================#include<stdio.h>main(){ int a[5],i; for(i=0;i<=4;i++) { scanf("%d",a+i); } for(i=0;i<=4;i++) { printf("%d",a[i]); }}//测试用=====================================================#include<stdio.h>main(){ int i,j,a[10],temp; for(i=0;i<=9;i++) { printf("a[%d]=:",i); scanf("%d",&a[i]); } printf("刚才输入的数值分别为 :\n"); for(i=0;i<=9;i++) { printf("%d ",a[i]); } printf("\n"); for(i=0;i<=8;i++) for(j=i+1;j<=9;j++) { if(a[i]<a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } printf("排序后的数值为:\n"); for(i=0;i<=9;i++) { printf("%d ",a[i]); } printf("\n");}\\输入十个数,按大小排序后输出================================================================#include<stdio.h>main(){ int a,b; printf("please enter two number:\n"); scanf("%d,%d",&a,&b); printf("1.a=%d,b=%d\n",a,b); swap(&a,&b); printf("4.a=%d,b=%d\n",a,b);}swap(int *x ,int *y){ int temp; printf("2.a=%d,b=%d\n",*x,*y); temp=*x; *x=*y; *y=temp; printf("3.a=%d,b=%d\n",*x,*y);}}==============================================#include <stdio.h>int *f(int *p,int*t){ if(*p<*t) return t;return p;}main(){ int *a,x,y; printf("please enter two nember:"); scanf("%d,%d",&x,&y); a=f(&x,&y); printf("x=%d,y=%d,*p=%d\n",x,y,*a);}================================================#include <stdio.h>add(int *a, int *b){ int sum; sum = *a + *b; return sum;}main(){ int a,b,c; printf("Enter two number:"); scanf("%d,%d",&a,&b); c=add(&a,&b); printf("the sum is %d\n",c);}========================================#include<stdio.h>main(){ int i=1,n=11,re=1; do { re=re*(2*i-1); i++; }while(i<=6); printf("the result is %d",re);}//计算1*3*5*。。。。。11的值====================================================\#include<stdio.h>main(){ int i=1,re=1; do { re=re*i; i++; }while(i<=11); printf(" the result is %d",re);}//计算1*2*3*。。。。。11的值=====================================================#include<stdio.h>main(){ float sign=1,deno=2,sum=1; float term; do { sign=(-1)*sign; term=sign*(1/deno); sum+=term; deno++; } while(deno<=100); printf("the result is %f\n",sum);}//计算1-1/2+1/3-1/4.......1/100的值======================================================#include<stdio.h>main(){ int a; int i; printf("Please Enter an number(Must lager than 3):"); scanf("%d",&a); for(i=2;i<=(a-1);i++) { if(a%i==0) { printf("this is not the number I refer to !"); break; } else if (i == (a - 1)) printf("You are excellent - -!"); } }}//输入一个数,判断是不是素数(只能被1和自身整除)。==============================================================#include<stdio.h>#include<string.h>main(){ char a[5]; gets(a)` int i; int la; la = strlen(a); for(i=la-1;i>=0;i--) { printf("%c",a[i]); } printf(" \n"); }//输入五个字符,倒序显示==============================================================#include<stdio.h>main(){ int i,a[5]; for(i=0;i<=4;i++) { scanf("%d",&a[i]); } for(i=4;i>=0;i--) { printf("%d ",a[i]); }}//输入五个数字,空格分隔,并倒序显示================================================================#include<stdio.h>main(){ int i; char a[5]; for(i=0;i<=4;i++) { scanf("%c",&a[i]); } for(i=4;i>=0;i--) { printf("%c",a[i]); } printf("\n");}//输入五个字符,并倒序显示,注意与输入数字的区别==================================================================#include<stdio.h>main(){ int i,num; float score[100],sum,aver; sum=0; printf("please enter the number of students:"); scanf("%d",&num); for(i=0;i<num;i++) { printf("please enter the score:"); scanf("%f",&score[i]); sum+=score[i]; } aver=(float)(sum/num); printf("%f,%d",sum,num); printf("the average score is %3.2f\n",aver);}==================================================================