Introduction to algorithmic competition the first chapter of the introduction of programming exercises

Source: Internet
Author: User
Tags mathematical functions pow

Exercise 1-1 average (average)
Enter three numbers, output their average, and keep 3 decimal places.

#include <stdio.h>int  main () {    double  A, B, C;    scanf ("%lf%lf%lf", &a, &b, &c);    printf ("%.3lf", (a+b+c)/3);     return 0 ;}

Exercise 1-2 temperature (temperature)
Input Fahrenheit temperature F, output the corresponding Celsius temperature C, reserved 3 decimal places. Tip: C=5 (f-32)/9.

#include <stdio.h>int  main () {    double  F;    scanf ("%lf", &f);    printf ("%.3lf"5-9);     return 0 ;}

Exercise 1-3 continuous and (sum)
Enter a positive integer n to output the value of 1+2+3+......+n. Tip: The goal is to solve the problem rather than practice programming.

#include <stdio.h>int  main () {    int  n;    scanf ("%d", &N);    printf ("%d"12);     return 0 ;}

Exercise 1-4 sine and cosine (sincos)
Enter a positive integer n (n<360) to output the sine and cosine function values of n degrees. Hint, use mathematical functions.

#include <stdio.h>#include<math.h>#definePi ACOs (-1.0)intMain () {intdegree; scanf ("%d", &degree); printf ("%.3lf\n", Sin (1.0* pi * Degree/180.0)); printf ("%.3lf\n", cos (1.0* pi * Degree/180.0)); return 0;}

Exercise 1-5 distance (distance)
Enter 4 floating-point numbers x1,y1,x2,y2, and the distance from the midpoint (x1,y1) of the plane coordinate system to (X2,Y2).

 #include <stdio.h> #include  <math.h> int   Main () { double   x1, y1, x2, y2; scanf (  %lf%lf%lf%lf   ", &x1, &y1, &x2, &y2);  double  dis = sqrt (Pow (x1-x2, 2 .) +    Pow (y1-y2, 2    %.3lf   "  return  0  ;}  

Exercise 1-6 even (odd)
Enter an integer to determine whether it is an even number. If yes, output "yes", otherwise output "no". Hint: it can be judged in a variety of ways.

 #include <stdio.h> #include  <math.h> int   Main () { double   x1, y1, x2, y2; scanf (  %lf%lf%lf%lf   ", &x1, &y1, &x2, &y2);  double  dis = sqrt (Pow (x1-x2, 2 .) +    Pow (y1-y2, 2    %.3lf   "  return  0  ;}  

Exercise 1-7 Discount (discount)
A dress 95 yuan, if spend 300 yuan, can play 85 percent. Enter the number of clothes purchased, the amount to be paid for the output (unit: Yuan), two decimal places reserved.

#include <stdio.h>int  main () {    int  n;    scanf ("%d", &N);    printf ("%.2lf"95.00.85  * n);     return 0 ;}

Exercise 1-8 Absolute (ABS)
Enter a floating-point number, output his absolute value, and keep two decimal places.

#include <stdio.h><math.h>int  main () {    double  F;    scanf ("%lf", &f);    printf ("%.2lf", Fabs (f));     return 0 ;}

Exercise 1-9 triangle (triangle)
Enter a triangular three-side length value (all positive integers) to determine if it can be three sides of the triangle. If you can, output "yes", or "no" if not. If the triangle cannot be formed at all, the output is "not a trangle".

#include <stdio.h>#include<algorithm>intMain () {inta[3];  for(inti =0; I <3; i + +) scanf ("%d", A +i); Std::sort (A, a+3); if(a[0] + a[1] <= a[2]) puts ("Not a trangle"); Else if(a[0] * a[0] + a[1] * a[1]! = a[2] * a[2]) puts ("No"); Elseputs ("Yes"); return 0;}

Exercise 1-10 (year)
Enter the year to determine whether it is leap years. If yes, output "yes", otherwise output "no". Hint, simple judgment divided by 4 of the remainder is not enough.

#include <stdio.h>#include<algorithm>intMain () {intYear ; scanf ("%d", &Year ); Puts ( year% -==0|| year% -!=0&& year%4==0?"Yes":"No"); return 0;}

Introduction to algorithmic competition the first chapter of the introduction of 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.