C&python (2)

Source: Internet
Author: User

Study of C this week

Use switch method to solve practical problems.

First, calculate the number of days

#include <stdio.h>
Main ()
{
int year,month,day;
int sum=0;
printf ("Please enter a date in the format: year-month-day):");
scanf ("%d-%d-%d", &year,&month,&day);
Switch (month-1)
{
Case 12:
sum=sum+31;
Case 11:
sum=sum+30;
Case 10:
sum=sum+31;
Case 9:
sum=sum+30;
Case 8:
sum=sum+31;
Case 7:
sum=sum+31;
Case 6:
sum=sum+30;
Case 5:
sum=sum+31;
Case 4:
sum=sum+30;
Case 3:
sum=sum+31;
Case 2:
if (year%4==0&&year%100!=0)
sum=sum+29;
Else
sum=sum+28;
Case 1:
sum=sum+31;
Break
}
Sum=sum+day;
printf ("%d-%d-month-%d-day%d-year-%d", year,month,day,year,sum);
}

! note int sum=0; write in front.

Ii. Calculation of interest rates

#include <stdio.h>
Main ()
{
int n,k;
float m,d;
printf ("Enter profit:");
scanf ("%d", &n);
m=n/100000;
k= (int) m;
Switch (k)
{
Case 0:
d=n*0.1;
Break
Case 1:
D= (n-100000) *0.075+100000*0.1;
Break
Case 2:
D= (n-200000) *0.05+100000*0.075+100000*0.1;
Break
Case 3:
D= (n-200000) *0.05+100000*0.075+100000*0.1;
Break
Case 4:
D= (n-400000) *0.03+200000*0.05+100000*0.075+100000*0.1;
Break
Case 5:
D= (n-400000) *0.03+200000*0.05+100000*0.075+100000*0.1;
Break
Case 6:
D= (n-600000) *0.015+200000*0.03+200000*0.05+100000*0.075+100000*0.1;
Break
Case 7:
D= (n-600000) *0.015+200000*0.03+200000*0.05+100000*0.075+100000*0.1;
Break
Case 8:
D= (n-600000) *0.015+200000*0.03+200000*0.05+100000*0.075+100000*0.1;
Break
Case 9:
D= (n-600000) *0.015+200000*0.03+200000*0.05+100000*0.075+100000*0.1;
Break
Case 10:
D= (n-1000000) *0.01+400000*0.015+200000*0.03+200000*0.05+100000*0.075+100000*0.1;
Break
}
printf ("Bonus =%.2f\n for profit of%d", n,d);
}

Take advantage of cast operations.

This week participated in the entrepreneurial Experiment project, understand the basic ideas, make a reply ppt

C&python (2)

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.