| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1156 人关注过本帖
标题:考考你,同时也是作业. - -!
只看楼主 加入收藏
showthesunli
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-12-3
收藏
得分:0 

#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 呵呵。

2006-12-19 16:49
huyekwok
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-12-15
收藏
得分:0 
A题目,最简单用switch语句
2006-12-19 23:34
快速回复:考考你,同时也是作业. - -!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014295 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved