簡單的程序設計下載:
C語言.docx
(16.85 KB, 下載次數: 5)
2017-2-17 09:22 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
1 /*一元二次方程的求解程序*/ # include <stdio.h> # include <math.h> int main(void) { inta = 1; intb = 2; intc = 1; doubledelta; double x1; doublex2; delta = b*b - 4*a*c; if(delta> 0) { x1= (-b + sqrt(delta)) / (2*a); x2 = (-b - sqrt(delta)) / (2*a); printf("兩個解,x1= %f, x2 = %f\n",x1,x2); } elseif (delta == 0) { x1= (-b) / (2*a); x2= x1; printf("唯一解,x1=x2=%f\n",x1); } else { printf("無解\n"); } return0; } 2.1 /*判斷奇偶數程序*/ #include"stdio.h" inteven(int n) { if(n%2 == 0) return1; return0; } voidmain() { int num,result; printf("請輸入一個整數:\n"); scanf("%d",&num); result=even(num); if(result==1) printf("該數為偶數\n"); else printf("該數為奇數\n"); } 2.2 /*判斷奇偶數程序*/ #include <stdio.h> main(void) { intx; printf("請輸入一個整數:\n"); scanf("%d",&x); if(x%2==0) printf("偶數\n"); else printf("奇數\n"); return 0; } C語言中常用的標準庫函數 <asset.h> <ctype.h>字符處理函數 (分類函數) <errno.h>錯誤信息 <float.h> <limits.h> <locale.h> <math.h>數學函數 <setjmp.h> <signal.h> <stdarg.h> <stddef.h>標準定義 <stdlib.h>功能函數 <stdio.h>輸入輸出函數 <string.h>字符串函數 <time.h>
|