ÄÚÈÝ·¢²¼¸üÐÂʱ¼ä : 2025/3/22 18:00:45ÐÇÆÚÒ» ÏÂÃæÊÇÎÄÕµÄÈ«²¿ÄÚÈÝÇëÈÏÕæÔĶÁ¡£
scanf(%f%f%f¡±,&a,&b,&c); if (¡¾1¡¿)
if (¡¾2¡¿) printf(¡±no answer due to input error\\n¡±); else printf(¡±the single root is %f\\n¡±, - c/b); else
{ disc=b*b-4*a*c; w=2*a;
term1= -b/w;
t=abs(disc); term2=sqrt(t)/w; if (¡¾3¡¿)
printf(¡±complex root\\n real part=%f imag part =%f\\n¡±, term1,term2);
else
printf(¡±real roots\\n root1=%f root2=%f\\n¡±, term1+term2,term1-term2);
} }
12£®ÒÔϳÌÐò¸ù¾ÝÊäÈëµÄÈý½ÇÐεÄÈý±ßÅжÏÊÇ·ñÄÜ×é³ÉÈý½ÇÐΣ¬
Èô¿ÉÒÔÔòÊä³öËüµÄÃæ»ýºÍÈý½ÇÐεÄÀàÐÍ¡£ÇëÔÚ¡¾¡¿ÄÚÌîÈëÕýÈ·ÄÚÈÝ¡£
#include ¡±math.h¡± #include ¡±stdio.h¡± main() {
float a,b,c,s,area;
printf(¡±please input three edges of a triangle:¡±); scanf(¡±%f%f%f¡±,&a,&b,&c);
if (¡¾1¡¿)
{ s=(a+b+c)/2;
area=sqrt(s*(s-A*(s-B*(s-c));
printf(¡±\\nthe area of the triangle is: %f¡±,area); if ((a==b)&&(b==c))
printf(¡±µÈ±ßÈý½ÇÐΡ±); else if (¡¾2¡¿)
printf(¡±µÈÑüÈý½ÇÐΡ±): else if (¡¾3¡¿)
printf(¡±Ö±½ÇÈý½ÇÐΡ±):
else printf(¡±Ò»°ãÈý½ÇÐΡ±): }
else printf(¡±²»ÄÜ×é³ÉÈý½ÇÐΡ±)£»
}
13£®ÒÔϳÌÐòµÄ¹¦ÄÜÊÇÅжÏÊäÈëµÄÄê·ÝÊÇ·ñÊÇÈòÄê¡£ÇëÔÚ¡¾¡¿ÄÚÌîÈëÕýÈ·ÄÚÈÝ¡£
#include ¡±stdio.h¡± main() {
int year, flag;
printf(¡±please input the year to jude whether year:¡±);
scanf(¡±%d¡±,&year);
if (year@0==0) flag=1; else if (¡¾1¡¿) flag=1; else ¡¾2¡¿;
if (flag) printf(¡±%d is a leap year\\n¡±,year); else printf(¡±%d is not a leap year!\\n¡±,year); }
14£®ÒÔϳÌÐòÊǶÔÓû§ÊäÈëµÄ×Öĸ½øÐдóСдת»»¡£ÇëÔÚ¡¾¡¿ÄÚÌîÈëÕýÈ·ÄÚÈÝ¡£
#include ¡±stdio.h¡± main()
it is a leap
{
char ch;
printf(¡±please input a letter:¡±); scanf(¡±%c¡±,&ch); if (¡¾1¡¿) ch=ch+32;
else if (ch>=¡¯a¡¯ && ch<=¡¯z¡¯) ¡¾2¡¿;
printf(¡± the converted letter is: %c\\n¡±,ch); }
15£®ÒÔϳÌÐòÊǶԴӼüÅÌÊäÈëµÄÈκÎÈý¸öÕûÊý£¬Çó³öÆäÖеÄ×îС
Öµ¡£ÇëÔÚ¡¾¡¿ÄÚÌîÈëÕýÈ·ÄÚÈÝ¡£ #include ¡±stdio.h¡± main() {
int a,b,c,min;
printf(¡±please input three numbers:¡±); scanf(¡±%d%d%d¡±,&a,&b,&c); if (¡¾1¡¿) min=b; else
min=a; if (min>c)
¡¾2¡¿;
printf(¡±min=%d\\n¡±,min); } 16£®ÒÔϳÌÐòʵÏÖÕâÑùµÄ¹¦ÄÜ£ºÉ̵êÂôÎ÷¹Ï£¬10½ïÒÔÉϵÄÿ½ï0.15
Ôª£¬8½ïÒÔÉϵÄÿ½ï0.3Ôª£¬6½ïÒÔÉϵÄÿ½ï0.4Ôª£¬4½ïÒÔÉϵÄÿ½ï0.6Ôª£¬4½ïÒÔϵÄÿ½ï0.8Ôª£¬´Ó¼üÅÌÊäÈëÎ÷¹ÏµÄÖØÁ¿ºÍ¹Ë¿ÍËù¸¶Ç®Êý£¬ÔòÊä³öÓ¦¸¶¿îºÍÓ¦ÕÒÇ®Êý¡£ÇëÔÚ¡¾¡¿ÄÚÌîÈëÕýÈ·ÄÚÈÝ¡£
#include ¡±stdio.h¡± main() {
float weight, money, rate;
printf(¡±the paid money of the client is:¡±); scanf(¡±%f¡±,&money);
printf(¡±the weight of the watermelon is:¡±); scanf(¡±%f¡±,&weight); if (¡¾1¡¿)
rate=0.15; else if (weight>8) rate=0.3; else if (weight>6) ¡¾2¡¿; else if (weight>4)
rate=0.6;
¡¾3¡¿
rate=0.8;
printf(¡±the account payable of the watermelon is %f\\n¡±,
weight*rate);
printf(¡±the change for client is %f\\n¡±,money-weight*rate); }
17£®ÒÔϳÌÐò¶ÎµÄÔËÐнá¹ûÊÇ________¡£
#include ¡±stdio.h¡± main() {
char ch1=¡¯a¡¯,ch2=¡¯A¡¯; switch (ch1) { case ¡¯a¡¯:
switch (ch2)
{case ¡¯A¡¯: printf(¡±good!\\n¡±); break;
case ¡¯B¡¯: printf(¡±bad!\\n¡±); break; }
case ¡¯b¡¯: printf(¡±joke\\n¡±); } }
18£®¸ù¾ÝÒÔϺ¯Êý¹Øϵ£¬¶ÔÊäÈëµÄÿ¸öxÖµ£¬¼ÆËã³öÏàÓ¦µÄyÖµ¡£
ÇëÔÚ¡¾¡¿ÄÚÌîÈëÕýÈ·ÄÚÈÝ¡£
x y x<0 0 0<=x<1x 0 10<=x<10 20 20<=x<-0.5x+240 0 #include ¡±stdio.h¡± main() {
int x, rate;
float y;
printf(¡±please input the value of x:¡±); scanf(¡±%d¡±,&x); if (¡¾1¡¿) rate= -1; else rate=¡¾2¡¿; switch(rate)
{ case ¨C1: y=0; break;
case 0: y=x; break; case 1: y=10; break; case 2:
case 3: y=-0.5*x+20; break; default: y= -2;