#include<stdio.h>
int main()
{
int a(char c);
int hua(char a,int b,int c);
float power(float a,int b);
void to_base_n(float f,int n);
char chose,c,d;
int b,f,h,j,k,e;
float g,i;
loop: printf("\nenter the operation of your choice:\na judje character b printf character \nc get a power d bas_n\ne exit\n");
scanf("%c",&chose);
getchar();
switch(chose)
{
case 'a':
{
printf("please typ in a character:");
scanf("%c",&c);
getchar();
b=a(c);
if(b==0) printf("this character is not a letter!!");
else printf("%d",b);
goto loop;
}
case 'b':
{
printf("please typ in a character and two intger number");
scanf("%c%d%d",&d,&e,&f);
getchar();
hua(d,e,f);
goto loop;
}
case 'c':
{
printf("please typ in two number,one is a float another is a intger");
scanf("%f%d",&g,&h);
getchar();
i=power(g,h);
printf("%f",i);
goto loop;
}
case 'd':
{
printf("please typ in two intger number");
scanf("%d%d",&j,&k);
getchar();
to_base_n(j,k);
goto loop;
}
case 'e':
{
break;
}
}
return 0;
}
int a(char c)
{
int a;
if(c>=65&&c<=90||c>=97&&c<=122)
{
a=c-64;
if(a>26){a-=32;}
}
else a=0;
return a;
}
int hua(char a,int b,int c)
{
int i,m;
for(m=1;m<=c;++m)
{
printf("\n");
for(i=1;i<=b;++i)
{ printf("%c",a); }
}
return 0;
}
float power(float a,int b)
{
int i;
float c;
c=a;
for(i=2;i<=b;i+=1)
{
a=a*c;
}
return a;
}
void to_base_n(float f,int n)
{
long a;
float b;
int c[30],i=0,j=0;
if(n>=2&&n<=10)
{
a=(int)f;
b=f-a;
while(a>=n)
{
c[i++]=a%n;
a=a/n;
}
c[i]=a;
for(j=i;j>=0;j--)
printf("%d",c[j]);
if(b!=0)
{
printf(".");
while(j<30)
{
b=b*n;
printf("%d",b);
}
}
}
else
{
printf("n out of the range\n");
}
}
偶自己写的程序,最后一个函数用的是Welton 呵呵。