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)