当前位置:网站首页>Chapter 5 programming

Chapter 5 programming

2020-11-08 23:53:00 Cx330

**2   Print values **

#include<stdio.h>

int main()
{
    int a, b;
    printf(" Enter the number you want :       ");
    scanf("%d", &a);
    b = a;
    while (b <= a + 10)
    {
        printf("%d\n", b);
        b++;
    } 
	}
	````
	
**	3   Day to week **

#include <stdio.h>
int main()
{
    int a, b, c;
    printf(" Please enter the number of days :");
    scanf("%d", &a);
    printf("%d God =%d Zhou %d God \n", a, a / 7, a % 7);
    return 0;
	}
	````
**	4   Height shift  **
	#include <stdio.h>
#define a 30.48
#define b 2.54
int main()
{
    int feet;
    float inches, cm;
    printf("CONVERT CM TO INCHES!\n");
    printf("Enter the hight in centimeters:");
    scanf("%f", &cm);
    while (cm > 0) {
        feet = cm / a;
        inches = (cm - feet * a / b);
        printf("%.1fcm=%dfeet,%.1f inches\n", cm, feet,inches);
        printf("Enter the hight in centimeters(<=0 to quit):");
        scanf("%f", &cm);
    }
    printf("PROGRAM EXIT!\n");
    return 0;
}
5  To make money 

#include<stdio.h>
int main()
{ 
int a, b; printf(" Enter the money you earn in a day :\n");
scanf("%d", &a); 
printf(" Enter the number of days :\n"); 
scanf("%d", &b); 
printf(" I've made a lot of money %d element ", a * b);
}
**8   Modular operation **
#include<stdio.h>
int main(int argc, char* argv[])
{
	int first, second;
	printf("This program computers moduli.\n");
	printf("Enter an integer to server as the second operand:");
	scanf("%d", &second);
	printf("now enter the first operand:");
	scanf("%d", &first);
	while (first > 0) {
		printf("%d %% %d is %d\n", first, second);
		printf("Enter next number for first operand:");
		scanf("%d", &first);
	}
	printf("done!\n");
	return 0;
}
#include <stdio.h>
int T(double fahrenheit);
int main(int arge, char* argv[])
{
	double input;
	printf("This program convert fahrenheit to celsius and kelvin.\n");
	printf("Enter a fahrenheit to start:");
	while (scanf("%1f",&input) == 1) {
		T(input);
		printf("Enter next fahrenheit!:");
	}
		printf("Done!\n");
		return 0;
}
int T(double fahrenheit) {
	const double FC = 32.0;
	const double CK = 273.16;
	double celsius, kelvin;
	celsius = 5.0 / 9.0 * (fahrenheit - FC);
	kelvin = celsius + CK;
	printf("%.2f.fahrenheit,equal %.2f celsius, and %.2f kelvin\n", fahrenheit, celsius,kelvin);
	return 0;
}

版权声明
本文为[Cx330]所创,转载请带上原文链接,感谢