C language programming introductory training (two)

C language programming introductory training (two)

C language programming introductory training (two)

Article Directory


Continuing from the previous introductory training (1) -blog entry

\

Exercise 11: ASCII code

Title description

BoBo teaches that the characters represented by KiKi character constants or character variables are stored in the form of ASCII codes in the memory. BoBo had a problem with KiKi, converting the following ASCII codes into corresponding characters and outputting them.

73, 32, 99, 97, 110, 32, 100, 111, 32, 105, 116, 33

Enter a description:

no

Output description:

Convert all the ASCII given in the output title to the corresponding characters.

code show as below:

# include <stdio.h> int main () { char arr[ 12 ] = { 73 , 32 , 99 , 97 , 110 , 32 , 100 , 111 , 32 , 105 , 116 , 33 }; int sz = sizeof (arr)/ sizeof (arr[ 0 ]); int i = 0 ; for (i = 0 ; i< 12 ; i++) { printf ( "%c" , arr[i]); } return 0 ; } Copy code

\

Exercise 12: Date of Birth Input and Output

Title description

Enter a person's date of birth (including year, month, and day), and output the year, month, and day of the birthday separately.

Enter a description:

The input is only one line, the date of birth, including the year, month and day, and the number between the year, month and day have no separator.

Output description:

3.lines, the first line is the year of birth, the second line is the month of birth, and the third line is the date of birth. If the month or day is 1 digit when outputting, you need to add 0 before the 1 digit.

Example 1
input

20130225

Output

year=2013
month=02
date=25

code show as below:

# include <stdio.h> int main () { int year = 0 ; int month = 0 ; int day = 0 ; scanf ( "%4d%2d%2d" ,&year,&month,&day); printf ( "year=%4d\n" ,year); printf ( "month=%02d\n" ,month); printf ( "date =%02d\n" ,day); return 0 ; } Copy code

:
scanf %m printf %0 0

\

-231~231-1

:

,

:

,

1

a=1,b=2

a=2,b=1

#include <stdio.h> int main() { int a; int b; int tmp; scanf("a=%d,b=%d",&a,&b); tmp=a; a=b; b=tmp; printf("a=%d,b=%d",a,b); return 0; }

:


\

ASCII

BoBo KiKi ASCII BoBo KiKi ASCII

:

:

ASCII

1

c

99

#include <stdio.h> int main () { char ch; scanf ( "%c" ,&ch); printf ( "%d" ,ch); return 0 ; } Copy code

\

Exercise 15: Calculate the value of an expression

Title description

Please calculate the expression "(-8+22) a-10+c 2", where a = 40 and c = 212.

Enter a description:

no.

Output description:

The result of (-8+22) a-10+c 2 is an integer.

code show as below:

# include <stdio.h> int main () { int a = 40 ; int c = 212 ; int sum = 0 ; sum=(-8+22)*a-10+c/2; printf("%d\n",sum); return 0; }

\

a b ( 10,000 < a,b < 10,000) a b

:

a b

:

1

15 2

7 1

#include <stdio.h> int main() { int a=0; int b=0; scanf("%d %d",&a,&b); printf("%d %d",a/b,a%b); return 0; }

\

kiki

KiKi 5 100 100 BoBo KiKi 100

  1. KiKi 1234 34
  2. 100 KIKI 0

45+80 = 25
a b KiKi a+b

:

a b 0 <= a,b<= 231-1

:

KiKi a+b

1

45 80

25

#include <stdio.h> int main() { int a; int b; scanf("%d %d",&a,&b); printf("%d\n",(a%100+b%100)%100); //printf("%d",(a+b)%100); return 0; }

\

:

:

1

13.141

3

#include <stdio.h> int main() { float c; scanf("%f",&c); printf("%d",(int)c%10); return 0; }

\

3.156 107s

:

age(0<age<=200)

:

1

20

631200000

#include <stdio.h> int main() { int age=0; scanf("%d", &age); long long ret = age*3.156e7; printf("%lld", ret); return 0; }

c int long long long

\

seconds (0< seconds < 100,000,000)

:

:

1

3661

1 1 1

#include <stdio.h> int main() { int sec=0; scanf("%d",&sec); printf("%d %d %d",sec/60/60,sec/60%60,sec%60); return 0; }

\

3

:

3

:

1

79.5 80.0 98.0

257.50 85.83

#include <stdio.h> int main() { float a,b,c; scanf("%f %f %f",&a,&b,&c); printf("%.2f %.2f",a+b+c,(a+b+c)/3.0); return 0; }

\

BMI BMI Body Mass Index BMI BMI

:

:

BMI

1

70 170

24.22

#include <stdio.h> #include<math.h> int main() { int wei,high; scanf("%d %d",&wei,&high); printf("%.2f",wei/(pow((high/100.0),2))); return 0; }

<math.h>,

\

3 a, b, c 0 < a, b, c < 100,000

:

3

:

1

3 3 3

circumference=9.00 area=3.90

# include <stdio.h> # include <math.h> int main () { int a = 0 ; int b = 0 ; int c = 0 ; scanf ( "%d%d%d" , &a, &b, &c ); double circumference = a + b + c; float p = (a + b + c)/2.0 ; float area = sqrt (p*(p-a)*(p-b)*(p-c)); printf ( "circumference=%.2f area=%.2f" , circumference, area); return 0 ; } Copy code

Remarks: Be familiar with the application of the square function and the Helen formula for calculating the area of a triangle.

\

Exercise 24: Calculate the volume of a sphere

Title description

Given the radius of a sphere, calculate its volume. The formula for the volume of the sphere is V = 4/3* r3, where = 3.1415926.

Enter a description:

One line, the radius of the sphere represented by a floating point number.

Output description:

One line, the volume of the sphere, keep 3 digits after the decimal point.

Example 1

enter

3.0

Output

113.097

code show as below:

# include <stdio.h> # include <math.h> int main () { double r = 0.0 ; double pi = 3.1415926 ; scanf ( "%lf" ,&r); printf ( "%.3lf" , 4.0/3 *pi*r*r*r); return 0 ; } Copy code

\

Exercise 25: Case conversion

Title description

Realize the case conversion of letters. Multiple sets of input and output.

Enter a description:

Enter multiple groups, and enter uppercase letters on each line.

Output description:

For each group of input and output corresponding lowercase letters.

Example 1
input

A
B

Output

a
b

code show as below:

#include <stdio.h> int main() { char ch ; while ((ch = getchar()) != EOF) { getchar(); putchar(ch+32); printf("\n"); } return 0; }

: (getchar())

\

2 n

<< 2 n

:

n 0 <= n < 31

:

2 n

1

2
10

4
1024

#include <stdio.h> int main() { int n=0; while(scanf("%d",&n)!=EOF) { printf("%d\n",1<<n); } return 0; }




\