==============================================
/* 程式檔名:test_13-37-1*/
/* 程式目的:請宣告兩個浮點數的內部變數,並輸出兩數的和*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140731*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Pause(const char* message);
int main(int argc, char *argv[])
{
float i=1.12;
float j=2.21;
printf("%.2f\n",i+j);
Pause("按 ENTER 繼續");
return EXIT_SUCCESS;
}
void Pause(const char* message)
{
printf("%s \n", message);
rewind(stdin);
getchar();
}
==============================================
/* 程式檔名:test_13-37-2*/
/* 程式目的:請宣告兩個浮點數的內部變數,並輸出兩數的和*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140731*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Pause(const char* message);
int main(int argc, char *argv[])
{
static int i=10;
static int j=5;
printf("%d\n",i-j);
Pause("按 ENTER 繼續");
return EXIT_SUCCESS;
}
void Pause(const char* message)
{
printf("%s \n", message);
rewind(stdin);
getchar();
}
==============================================
/* 程式檔名:test_13-37-3*/
/* 程式目的:請宣告兩個浮點數的外部變數,以及一個內部變數,寫一個比大小的函式,最後由大到小輸出*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140731*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Pause(const char* message);
float com(float,float,float);
float i=1.21;
float j=3.34;
int main(int argc, char *argv[])
{
float k=2.12;
float b1,b2;
com(i,j,k);
Pause("按 ENTER 繼續");
return EXIT_SUCCESS;
}
float com(float a,float b,float c)
{
float max,mid,min;
float big,sma;
if(a>b)
{
big=a;
sma=b;
}
else
{
big=b;
sma=a;
}
if(big>c)
{
max=big;
if(c>sma)
{
mid=c;
min=sma;
}
else
{
mid=sma;
min=c;
}
}
else
{
max=c;
mid=big;
min=sma;
}
printf("大中小排序 %f > %f > %f \n",max,mid,min);
}
void Pause(const char* message)
{
printf("%s \n", message);
rewind(stdin);
getchar();
}
==============================================
/* 程式檔名:test_13-37-4*/
/* 程式目的:請宣告兩個整數的暫存器變數,並輸出最大公因數*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140731*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Pause(const char* message);
float com(float,float,float);
int main(int argc, char *argv[])
{
register int num1=54,num2=48;
register int a,b,c;
c=num1%num2;
b=num2;
while(c!=0)
{
a=b;
b=c;
c=a%b;
}
printf("%d 與 %d 的最大公因數是 %d",num1,num2,b);
Pause("按 ENTER 繼續");
return EXIT_SUCCESS;
}
void Pause(const char* message)
{
printf("%s \n", message);
rewind(stdin);
getchar();
}
==============================================
/* 程式檔名:test_13-37-5*/
/* 程式目的:定義一個整數的外部變數,由鍵盤輸入,在函式中計算立方值,然後顯示再main輸出結果*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140731*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Pause(const char* message);
int sai(int);
int a;
int main(int argc, char *argv[])
{
printf("請輸入一個數字:");
scanf("%d",&a);
printf("立方值: %d \n",sai(a));
Pause("按 ENTER 繼續");
return EXIT_SUCCESS;
}
int sai(int a)
{
return a*a*a;
}
void Pause(const char* message)
{
printf("%s \n", message);
rewind(stdin);
getchar();
}
==============================================
/* 程式檔名:test_13-37-6*/
/* 程式目的:請計算1加到100的結果,累加運算在函式中完成,但限制函式中不可以使用迴圈*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140731*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Pause(const char* message);
int suma(int *);
int main(int argc, char *argv[])
{
int a=1;
int i,j=0;
for(i=1;i<=100;i++)
{
j=suma(&a);
}
printf("%d\n",j);
Pause("按 ENTER 繼續");
return EXIT_SUCCESS;
}
int suma(int *b)
{
static int sum=0;
sum=sum+(*b)++;
return sum;
}
void Pause(const char* message)
{
printf("%s \n", message);
rewind(stdin);
getchar();
}
==============================================
/* 程式檔名:test_13-37-7*/
/* 程式目的:請計算1加到100的結果,累加運算在函式中完成,但限制函式中不可以使用迴圈*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140731*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 10
void Pause(const char* message);
int sam[SIZE]={1,2,3,4,5,6,7,8,9,10};
int main(int argc, char *argv[])
{
int j;
for(j=0;j<10;j++)
{
printf("%d ",sam[j]);
}
Pause("按 ENTER 繼續");
return EXIT_SUCCESS;
}
void Pause(const char* message)
{
printf("%s \n", message);
rewind(stdin);
getchar();
}
==============================================
/* 程式檔名:test_13-37-8*/
/* 程式目的:利用內部靜態變數,可以持續累加使用者從鍵盤輸入的數字,值到輸入0結束,再main讀入鍵盤輸入的數字,並在另一函式中作累加*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140731*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 10
void Pause(const char* message);
int sum(int);
int main(int argc, char *argv[])
{
int n=0,s=0;
do
{
printf("請輸入數字:");
scanf("%d",&n);
s=sum(n);
printf("\n");
}while(n!=0);
printf("%d\n",s);
Pause("按 ENTER 繼續");
return EXIT_SUCCESS;
}
int sum(int a)
{
static int add=0;
add=add+a;
return add;
}
void Pause(const char* message)
{
printf("%s \n", message);
rewind(stdin);
getchar();
}
==============================================
/* 程式檔名:test_13-37-9*/
/* 程式目的:試寫一程式,判斷由鍵盤輸入的數字是正或負數 奇數或偶數,並將結果印出*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140731*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void Pause(const char* message);
extern int n;
int main(int argc, char *argv[])
{
int n;
printf("請輸入一個數字:");
scanf("%d",&n);
if(n==0)
{
printf("此數為0\n");
}
else if(n%2==0)
{
printf("偶數\n");
if(n>0)
{
printf("正數\n");
}
else
{
printf("負數\n");
}
}
else
{
printf("奇數\n");
if(n>0)
{
printf("正數\n");
}
else
{
printf("負數\n");
}
}
Pause("按 ENTER 繼續");
return EXIT_SUCCESS;
}
void Pause(const char* message)
{
printf("%s \n", message);
rewind(stdin);
getchar();
}
==============================================
/* 程式檔名:test_13-37-10*/
/* 程式目的:將原本放入堆疊中的字母a,b,c,d,e改成用一個字元陣列"I will be back"來做*/
/* 程式設計:蘇彥儒*/
/* 完成日期:20140731*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFSIZE 255
char pop(void);
void push(char);
void dump(void);
static char stack[BUFSIZE];
static int sp=0;
void Pause(const char* message);
int main(int argc, char *argv[])
{
int i;
char c;
char str[14]={'I',' ','w','i','l','l',' ','b','e',' ','b','a','c','k'};
puts("Pushing...");
for(i=0;i<14;i++)
{
push(str[i]);
printf("放進 %c ",str[i]);
dump();
}
puts("\n Poping...");
for(i=0;i<14;i++)
{
c=pop();
printf("取出 %c ",c);
dump();
}
Pause("按 ENTER 繼續");
return EXIT_SUCCESS;
}
void push(char s)
{
if(sp<BUFSIZE)
stack[sp++]=s;
else
printf("ERROR: stack full \n");
}
char pop(void)
{
if(sp<BUFSIZE)
return (stack[--sp]);
else
printf("ERROR: stack empty \n");
return EXIT_SUCCESS;
}
void dump(void)
{
int i;
printf("堆疊內容");
if(sp>0)
for(i=sp-1;i>=0;i--)
printf("%c ",stack[i]);
else
printf("EMPTY");
printf("\n");
}
void Pause(const char* message)
{
printf("%s \n", message);
rewind(stdin);
getchar();
}
==============================================
沒有留言:
張貼留言