C Week 1 Simple Calculation program

Source: Internet
Author: User

    • 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 >
  1. Can only consist of letters, numbers, underscores, numbers do not appear in the first place.
  2. c keyword cannot be used as a variable name
  3. 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

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.