- Installation of Dev C + +
- Basic Program Framework:
1 # include <stdio.h>23int main () {4 printf ("Hello world\ n "); \ \" "String, \ nthe newline 5return0; 6 7 }
- Variable:< variable type >< variable name >=< initial value >
- Can only consist of letters, numbers, underscores, numbers do not appear in the first place.
- c keyword cannot be used as a variable name
- Example of change:
1# include <stdio.h>2 3 intMain () {4 intPrice=0;5 6printf"Please enter the amount (yuan):");7scanf"%d",&Price );8 9 intChange = --Price ;Tenprintf"find you%d dollars", change); One A return 0; -}
Floating-point type double input%LF output%f
1 intMain () {2 3printf"Please enter the height of feet and inches separately,""as input \ "5 7\" means 5 feet 7 inches:");4 5 Doublefoot;6 Doubleinch;7 8scanf"%LF%LF",& Foot, &inch);9 Tenprintf"height is%f m \ n", ((foot+inch/ A)*0.3048)); One A return 0; -}
- Calculate Time Difference
1 intMain () {2 intHour1, minute1;3 inthour2, Minute2;4 5scanf"%d%d",&hour1,minute1);6scanf"%d%d",&hour2,minute2);7 8 intt1= hour1* -+minute1;9 intT2= hour2* -+Minute2;Ten One intt= t2-T1; Aprintf"Time difference is%d hours%d minutes", t/ -, t% -); -}
- HW:
The program reads a positive three-digit number each time, and then outputs the number in reverse order. Note that when the input number contains the end of 0 o'clock, the output should not have a leading 0. For example, enter 700 and the output should be 7.
Input format:
Each test is a 3-bit positive integer.
Output format:
The number of output reverse order.
Input Sample:
123
Sample output:
321
1#include <stdio.h>2 voidOutputintN)3 { 4 _bool sign;5 if((n%Ten) ||(sign))6 {7printf"%d", n%Ten);8sign=1;9 }Tenn/Ten? Output (n/Ten) :0; One A } - - intMainvoid) the { - intN; -scanf"%d", &n); - output (n); + return 0; -}View Code
C Week 1 Simple Calculation program