/*(1)某市不同車牌的出租車3公裡的起步價和計費分別為:夏利7元/公裡,3公裡以外2.1元/公裡;富康8元/公裡,3公裡以外2.4元/公裡;桑塔納9元,3公裡以外2.7元/公裡。編程:從鍵盤輸入乘車的車型及公裡數,輸出應付的車資。*/
/*
#include<stdio.h>
void xiali(double *x);
void fukang(double *x);
void sangtana(double *x);
void main(){
double m,*x;
int n;
printf("請輸入行駛的公裡數:");
scanf("%lf",&m);
x=&m;
printf("車型是(夏利為1,富康為2,桑塔納為3:");
scanf("%d",&n);
switch(n){
case 1 :xiali(x);break;
case 2 :fukang(x);break;
case 3 :sangtana(x);break;
}
printf("總價格為:%.2lf\n",*x);
}
void xiali(double *x){
double a;
a=*x;
if(a<=3)
*x=7*a;
else
*x=7*3+2.1*(a-3);
}
void fukang(double *x){
double a;
a=*x;
if(a<=3)
*x=8*a;
else
*x=8*3+2.4*(a-3);
}
void sangtana(double *x){
double a;
a=*x;
if(a<=3)
*x=9*a;
else
*x=9*3+2.7*(a-3);
}
*/
/*Write a program that asks the user to type in two integer values at the terminal. Test these two number to determine if the first is evenly divisible by the second, and then display an appropriate message at the terminal.*/
/*
#include<stdio.h>
int panduan(int x,int y);
void main(){
int x,y;
int m;
printf("請輸入兩個要判斷的數:");
scanf("%d %d",&x,&y);
m=panduan(x,y);
if(m==0)
printf("%d不能整除%d\n",x,y);
else
printf("%d能整除%d\n",x,y);
}
int panduan(int x,int y){
int flat=0;
if(x%y==0)
flat=1;
return flat;
}
*/
/*編寫程序。功能:從讀入的整數數據中,統計大於零的整數個數和小於零的整數個數。用輸入零來結束輸入,程序中用變量i統計大於零的整數個數,用變量j統計小於零的整數個數。*/
/*
#include<stdio.h>
int duru(int s[],int n);
void panduan( int s[],int n);
#define N 20
void main(){
int x;
int shuju[N];
x=duru(shuju,N);
panduan(shuju,x);
printf("大於零的整數個數是:%d,小於零的整數個數是:%d\n",shuju[0],shuju[1]);
}
int duru(int s[],int n){
int i;
printf("請輸入一串數字:");
for(i=0;i<n ;i++){
scanf("%d",&s[i]);
if(s[i]==0)
break;
}
return i;
}
void panduan( int s[],int n){
int m,i,j;
for(m=0,i=j=0;m<n;m++){
if(s[m]>0)
i++;
else
j++;
}
s[0]=i;
s[1]=j;
}
*/
/*功能:以每行5個數來輸出300以內能被7或17整除的偶數,並求出其和。*/
/*
#include<stdio.h>
int panduan(int s[],int n);
#define N 300
void main(){
int shu[N],i,j,sum=0;
j=panduan(shu,N);
for(i=0;i<j;i++){
printf("%4d",shu[i]);
if((i+1)%5==0 && i!=0)
printf("\n");
sum +=shu[i];
}
printf("\n%4d\n",sum);
}
int panduan(int s[],int n){
int i,j=0;
for(i=0;i<n;i++)
if(i%2==0)
if(i%7==0 || i%17==0)
s[j++]=i;
return j-1;
}
*/
/*分別求出一批非零整數中的偶數、奇數的平均值,用零作為終止標記。*/
/*
#include<stdio.h>
int duru(int s[],int n);
void panduan( int s[],int n);
#define N 20
void main(){
int x;
int shuju[N];
x=duru(shuju,N);
panduan(shuju,x);
printf("偶數的平均值是:%.2f,奇數的平均值是:%.2f\n",(float)shuju[0]/(float)shuju[1],(float)shuju[2]/(float)shuju[3]);
}
int duru(int s[],int n){
int i;
printf("請輸入一串數字:");
for(i=0;i<n ;i++){
scanf("%d",&s[i]);
if(s[i]==0)
break;
}
return i;
}
void panduan( int s[],int n){
int m,i,j,sum1=0,sum2=0;
for(m=0,i=j=0;m<n;m++){
if(s[m]%2==0){
i++;
sum1 +=s[m];
}
else{
j++;
sum2 +=s[m];
}
}
s[0]=sum1;
s[1]=i;
s[2]=sum2;
s[3]=j;
}
*/
/*計算並輸出500以內最大的10個能被13或17整除的自然數之和。*/
#include<stdio.h>
int panduan(int s[],int n);
#define N 500
void main(){
int shu[N],i,j,sum=0;
j=panduan(shu,N);
for(i=j;i>j-10;i--){
printf("%4d",shu[i]);
sum +=shu[i];
}
printf("\n%4d\n",sum);
}
int panduan(int s[],int n){
int i,j=0;
for(i=0;i<n;i++)
if(i%13==0 || i%17==0)
s[j++]=i;
return j-1;
}