1、
#include<stdio.h>
int divisor(int a,int b)
{ int r;
while((r=a%b)!=0)
{ a=b;
b=r;
}
return b;
}
int multiple(int a,int b)
{ int d;
d=divisor(a,b);
return a*b/d;
}
void main()
{ int a,b,c,d;
printf("intput (a,b): ");
scanf("%d,%d",&a,&b);
c=divisor(a,b);
d=multiple(a,b);
printf("\ndivisor=%d\t\tmultiple=%d",c,d);
}
2、
#include<stdio.h>
void tongji(char a[])
{ int b[3]={0,0,0},i=0;
while(a[i]!='\0')
{ if((a[i]<=90&&a[i]>=65)||(a[i]<=122&&a[i]>=97))
b[0]++;
else if(a[i]<=57&&a[i]>=48)
b[1]++;
else
b[2]++;
i++;
}
printf("zimu have: %d; shuzi have: %d; qita have: %d",b[0],b[1],b[2]);
getch();
}
void main()
{ char a[100];
printf("Please input a string: ");
gets(a);
tongji(a);
}
3、
#include<stdio.h>
int flower(int n)
{ int x=0,i,j,k;
i=(n%10);
j= (n/10%10);
k=(n/100);
x=i*i*i+j*j*j+k*k*k;
if(x==n) return 1;
else return 0;
}
void main()
{ int i,n;
printf("Please intput n: ");
scanf("%d",&n);
if(n>999||n<100)printf("Input error!!!");
else
{ for(i=100;i<n;i++)
if(flower(i))printf("%d ",i);
}getch();
}
4、
#include<stdio.h>
#define SWAP(a,b) t=b;b=a;a=t;
main()
{ float x,y,t;
printf("Enter two number (x,y): ");
scanf("%f,%f",&x,&y);
SWAP(x,y);
printf("\n\nExchanged:x=%f,y=%f",x,y);
getch();
}
5、
#include<stdio.h>
int fib(int n)
{ int p;
if(n==0) p=0;
else if(n==1) p=1;
else p=fib(n-1)+fib(n-2);
return p;
}
void main()
{ int n;
printf("Please input fib: ");
scanf("%d",&n);
printf("\n\nfibonacci=%d",fib(n));
}
6、
#include<stdio.h>
long fac(int n)
{ long f;
if(n==0) f=1;
else f=n*fac(n-1);
return f;
}
void main()
{ int m,n;
long f;
printf("Please input (m,n): ");
scanf("%ld,%ld",&m,&n);
f=fac(n+m)+fac(n);
printf("\n\nfibonacci=%ld",f);
}
7、
#include<stdio.h>
void list()
{ int i,j;
for(i=1;i<=9;i++)
{ for(j=1;j<=i;j++)
printf("%d*%d=%d ",i,j,i*j);
printf("\n");
}
}
void main()
{ list();
}
8、
#include<stdio.h>
int he(int n)
{ int i,s=0;
for(i=1;i<n;i++)
if(n%i==0)s+=i;
return s;
}
void main()
{ int i,j;
for(i=1;i<30000;i++)
{for(j=1;j<30000;j++)
if((he(i)==j)&&(he(j)==i)&&(i!=j))
printf("%d<--->%d ",i,j);
}
}
9、
#include<stdio.h>
#define max 100
struct work
{ long sid;
char name[15];
}worker[max];
int size=0;
struct work *set_list()
{ do
{ printf("\n\nPlease input (sid,name): ");
scanf("%ld,%s",&worker[size].sid,worker[size].name);
size++;
}while(worker[size-1].sid!=0);
return worker;
}
void paixu(struct work a[])
{ int i,j,k;long t;char v[15];
for(i=0;i<size-1-2;i++)
{ k=i;
for(j=i;j<size-2;j++)
if(a[i].sid>a[j].sid)k=j;
if(k!=i)
{ t=a[i].sid; a[i].sid=a[j].sid; a[j].sid=t;
strcpy(v,a[i].name);strcpy(a[i].name,a[j].name);strcpy(a[j].name,v);
}
}
for(i=0;i<=size-2;i++)
printf("sid: %ld\tname:%s\n\n",a[i].sid,a[i].name);
getch();
}
void select(struct work a[])
{ int i=0,found=1;long num;
printf("Input select sid: ");
scanf("%ld",&num);
for(i=0;i<=size-2;i++)
{ if(a[i].sid==num)
{ found=0;
printf("%ld: %s",num,a[i].name);
break;
}
}
if(found)printf("\n\nNO this sid!!!");
getch();
}
void main()
{ struct work *p;
p=set_list();
paixu(p);
select(p);
}
10、
#include<stdio.h>
float jiecheng(int n)
{ long s=1;int i;
for(i=1;i<=n;i++)
s=s*i;
return s;
}
float chengfang(float x,int n)
{ float s=1;int i;
for(i=1;i<=n;i++)
s=s*x;
return s;
}
float f(float x,int n)
{ float s=1,t=0;int i=1,j=-1;
for(i=1;i<=n;i++)
{ t=j*chengfang(x,2*i)/jiecheng(2*i);
s+=t;
j=j*j;
}
return s;
}
main()
{ float s1=0,s2=0,s3=0,s4=0,x=5.6;int n=7;
s1=f(x,n);
s2=f(x+2.3,n);
s3=f(x-3.2,n+3);
s4=s1/(s2+s3);
printf("%f",s4);
getch();
}