Created
March 28, 2019 04:30
-
-
Save ruyut/7264df16f8a0df55aa190939146ebe31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//901-2 | |
#include<stdlib.h> | |
#include<stdio.h> | |
void exchange(double*, double*);//宣告副程式,名字叫exchange | |
//呼叫時要傳入兩個雙精浮點數的記憶體位置 | |
int main() { | |
double c, d;//宣告兩個雙精浮點數c和d | |
printf("請輸入兩個浮點數(數字跟數字中間請以空白間隔)");//列印文字 | |
scanf("%lf %lf", &c, &d);//讓使用者輸入兩個數字 | |
printf("c:%lf d:%lf\n", c, d);//列印變數 | |
exchange(&c, &d);//呼叫副程式,並且傳入兩個雙精浮點數的記憶體位址 | |
printf("c:%f d:%f\n", c, d);//列印變數 | |
system("PAUSE");//等待使用者按下任意按鍵 | |
return 0;//跳出 | |
} | |
void exchange(double* c, double* d) {//副程式exchange,呼叫時要傳入兩個變數的記憶體位址 | |
double ch;//宣告雙精浮點數 | |
ch = *c;//ch=c的記憶體位址 | |
*c = *d;//c的記憶體位址=d的記憶體位址 | |
*d = ch;//d的記憶體位址=ch(原本c的記憶體位址) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment