Current location - Loan Platform Complete Network - Loan intermediary - C language of loan
C language of loan
1. Mr. Zhang borrowed money from the bank to buy a house. The loan amount is D yuan, and he is going to pay back P yuan every month. The monthly interest rate is r, how many months will it take to pay it off? The known calculation formula is:

M=(㏒P-㏒(P-D*R))/ ㏒( 1+R)

M is the number of months required to pay off the loan. Suppose today D=324 500 yuan, P=3245 Yuan, and R=0.8%. The program asks about the number of months m to repay the loan and how much to pay in total.

# include & ltmath.h & gt

# include & ltstdio.h & gt

Double m (double p, double d, double r)

{

Double a, b, c;

a = log(P);

b = log(P-D * R);

c = log( 1+R);

Return (a-b)/c;

}

int main(void)

{

Double d = 324500, p = 3245, r = .008f

Long month = 0;

month = (long)M(p,d,r);

printf(" months = % d \ n payment = % d \ n ",month,month *(long)p);

Returns 0;

}

/* Operation result:

Month = 20 1

Payment = 652245

*/

Write a program to output English letters C, H, I, N and A one by one. Then output in reverse order, that is, a, n, I, h, c.

# include & ltstdio.h & gt

int main(void)

{

Char s[6]= "China"; int I = 0;

for(I = 0; I<5; i++) printf("%c ",s[I]);

printf(" \ n ");

for(I = 4; I>- 1; i - )printf("%c ",s[I]);

printf(" \ n ");

Returns 0;

}

3. Enter the three-side lengths A, B and C of the triangle, and write a program to find the area of the triangle. Known triangle area formula is:

Area=sprt(s(s-a)(s-b)(s-c)), where s=(a+b+c)/2.

# include & ltmath.h & gt

# include & ltstdio.h & gt

Double area (double A, double B, double C)

{

Double s = 0;;

s =(a+b+c)/2.0f;

s = s *(s-a)*(s-b)*(s-c);

Return to sqrt

}

int main(void)

{

Double a, b, c;

Scanf("%f %f %f ",& i, & ampb & amp;; c);

printf("area = %f ",area(a,b,c));

Returns 0;

}

4. Write a program to find ax? The root of the equation +bx+c=0. A, b, c input with the keyboard, b? -4ac & gt; 0。

# include & ltmath.h & gt

# include & ltstdio.h & gt

Double area (double A, double B, double C)

{

Double s = 0;;

s =(a+b+c)/2.0f;

s = s *(s-a)*(s-b)*(s-c);

Return to sqrt

}

int main(void)

{

int a,b,c,d; Double e, x, y;

Scanf("%d %d %d ",& i, & ampb & amp;; c);

d = b * b-4 * a * c;

if(d & lt; 0) {

Printf ("There is no real root. \ n ");

Returns 0;

}

if(d == 0) {

e =-2 * a;

e =(double)b/e;

printf("X 1 = X2 = %f ",e);

Returns 0;

}

e = d;

e = sqrt(e);

x =(-(double)b+e)/(double)(2 * a);

y =(-(double)b-e)/(double)(2 * a);

printf("X 1 = %f,X2 = %f\n ",x,y);

Returns 0;

}