1. Enter the Fahrenheit temperature to calculate the Celsius temperature.
# Include <stdio. h>
Void main ()
{
Float F, C;
Printf ("Enter the Fahrenheit temperature: \ n ");
Scanf ("% F", & F );
C = (f-32) * 5/9;
Printf ("% F", C );
}
2. input the radius to calculate the area and perimeter of the circle.
# Include <stdio. h>
Void main ()
{
# Define PI 3.1415
Float R, S, D;
Printf ("Enter the radius: \ n ");
Scanf ("% F", & R );
S = pI * r * R;
D = 2 * pI * R;
Printf ("% F", D, S );
}
3. Write a program for inputting a number and outputting the numbers respectively from 1 to 1 ~ Result of multiplying the number of 10.
# Include <stdio. h>
Void main ()
{
Int I, d;
Printf ("enter a number :");
Scanf ("% d", & d );
For (I = 1; I <= 10; I ++)
{
Printf ("% d", d );
Printf ("*");
Printf ("% d", I );
Printf ("= ");
Printf ("% d", d * I );
If (I % 2 = 0)
Printf ("\ n ");
}
}
4. Thinking: enter a five-digit number to calculate the result of adding each bit.
Example: 12345: 1 + 2 + 3 + 4 + 5
# Include "stdio. h"
Main ()
{
Long I;
Int n, sum = 0;
Scanf ("% ld", & I );
While (I)
{
N = I % 10;
Sum = sum + n;
I = I/10;
}
Printf ("% d", sum );
}
5. Think: Enter the year to determine whether it is a year or a leap year?
# Include <stdio. h>
Void main ()
{
Int year, leap;
Printf ("input your year. \ n ");
Scanf ("% d", & year );
Leap = year % 4 = 0 & year % 100! = 0 | year % 400 = 0;
If (LEAP)
Printf ("% d is a leap year. \ n", year );
Else
Printf ("% d is a not leap year. \ n", year );
}
6. Thinking: input three numbers to calculate the maximum value of the three numbers.
# Include <stdio. h>
Void main ()
{
Int X, Y, Z, K, P;
Printf ("Enter these three numbers: \ n ");
Scanf ("% d, % d, % d", & X, & Y, & Z );
K = z> (P = x> Y? X: Y )? Z: P;
Printf ("the maximum number is % d \ n", k );
}
7. Enter the day of the week. If the input is: 1-5: Print: happy working day;
If you enter 6, 7, print: Happy weekend. If you do not enter between 1 and 7, the input is incorrect.
# Include <stdio. h>
Void main ()
{
Int d;
Printf ("Enter the week: \ n ");
Scanf ("% d", & d );
Switch (d)
{
Case 1:
Case 2:
Case 3:
Case 4:
Case 5: printf ("happy working day \ n ");
Break;
Case 6:
Case 7: printf ("Happy weekend \ n ");
Break;
Default: printf ("incorrect input ");
}
}
8. Thinking: enter a number 3, enter the number of digits (4), and calculate the result of 3 + 33 + 333 + 3333.
# Include <stdio. h>
Void main ()
{
Int I;
Long sum;
Printf ("enter this number: \ n ");
Scanf ("% I", & I );
Sum = I * 1000 + I * 100 + I * 10 + I;
Printf ("% ld \ n", sum );
}
9. Input a base number (m), input an index (n), and evaluate the n power of m.
# Include <stdio. h>
Void main ()
{
Int n, I, m;
Int q = 1;
Printf ("Enter the base number and index :");
Scanf ("% d, % d", & m, & n );
For (I = 1; I <= n; I ++)
{
Q * = m;
}
Printf ("% d \ n", q );
}
10, please: 1 + 2 + 3... + 100?
# Include <stdio. h>
Void main ()
{
Int I;
Long sum = 0;
For (I = 1; I <= 100; I ++)
{
Sum + = I;
}
Printf ("1 + 2 + 3 +... + 100 = % d \ n", sum );
}
Page68 first question
# Include <stdio. h>
Void main ()
{
Long x, float price;
Double sum;
Printf ("Enter the quantity and unit price of the purchased item \ n ");
Scanf ("% ld, % f", & x, & price );
If (x <5)
{
Sum = x * price;
Printf ("% lf", sum );
}
Else if (5 <= x <10)
{
Sum = x * price * 0.01;
Printf ("% lf", sum );
}
Else if (10 <= x <20)
{
Sum = x * price * 0.02;
Printf ("% lf", sum );
}
Else if (20 <= x <30)
{
Sum = x * price * 0.04;
Printf ("% lf", sum );
}
Else if (x> = 30)
{
Sum = x * price * 0.06;
Printf ("% lf", sum );
}
Else
{
Printf ("You have not bought the product ");
}
}
Page69 Question 2
# Include <stdio. h>
Void main ()
{
Int I;
Printf ("enter date: \ n ");
Scanf ("% d", & I );
Switch (I)
{
Case 1: printf ("green vegetables ");
Break;
Case 2: printf ("chicken ");
Break;
Case 3: printf ("fish ");
Break;
Case 4: printf ("meat ");
Break;
Case 5: printf ("eggs ");
Break;
Case 6: printf ("Bean ");
Break;
Case 7: printf ("seafood ");
Break;
Default: printf ("input error :");
}
}
Page 197 Question 1
# Include <stdio. h>
Void main ()
{
Long X; float PR;
Float sum, Qr;
Printf ("Enter the quantity and unit price: \ n ");
Scanf ("% lD, % F", & X, & pr );
If (x> = 10 & x * Pr> = 10000)
{
Sum = x * Pr * (1-0.1 );
Qr = x * Pr * 0.1;
}
Printf ("% F \ n", sum, QR );
}
Page197 second question
# Include <stdio. h>
Void main ()
{
Int num1, num2;
Int sum;
Int diff;
Char C;
Printf ("enter two numbers: \ n ");
Scanf ("% d", & num1, & num2 );
Printf ("enter this symbol: \ n ");
Scanf ("% C", & C );
Switch (c)
{
Case '+': sum = num1 + num2;
Printf ("% d", sum );
Break;
Case '-': diff = num1-num2;
Printf ("% d", diff );
Break;
Default: printf ("null ");
Break;
}
}