0

## 想請教C語言T/6G4XU04VU6的問題

#include <stdio.h>
#include <stdlib.h>

int max(int x, int y, int z)
{
int r = x;
if(y > r)
r = y;
if(z > r)
r = z;
return r;
}
int min(int x, int y, int z)
{
int r = x;
if(y < r)
r = y;
if(z < r)
r = z;
return r;
}
int main() {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
printf("The maximum integer is %d\n", max(a, b, c));
int d , e , i ;
for(d=1 ; e<=max(a, b, c)2-1 ; e++)
{
if (a % 2 !=0)
{
for(i=0 ; i<((max(a, b, c)2-1)-d)/2 ; i++)
printf(" ");
for(e=1 ; e<=d ; e++)
printf("
");
}
else
printf("\n");
}
printf("\n");
}

#include <stdio.h>

int main(void) {
float price,total = 0;
while(price != -1){
scanf("%f", &price);
if(price >= 500)
total += price
0.5;
else if(price >= 400)
total += price0.6;
else if(price >= 300)
total += price
0.7;
else if(price >= 200)
total += price0.8;
else if(price >= 100)
total += price
0.9;
else
total += price;
}
printf("The summery is %.2f\n",total+1);
printf("The Average price is %.2f\n",(total+1)/5);
return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
int a, b, c, D, spD, x1, x2;
printf("請輸入一元二次方程式的三個係數，如 aX^2 + bX + c = 0\n以a b c表示\n");
while(scanf("%d %d %d", &a, &b ,&c)==3){
D=(bb) - (4ac);
if(D>0){
spD=sqrt(D);
x1= (-b+spD)/(2
a);
x2= (-b-spD)/(2a);
if (x1==x2){
printf("此一元二次方程式的解為兩相等實根(重根) X=%d\n", x1);
}
else {
printf("此一元二次方程式的解為兩相異實根 X=%d或%d\n", x1, x2);
}
}
else if(D==0){
x1= (-b)/(2
a);
if(b==0){
printf("此一元二次方程式的解為兩相等實根 X=0");
}
else{
printf("此一元二次方程式的解為兩相等實根(重根) X=%d\n", x1);
}
}
else{
printf("此一元二次方程式無實數解\n");
}
}
printf("請輸入正確的三項係數");
system("PAUSE");
return 0;
}

wrxue iT邦新手 1 級 ‧ 2020-08-20 17:03:27 檢舉

float discount(int x)

### 1 個回答

1

iT邦大神 1 級 ‧ 2020-08-20 17:31:59

#include <stdio.h>
#include <stdlib.h>

int max(int x, int y, int z)
{
int r = x;
if(y > r)
r = y;
if(z > r)
r = z;
return r;
}
int min(int x, int y, int z)
{
int r = x;
if(y < r)
r = y;
if(z < r)
r = z;
return r;
}
int main() {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
printf("The maximum integer is %d\n", max(a, b, c));
int d , e , i ;
for(d=1 ; d<=max(a, b, c) ; d++)
{
//if (a % 2 !=0)
//{
for(i=0 ; i<((max(a, b, c)*2-1)-((d-1)*2+1))/2 ; i++)
printf(" ");
for(e=1 ; e<=((d-1)2+1); e++)
printf("
");
printf("\n");
//}
//else
//printf("\n");
}
printf("\n");
}

#include <stdio.h>
float discount(int x) {
float fret;
if(x >= 500)
fret = x0.5;
else if(x >= 400)
fret = x
0.6;
else if(x >= 300)
fret = x0.7;
else if(x >= 200)
fret = x
0.8;
else if(x >= 100)
fret = x*0.9;
else
fret = x;

return fret;
}
int main(void) {
float price,total = 0;
while(price != -1){
scanf("%f", &price);
total += discount(price);
// if(price >= 500)
// total += price0.5;
// else if(price >= 400)
// total += price
0.6;
// else if(price >= 300)
// total += price0.7;
// else if(price >= 200)
// total += price
0.8;
// else if(price >= 100)
// total += price*0.9;
// else
// total += price;
}
printf("The summery is %.2f\n",total+1);
printf("The Average price is %.2f\n",(total+1)/5);
return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int b24ac(int a, int b, int c) {
int ret;
ret = bb - 4a*c;
return ret;
}

int main(){
int a, b, c, D, spD, x1, x2;
printf("請輸入一元二次方程式的三個係數，如 aX^2 + bX + c = 0\n以a b c表示\n");
while(scanf("%d %d %d", &a, &b ,&c)==3){
// D=(bb) - (4ac);
D = b24ac(a, b, c);
if(D>0){
spD=sqrt(D);
x1= (-b+spD)/(2
a);
x2= (-b-spD)/(2a);
if (x1==x2){
printf("此一元二次方程式的解為兩相等實根(重根) X=%d\n", x1);
}
else {
printf("此一元二次方程式的解為兩相異實根 X=%d或%d\n", x1, x2);
}
}
else if(D==0){
x1= (-b)/(2
a);
if(b==0){
printf("此一元二次方程式的解為兩相等實根 X=0");
}
else{
printf("此一元二次方程式的解為兩相等實根(重根) X=%d\n", x1);
}
}
else{
printf("此一元二次方程式無實數解\n");
}
}
printf("請輸入正確的三項係數");
system("PAUSE");
return 0;
}

peter1111 iT邦新手 5 級 ‧ 2020-08-20 17:53:22 檢舉

#include <stdio.h>
#include <stdlib.h>

int max(int x, int y, int z)
{
int r = x;
if(y > r)
r = y;
if(z > r)
r = z;
return r;
}
int min(int x, int y, int z)
{
int r = x;
if(y < r)
r = y;
if(z < r)
r = z;
return r;
}
int main() {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
printf("The maximum integer is %d\n", max(a, b, c));
int d , e , i ;
for(d=1 ; d<=max(a, b, c) ; d++)
{
//if (a % 2 !=0)
//{
for(i=0 ; i<((max(a, b, c)*2-1)-((d-1)*2+1))/2 ; i++)
printf(" ");
for(e=1 ; e<=((d-1)2+1); e++)
printf("
");
printf("\n");
//}
//else
//printf("\n");
}
printf("\n");
}

peter1111 iT邦新手 5 級 ‧ 2020-08-20 18:07:29 檢舉

void print_star(int line_number); 我應該怎麼把它弄上去會比較好

#include <stdio.h>
#include <stdlib.h>

int a,b,c;

void print_star(int line_number) {
for(int i=0 ; i<((max(a, b, c)*2-1)-((line_number-1)*2+1))/2 ; i++)
printf(" ");
for(int e=1 ; e<=((line_number-1)2+1); e++)
printf("
");
printf("\n");
}
int max(int x, int y, int z)
{
int r = x;
if(y > r)
r = y;
if(z > r)
r = z;
return r;
}
int min(int x, int y, int z)
{
int r = x;
if(y < r)
r = y;
if(z < r)
r = z;
return r;
}
int main() {
// int a, b, c;
scanf("%d%d%d", &a, &b, &c);
printf("The maximum integer is %d\n", max(a, b, c));
int d , e , i ;
for(d=1 ; d<=max(a, b, c) ; d++)
{
//if (a % 2 !=0)
//{
print_star(d);
// for(i=0 ; i<((max(a, b, c)*2-1)-((d-1)*2+1))/2 ; i++)
// printf(" ");
// for(e=1 ; e<=((d-1)2+1); e++)
// printf("
");
// printf("\n");
//}
//else
//printf("\n");
}
printf("\n");
}

200元打八折，「折扣數」可能有四種寫法
(「打八折」有另一種寫法是 20% off,

``````moa = discount(200);//直接回傳答案 160
moa = 200 - discount(200);//200 - 40
moa = 200 * discount(200);//200 * 0.8
moa = 200 * (1 - discount(200));//200 * (1 - 0.2)
``````