Algorithmic competition Getting started classic _1.5_ exercises

Source: Internet
Author: User

Tag: amp runs style ons = = using Color 1.0 exercise

1. Temperature problems

#include <stdio.h>int  main () {    double  F, C;    scanf ("%lf", &f);     5 ) /9.0;    printf ("%.3lf\n", c);     return 0 ;}

Operation Result:

2. The question of averages

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

Keep three decimal places%.3f

Operation Result:

3. Continuity and Problems

#include <stdio.h>int  main () {    int n=0, sum;      while 1 && scanf ("%d", &N));     = N (1+n)/2;    printf ("%d\n", sum);     return 0 ;}

Operation Result:

4. Sine and cosine problems

#include <stdio.h>#include<math.h>intMain () {Const DoublePI = ACOs (-1.0);//Pi uses ACOs (-1.0) to obtain M_PI is not ANSI C standard    intn =0;  while(N <1|| n >359) && scanf ("%d", &n));//1-359    Doubleth = n/180.0* PI;//Convert to Radian systemprintf"%LF%lf\n", sin (th), cos (th)); return 0;}

Operation Result:

5. Discount Issues

#include <stdio.h>intMain () {intn =0; DoubleAmount =0;  while(N <1&& scanf ("%d", &N)); if(n the>= -) Amount= N the*0.85; ElseAmount= N the; printf ("%.2lf\n", amount); return 0;}

Operation Result:

6. Triangle problem

#include <stdio.h>intMain () {intA =0, B =0, C =0;  while((A * b *c <1&& (a<1|| b<1|| c<1)) && (scanf ("%d%d%d", &a, &b, &c) <=3) {fflush (stdin);    }; if(! (A+b > C && a+c > B && b+c >a) printf ("Not a triangle\n"); Else    {     if(a*a + b*b = = C*c | | a*a + c*c = B*b | | b*b + C*C = = *a) printf ("yes\n"); Elseprintf ("no\n"); }    return 0;}

Operation Result:

7. Leap Year issues

#include <stdio.h>intMain () {inty =0;  while(Y <1&& scanf ("%d", &y) <=1) {fflush (stdin); }    if((y%4==0&& y% -!=0)|| (Y% -==0) {printf ("yes\n"); }    Else{printf ("no\n"); }    return 0;}

Conditions for leap years
Multiples of 4, but not multiples of 100
Or a multiple of 400.

Operation Result:

About scanf control user input questions please see the author of this essay

Http://www.cnblogs.com/ncgds/p/7102967.html

Sometimes you don't push yourself, how do you know you can't?

Algorithmic competition Getting started classic _1.5_ 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.