C Primer Plus 5th operator, expression, and statement programming exercises

Source: Internet
Author: User

1.

#include <stdio.h>Const intS_per_m = -;intMainvoid){    intmin, hour, lmin; printf ("Please enter the number of minutes: \ n"); scanf ("%d", &min);  while(Min >0) {Hour= Min/s_per_m; Lmin= min%s_per_m; printf ("%d minutes =%d hours,%d minutes \ n", Min, hour, lmin); scanf ("%d", &min); } printf ("done!\n"); return 0;}

2.

#include <stdio.h>intMainvoid){    intnum, i =-1; printf ("Please enter a number: \ n"); scanf ("%d", &num); printf ("output is: \ n");  while(I++ <Ten) printf ("%d", Num +i); return 0;}

3.

#include <stdio.h>intMainvoid){    intDays , week, ldays; printf ("Please enter the number of days: \ n"); scanf ("%d", &Days );  while(Days >0) {Week= days/7; Ldays= Days%7; printf ("%d days is%d week,%d days.\n", days, week, ldays); printf ("Please enter the number of days: \ n"); scanf ("%d", &Days ); } printf ("done!\n"); return 0;}

4.

#include <stdio.h>#defineCAST1 0.3937008#defineCAST2 12intMainvoid){    floatcm, inch; intfeet; printf ("Enter a height in centimeters:"); scanf ("%f", &cm);  while(cm >0) {feet= (int) (CM * CAST1)/CAST2; Inch= cm * Cast1-feet *CAST2; printf ("%.1f cm =%d feet,%.1f inches\n", cm, feet, inch); printf ("Enter a height in centimeters (<= 0 to quit):"); scanf ("%f", &cm); } printf ("bye\n"); return 0;}

5.

#include <stdio.h>intMainvoid){    intcount, sum, number; Count=0; Sum=0; printf ("Please enter a number: \ n"); scanf ("%d", &Number );  while(Count++ <Number ) Sum+=count; printf ("1 + 2 + 3 + ... +%d =%d\n", number, sum); return 0;}

6.

#include <stdio.h>intMainvoid){    intcount, sum, number; Count=0; Sum=0; printf ("Please enter a number: \ n"); scanf ("%d", &Number );  while(Count++ <Number ) Sum+ = Count *count; printf ("the sum of the squares of the 1~%d is:%d\n", number, sum); return 0;}

7.

#include <stdio.h>voidPrintfloatFL);intMainvoid){    floatN; printf ("Please enter a number of type float: \ n"); scanf ("%f", &N);    print (n); return 0;}voidPrintfloatFL) {printf ("%.2f's Cube is:%.2f\n", FL, FL * FL *FL);}

8.

#include <stdio.h>voidTemperatures (Doubledb);intMainvoid){    DoubleFahrenheit; printf ("Please enter a temperature of Fahrenheit: \ n");  while(SCANF ("%LF", &Fahrenheit))        {temperatures (Fahrenheit); printf ("Please enter a temperature of Fahrenheit: \ n"); } printf ("bye\n"); return 0;}voidTemperatures (Doubledb) {    Const DoubleCast1 =1.8; Const DoubleCast2 =32.0; Const DoubleCast3 =273.16; DoubleCelsius, Kelvin; Celsius= Cast1 * db +Cast2; Kelvin= Celsius +Cast3; printf ("Fahrenheit temperature%.2f\n------> Celsius temperature is%.2f\n------> Absolute temperature is%.2f\n", DB, Celsius, Kelvin);}

C Primer Plus 5th operator, expression, and statement programming exercises

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.