c primer plus 第五章

//第一题 
#include<stdio.h>
#define minutes_to_hours 60
int main()
{
	int minutes;
	scanf("%d",&minutes);
	
	while(minutes>0){
		printf("Your minutes is %d hours %d minutes\n",minutes/minutes_to_hours,minutes%minutes_to_hours);
		printf("Please enter another minutes\n");
		scanf("%d",&minutes);
	}
	printf("Done!");
}
//第二题 
#include<stdio.h>
int main()
{
	int number;
	printf("Please enter a number:\n");
	scanf("%d",&number);
	
	int i;
	for(i=0;i<=10;i++){
		printf("%d ",number+i);
	}
}
//第三题 
#include<stdio.h>
#define days_to_weeks 7
int main()
{
	int days;
	printf("Please enter the days:\n");
	scanf("%d",&days);
	
	while(days>0){
		printf("%d days are %d weeks,%d days:\n",days,days/days_to_weeks,days%days_to_weeks);
		printf("Please enter another days\n");
		scanf("%d",&days);
	}
}
//第四题 
#include<stdio.h>
#define height_cm_to_height_feet 30.48
#define height_cm_to_height_inches 2.54
int main()
{
	double height_cm;
	printf("Please enter your height(centimeters):\n");
	scanf("%lf",&height_cm);
	
	int height_feet=(int)height_cm/height_cm_to_height_feet;
	double height_inches=(height_cm-height_feet*height_cm_to_height_feet)/height_cm_to_height_inches;
	while(height_cm>0){
		int height_feet=(int)height_cm/height_cm_to_height_feet;
		double height_inches=(height_cm-height_feet*height_cm_to_height_feet)/height_cm_to_height_inches;
		printf("%.1lf cm = %d feet, %.1lf inches\n",height_cm,height_feet,height_inches);
		printf("Enter a height in centimeters (<=0 to quit):\n");
		scanf("%lf",&height_cm);
	}
	printf("bye");
}
//第五题 
#include<stdio.h>

int main()
{
	int cnt, sum, n;
	sum=0;
	cnt=0;
	
	printf("How many days dou you want to work?\n");
	scanf("%d",&n);
	while(cnt++<n)
		{
			sum=sum+cnt;
		}
	printf("sum=%d\n",sum);
}
//第六题 
#include<stdio.h>

int main()
{
	int cnt, sum, n;
	sum=0;
	cnt=0;
	
	printf("How many days dou you want to work?\n");
	scanf("%d",&n);
	while(cnt++<n)
		{
			sum=sum+cnt*cnt;
		}
	printf("sum=%d\n",sum);
}
//第七题 
#include<stdio.h>

void cube(double number);
int main()
{
	printf("Please enter a number in double:\n");
	double number;
	scanf("%lf",&number);
	cube(number);
}
void cube(double number)
{
	printf("The cube of this number is %lf",number*number*number);
}
//第八题 
#include<stdio.h>

int main()
{
	int second_operand;
	int first_operand;
	printf("This program computes moduli.\n");
	printf("Enter an integer to serve as the second operand: ");
	scanf("%d",&second_operand);
	printf("Now enter the first operand: ");
	scanf("%d",&first_operand);
	
	while(first_operand>0){
		printf("%d %% %d is %d",first_operand,second_operand,first_operand%second_operand);
		printf("\nEnter next number for first operand (<= 0 to quit): ");
		scanf("%d",&first_operand);
	}
	
	printf("Done!");
	
}
//第九题 
#include<stdio.h>
void Temperaturs(double temperatur);
int main()
{
	printf("Plesae enter a Fahrenheit temperatur:\n");
	double temperatur;
	
	while(scanf("%lf",&temperatur)==1){
		Temperaturs(temperatur);
		printf("Plesae enter another Fahrenheit temperatur(q to quit):\n");
	}
	printf("Done!");
}
void Temperaturs(double temperatur)
{
	const double Fahrenheit_decrease=32.0;
	const double Kelvin_increase=273.16;
	const double centigrade=5.0/9.0*(temperatur-Fahrenheit_decrease);
	const double Kelvin=centigrade+Kelvin_increase;

	printf("Fahrenheit:%.2lf centigrade: %.2lf Kelvin:%.2lf\n",temperatur,centigrade,Kelvin);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值