Current location - Training Enrollment Network - Mathematics courses - Programming mathematics problem
Programming mathematics problem
1. Enter a four-digit natural number and output the sum of its digits.

# contains "stdio.h"

Master ()

{

int n,sum = 0;

Printf ("Please enter a four-digit natural number:");

scanf("%d ",& ampn);

while(n & gt; = 10000 | | n & lt; 1000)

{

Printf ("Input error, please re-enter!" );

scanf("%d ",& ampn);

}

sum = n % 10+n/ 10% 10+n/ 100% 10+n/ 1000;

Printf("\n%d, the sum of digits is: %d ",n, sum);

getch();

}

2. Programming, converting the length value in inches into the length value in centimeters, and the output accuracy is 10-3, which requires a friendly interface.

Conversion formula: 1 inch =2.54 cm.

# contains "stdio.h"

Master ()

{

Double n;

Printf ("Please enter a length value (inches):");

scanf("%lf ",& ampn);

while(n & lt; 0)

{

Printf ("Input error, please re-enter!" );

scanf("%lf ",& ampn);

}

printf(" \ n % lf inch = % 10.3 lf cm ",n * 2.54+0.0005);

getch();

}

3. Programming, input a character and output the ASCII code of the character.

# contains "stdio.h"

Master ()

{

char n;

Printf ("Please enter a character:");

scanf("%c ",& ampn);

Printf (ASCII value is "\ n% c is: %d", n, n);

getch();

}

4. Write a program to convert the input Fahrenheit temperature value into Celsius temperature value, and the accuracy of the output result is 0. 1 (the conversion formula is found online on Baidu and other tools).

# contains "stdio.h"

Master ()

{

Double f, c;

Printf ("Please enter a Fahrenheit temperature value (f):");

scanf("%lf ",& ampf);

c = 5 *(F-32)/9+0.05;

Printf("\n%lf Fahrenheit =%. 1lf Celsius ",f, c);

getch();

}

5. Enter the values of three sides of the triangle and calculate the area of the triangle. The accuracy of the result is 10-3 (the conversion formula is found in online Baidu and other tools).

# contains "stdio.h"

# contains "math.h"

Master ()

{

Double a, b, c, s, s;

Printf ("Please enter three sides of the triangle:");

Scanf("%lf, %lf, %lf ",& one, & c);

while(a+b & lt; = c | | a+c & lt; = b | | b+ c & lt; =a)

{

Printf ("input error, cannot form triangle, please re-enter!" );

Scanf("%lf, %lf, %lf ",& one, & c);

}

s =(a+b+c)/2;

s = sqrt(s *(s-a)*(s-b)*(s-c))+0.0005;

Printf(" \ n The area of triangle is:% 10.3lf ",s);

getch();

}

(additional questions) 6. Programming converts decimal numbers input by users into hexadecimal numbers and octal numbers for output, which requires a friendly interface.

# contains "stdio.h"

Master ()

{

int n;

Printf ("Please enter a decimal:");

scanf("%d ",& ampn);

Printf("\n%d converted to octal number: %o ",n, n);

Printf("\n%d converted to hexadecimal number: %x ",n, n);

getch();

}