IT科技

當前位置 /首頁/IT科技 > /列表

輸入三個數求最大值c語言,關於c語言三個數求最大值

你的錯誤原百因在於scanf("%d%d%d"&a,&b,&c);少了一個逗號,應該是scanf("%d%d%d",&a,&b,&c);以下度是三個任意數求輸出最大值最小值版正確的代碼:擴展權資料:用另外一種方法求三個任意數求輸出最大值最小值#include <iostream>using namespace std;int main(){int num1,num2,num3,max,min;cout<<"任意輸入三個整數:";cin>>num1>>num2>>num3;if(num1>num2){max=num1;min=num2;}else{max=num2;min=num1;}if(max>num3){max=max;}else{max=num3; }if(min>num3){min=num3;}else{min=min;}cout<<"max="<<max<<endl;cout<<"min="<<min<<endl;return 0;},求三個任意數的最大最小值最簡單的方百法就是通過if語句來實現。具體的實現方法可度以參考如下程序段:double a, b, c, max, min;scanf("%f%f%f", &a, &b, &c); // 接收用户輸入的三個數max = a;  // 初始最大值為aif(b>a && b>c)  // 如果版b>a並且b>c,則最大值為b    max = b;if(c>a && c>b)  // 如果c>a並且c>b,則最大值為c    max = c;printf("最大值為:%lf", max);min = a; // 初始最小權值為aif(b<a && b<c) // 如果b<a並且b<c,則最小值為b    min = b;if(c<a && c<b) // 如果c<a並且c<b,則最小值為c    min = c;printf("最小值為:%lf", min);,1.你的scanf語句好像少了逗號 應該是scanf("%d,%d,%d",e799bee5baa6e79fa5e98193e59b9ee7ad9431333236393039&a,&b,&c); // 輸入時候也要有逗號 像這樣:2,4,1回車2.#####另一種寫法. #include<stdio.h> void main() { int a,b,c,max,min; printf("input 3 number:\n"); scanf("%d%d%d",&a,&b,&c); if(a>b) max=a; else max=b; if(max<c) max=c; if(a>b) min=b; else min=a; if(min>c) max=c; printf("the max is %d\n",max); printf("the min is %d\n",min); } 3.######最簡單的寫法 void main() { int a,b,c,max,min; printf("input 3 number:\n"); scanf("%d%d%d",&a,&b,&c); max = a>b?a>c?a:c:b>c?:b:c; min = a<b?a<c?a:c:b<c?:b:c; printf("the max is %d\n",max); printf("the min is %d\n",min); }本回答被提問者採納,#include<stdio.h> void main() { int a,b,c,max,min; // 半角來分自號百度 ;printf("input 3 number:\n"); // 半角分號 ;scanf("%d%d%d"&a,&b,&c); // 缺逗知號,半角分號 ;//更正道為: scanf("%d%d%d",&a,&b,&c);max=a; min=b; if(a<b) { max=b; min=a; } if(c>max) { max=c; } if(c<min) { min=c; } printf("the max is %d\n",max); printf("the min is %d\n",min); },scanf("%d%d%d"&a,&b,&c); 他的格式是scanf(" ",& )所以你缺少了個逗號啊www.51dongshi.com防採集。

有沒有想要了解C語言的小夥伴呢?下面就讓我們一起來看看關於c語言三個數求最大值_輸入三個數求最大值c語言吧

#include<stdio.h>int main(){int a,b,c;

工具/材料

vc6.0編程軟件、c語言

#include <stdio.h>main (){ double a,b,c,m;

方法一:關於c語言三個數求最大值_輸入三個數求最大值c語言代碼

正確代碼:#include<stdio.h>int max(int a,int b,i

我們首先需要在vc6.0裏面編輯代碼並保存在.c文件,之後我們就可以點擊build按鈕(或者按下鍵盤F7快捷鍵)來操作。

關於c語言三個數求最大值 輸入三個數求最大值c語言

