The first experimental report of C language

Source: Internet
Author: User
Tags pow

Experiment One: integer arithmetic

#include <stdio.h>intMain (void){  intb; scanf ("%d%d",&a,&B); printf ("%d +%d =%d\n", a,b,a+B); printf ("%d-%d =%d\n", a,b,a-c); printf ("%d *%d =%d\n", a,b,a*B); printf ("%d/%d =%d\n", a,b,a/B); return 0;}

Design ideas: (1) First define two functions, (2) output results.

Encountered Problems and solutions: (1) Just contact with C language, the format is not very understanding, resulting in many wrong times. (2) The big guy who asked the dorm was settled.

Experiment two: Calculate the piecewise function

#include <stdio.h>#include<math.h>intMain () {DoubleX,y,a,b,c; scanf ("%LF",&x); if(x>=0) {y=pow (x,0.5); }    Else{a=pow ((x+1),2); b=x*2; C=1/x; Y=a+b+C; } printf ("f (%.2lf) =%.2lf", x, y); return 0;}

Design ideas: (1) Define the function first, (2) Use the conditional statement if to write (3) according to the equation. (4) Output results.

Problems encountered and solutions: here to call the mathematical function, but at first do not know, how to do wrong. Asked the classmate and read a book, it solved.

Experiment three: Three numbers from large to small output

Else if(a>c) {x=c;y=a;z=b; printf ("x=%d,y=%d,z=%d", x, Y, z); }  Else  {      if(b>c) {x=a;y=c;z=b; printf ("x=%d,y=%d,z=%d", x, Y, z); }      Else{x=a;y=b;z=C; printf ("x=%d,y=%d,z=%d", x, Y, z); }  }  return

Design ideas: With If-else statement, but with a number of if-else statements, multiple comparisons, output results.

Encountered problems and solutions: here with If-else multi-composite, think for a long time have not done, to check the information, only completed. When comparing size, it's a bit complicated.

The first experimental report of C language

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.