早教吧 育儿知识 作业答案 考试题库 百科 知识分享

c语言的计算(电阻)请问要如何用C计算电阻的三色环如~~宗黑红==1K#include#include#includeintmain(intargc,char*argv[]){chara=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=0;intx,y,z,p;

题目详情
c 语言的计算(电阻)
请问要如何用C计算电阻的三色环
如~~宗 黑 红 ==1K
#include
#include
#include
int main(int argc, char *argv[])
{
char a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=0;
int x, y, z, p;
//explanation
printf("\nThis program is to calculate the roots of a quadratic equation.\n");
printf("a=宗 b=红 c=澄 d=黄 e=绿 f=蓝 g=紫 h=灰 i=白 j=黑\n");

//prompt for input
printf("Please choose the first colours you want:\n");
scanf(" %c", &x);
printf("Please choose the second colours you want:\n");
scanf(" %c", &y);
printf("Please choose the third colours you want:\n");
scanf(" %c", &z);
//calculation
p=(x*10+y)*pow(double(10),double(z));// 出现错误
printf("The vlaue of reisitance is %d\n", p);

system("PAUSE");
return 0;
}
我的答案是要有 K M P
如~~宗 黑 红 ==1K (不是 1000)
红 澄 绿 ==2.3M
==3.6P
可否在帮我修正一下
谢谢
无法执行
出现错误
int i=-1; bool flag=false;
8 C:\Dev-Cpp\main.c `bool' undeclared (first use in this function)
可否麻烦再看一下
▼优质解答
答案和解析
下面是正文:
#include
#include
#include
int main(int argc,char *argv[])
{
char danwei[3]={'K','M','G'};
int i=-1; bool flag=false;
int x,y,z,p;
double pp;
//explanation
printf("\nThis program is to calculate the roots of a quadratic equation.\n");
printf("1=宗 2=红 3=澄 4=黄 5=绿 6=蓝 7=紫 8=灰 9=白 0=黑\n");
//prompt for input
printf("Please choose the first colours you want:\n");
scanf(" %d",&x);
printf("Please choose the second colours you want:\n");
scanf(" %d",&y);
printf("Please choose the third colours you want:\n");
scanf(" %d",&z);
//calculation
if(x9) { printf("input x error!"); return -1; }
if(y9) { printf("input y error!"); return -1; }
if(z9) { printf("input z error!"); return -1; }
while(z>=3 && i=1000.0 && i