/*輸入三個整數(逗號隔開) : 34,56,12max = 56Press any k

這時候我們就可以看到在屏幕上並沒有任何錯誤error和警告等提示。

關於c語言三個數求最大值 輸入三個數求最大值c語言 第2張

我也是跟你一樣的問題,但是我發現你在運行後輸入三個具體的數時,要開啟大寫鍵盤輸入數字,不然就是第一個

這時候後我們就可以點擊按下運行按鈕(或者直接按快捷鍵Ctrl+F5)來運行。

你的錯誤原因在於scanf("%d%d%d"&a,&b,&

然後我們就可以點擊輸入45412861來進行代碼測試啦。

關於c語言三個數求最大值 輸入三個數求最大值c語言 第3張

參考代碼#include <stdio.h>int main(void) { int

然後我們就可以看到界面中貼出來的三個數求最大值c語言代碼:

#include <stdio.h>void max(int a,int b,int c

1、#include<stdio.h>main(){int a,b,c;int big;printf("點擊輸入3個數")

int max(int a, int b){return a>b?a:b;}int main(

2、scanf("%d %d %d",&a,&b,&c);if(a>=b)big=a;

程序是對的啊!如果輸入的a的值正是最大值,那麼當然應該輸出a的值啊!總之,輸入的3個數裏,哪

3、elsebig=b;if(c>big)big=c;printf("其中的最大數是%d",big);}

#include<stdio.h>int main(){int a,b,c;

關於c語言求三個數最大值_輸入三個數求最大值c語言程序

#include <stdio.h>main (){ double a,b,c,m;

1、首先我們需要依次在電腦中輸入#include<stdio.h>main(){int a,b,c;int big;printf("請輸入3個數");scanf("%d %d %d",&a,&b,&c);big=(a>b)?a:b;big=(big>c)?big:c;printf("最大數是%d",big);}這些代碼。

正確代碼:#include<stdio.h>int max(int a,int b,i

然後等到上面的代碼輸入好之後我們就可以測試運行啦,這時候電腦上就會顯示結果正確啦。

關於c語言三個數求最大值 輸入三個數求最大值c語言 第4張

/*輸入三個整數(逗號隔開) : 34,56,12max = 56Press any k

關於c語言三個數求最大值_輸入三個數求最大值c語言代碼

之後我們就可以點擊輸入#include<stdio.h>#definemax(a,b) (a>b)?a:bmain(){int a,b,c;int big;printf("請輸入3個數");scanf("%d %d %d",&a,&b,&c);big=max(max(a,b),c);printf("最大數是%d",big);}這些代碼到電腦中。

這時候我們就可以嘗試測試運行啦,電腦上就會顯示結果正確也就表示已經成功啦。

關於c語言三個數求最大值 輸入三個數求最大值c語言 第5張

參考代碼#include <stdio.h>int main(void) { int a,b,c;scanf("%d %d %d",&a,&b,&c);// 輸入3個數int max = a;//默認最大值來為a//選出a,b中的最大值if(max<b)max = b;//將前兩個中最大值與c比較,得出真正的最大值if(max < c)max = c;printf("%d",max);//輸出最大值return 0;}運行截圖分析關於我寫的參考代碼我已經加了註釋,現在源分析一下譚浩強的。void main()這種用法很古老,不建議使用.編譯器給出的錯誤提示是去掉多餘的括號,分知號和void後,通過debug後發現b和c讀取的數據不正確,解決方法是在全英文輸入環境道下降3 - 7行的代碼重新輸入。再來分析你的,C語言的三個數求最大值的話,你就可以進行比較嗎?就是比如説ABC,你可以先用a和b,然後再用a和c:,然後就哪怕只用一個if,多嵌套倆次就搞定,一般方法:#include <iostream>#include <iostream> //一般方法using namespace std;int main(){ int n1,n2,n3,max;cout<<"請您輸入三個數e5a48de588b6e799bee5baa6e997aee7ad9431333366306531:";cin>>n1>>n2>>n3;if(n1>n2 && n1>n3) max=n1;if(n2>n1 && n2>n3) max=n2;if(n3>n1 && n3>n2) max=n3;if(n1==n2&&n1==n3) max=n1;cout<<max;}#include <iostream> //指針來做,和副函數加在一起using namespace std;int main(){ void exchange(int *,int *,int *);int a,b,c,*p1,*p2,*p3,max;cout<<"請您輸入三個數:";cin>>a>>b>>c;p1=&a;p2=&b;p3=&c;exchange(p1,p2,p3);cout<<"max="<<a<<endl;}void exchange(int *q1,int *q2,int *q3){ void swap(int *,int *);if(*q1<*q2) swap(q1,q2);if(*q1<*q3) swap(q1,q3);if(*q2<*q3) swap(q2,q3);}void swap(int *pt1,int *pt2){ int temp;temp=*pt1;*pt1=*pt2;*pt2=temp;},給你一個簡短百的程特點是序,度方知法是取前兩者大道值與第三者的大值專。執行效率屬較高。#include <stdio.h>#define max(a,b) (a>b?a:b)int main(){int a,b,c;scanf("%d %d %d",&a,&b,&c);printf("%d\n",max(max(a,b),c));return 0;}本回答被網友採納,#include "stdio.h"void main(){int a,b,c,max;printf("a,b,c:");scanf("%d %d %d",&a,&b,&c);max=a;if(max<b) max=b;if(max<c) max=c;//printf("a:%d,b:%d,c:%d\n",a,b,c);printf("%d\n",max);} 最大的問題是 scanf("%d,%d,%d",&a,&b,&c);%d,%d,%d 這裏不應該加 逗號 因為這裏是格百式化輸入 你必須按照它的格式(度要不以逗號間隔,要不以空格間隔),如果按照你那問樣寫,測試數據你必須輸入,比如:1,2,3 用逗號隔開答,否則版,按照我那樣 就要用空格隔開。要不輸入進去的數據就會出現錯誤。不行你權把註釋取消看看輸入的值是什麼,#include <stdio.h>void max(int a,int b,int c);int main(void) {int i,j,k;printf("  請輸百入3個整數(數與度數之間用空格隔知開道):");scanf("%d %d %d",&i,&j,&k);max(i,j,k);return 0;}void max(int a,int b,int c){int temp;if(a<b){temp=b;b=a;a=temp;}if(a<c){temp=c;c=a;a=temp;}if(b<c){temp=c;c=b;b=temp;}printf("              輸入的3個整數中內最大值為:容%dn",a);},本回答被提問者採納,#include <stdio.h>int my_max( int , int, int ) ;void main( ){int result, x, y, z ;scanf("%d %d %d", &x, &y, &z) ;result = my_max(x , y, z) ;printf("MAX number is %d\n", result) ;}int my_max( int x, int y, int z ){int temp ;if( x > y)temp = x ;if( y > temp )temp = y ;return( temp ) ;}內容來自www.51dongshi.com請勿採集。

TAG標籤:輸入 數求 最大值 語言 #