/*(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;
}