C ++ exercises have solutions (sample code)

TipsMake.com has summarized for you some basic C ++ exercises to practice more in the process of learning C ++ programming language.

Besides the Python, Java exercises, TipsMake.com also summarizes for you some basic C ++ exercises to practice more in the process of learning C ++ programming language.

This C ++ exercise list is divided into 9 sections, each with 3 to 5 items, with increasing difficulty levels. Initially you will "boot" with very basic C ++ exercises, such as simulating the multiplication, printing the amount, checking a set of 3 numbers to see if it is the edge of a triangular triangle, calculating the circumference, area of ​​that triangle.

Gradually, it will be more difficult to create and manage student lists, documents, print or perform other tasks as required by the lesson. Even draw a graph of trigonometric functions.

C ++ exercises list

  1. C + 1 exercise
    1. Question 1: Simulation of manual multiplication
    2. Question 2: Enter the amount, print the number of sheets and par values
    3. Question 3: Change the number of Roman numerals
    4. Question 4: Print how to read numbers
    5. Question 5: Solving quadratic equations
  2. C ++ exercise # 2
    1. Question 1: Check if 3 numbers are right next to the triangle, if there are any kind of triangle, calculate perimeter, area
    2. Question 2: Calculate the number of years to save
    3. Question 3: Print PI numbers to calculate with a given error
    4. Question 4: Find and print perfect numbers
    5. Question 5: Find and print smaller prime numbers n
  3. Exercise C ++ No. 3
    1. Question 1: Check the main number
    2. Question 2: The first unequal solution
    3. Question 3: Write recursive function to find the greatest common convention
    4. Question 4: Calculate the distance of the positive integer n
    5. Question 5: Write recursive function to solve the problem of Hanoi tower
  4. C ++ exercise # 4
    1. Question 1: Print the elements of the array as required
    2. Question 2: Enter, arrange and print array
    3. Question 3: Enter, print array, count paragraphs according to criteria
    4. Question 4: Enter, print, calculate 2 matrices
    5. Question 5: Enter, print square matrix, determinant
  5. Exercise C ++ No. 5
    1. Question 1: Check the symmetry of a string
    2. Question 2: Statistics of the number of occurrences of a character in the string
    3. Question 3: Standardize the character string
    4. Question 4: Enter the array of characters and sort in ascending order
  6. C ++ exercise # 6
    1. Question 1: Manage the score of candidates by array
    2. Question 2: Manage documents, print the list as required
    3. Question 3: Manage electricity payment
  7. C ++ exercise # 7
    1. Question 1: Create a digital file, count the number, the largest number and the smallest number
    2. Question 2: Create student name file, arrange and print
    3. Question 3: Create student file list file as required
  8. Exercise C ++ No. 8
    1. Question 1: Draw the yellow star red flag at the center of the screen.
    2. Question 2: Draw the antenna tower simulation.
    3. Question 3: Draw the starry sky on the screen.
    4. Question 4: Graph the function y = sinx.
    5. Question 5: Draw the moving ball in the rectangular frame.
  9. Exercise C ++ No. 9
    1. Question 1: Create vector layer as required
    2. Question 2: Create a fractional layer as required
    3. Question 3: Create a class of goods as required
    4. Question 4: Write functions to import, export, and sort arrays

C + 1 exercise

Question 1: Simulation of manual multiplication

Programming to print the screen simulating manual multiplication 2 positive integers with 3 digits entered from the keyboard. For example, with 2 numbers entered 763 and 589, the screen must be printed as follows:

 

Picture 1 of C ++ exercises have solutions (sample code)

Sample code:

 clrscr();44 
clrscr();43
clrscr();42
clrscr();41
clrscr();40
clrscr();39
clrscr();38
clrscr();37
clrscr();36
clrscr();35
clrscr();34
clrscr();33
clrscr();32
clrscr();31
clrscr();30
clrscr();29
clrscr();28
clrscr();27

clrscr();26

Question 2: Enter the amount, print the number of sheets and par values

A person needs to withdraw a T amount from the bank and wants the minimum number of sheets. Indicates that there are denominations of 100, 20, 5 and 1 denominations. Enter from the T-number keyboard and print out the number of sheets for each par value and the total number of sheets received.

Sample code:

 clrscr();25 
clrscr();24
clrscr();23
clrscr();22
clrscr();21
clrscr();20
clrscr();19
clrscr();18
clrscr();17
clrscr();16
clrscr();15
clrscr();14
clrscr();13
clrscr();12
clrscr();11

Question 3: Change the number of Roman numerals

Programming enter a positive integer less than 1000 and change to the corresponding Roman number, print the result to the screen.

Sample code:

 clrscr();10 

clrscr();09

clrscr();08

clrscr();07

clrscr();06

clrscr();05

clrscr();04

clrscr();03

clrscr();02

clrscr();01

clrscr();00

f=fopen("HosoSV.DAT","w+b");99

f=fopen("HosoSV.DAT","w+b");98

f=fopen("HosoSV.DAT","w+b");97

f=fopen("HosoSV.DAT","w+b");96

f=fopen("HosoSV.DAT","w+b");95

f=fopen("HosoSV.DAT","w+b");94

f=fopen("HosoSV.DAT","w+b");93

f=fopen("HosoSV.DAT","w+b");92

f=fopen("HosoSV.DAT","w+b");91

f=fopen("HosoSV.DAT","w+b");90

f=fopen("HosoSV.DAT","w+b");89

f=fopen("HosoSV.DAT","w+b");88

f=fopen("HosoSV.DAT","w+b");87

f=fopen("HosoSV.DAT","w+b");86

f=fopen("HosoSV.DAT","w+b");85

f=fopen("HosoSV.DAT","w+b");84

f=fopen("HosoSV.DAT","w+b");83

f=fopen("HosoSV.DAT","w+b");82

f=fopen("HosoSV.DAT","w+b");81

f=fopen("HosoSV.DAT","w+b");80

f=fopen("HosoSV.DAT","w+b");79

f=fopen("HosoSV.DAT","w+b");78

f=fopen("HosoSV.DAT","w+b");77

f=fopen("HosoSV.DAT","w+b");76

f=fopen("HosoSV.DAT","w+b");75

f=fopen("HosoSV.DAT","w+b");74

f=fopen("HosoSV.DAT","w+b");73

f=fopen("HosoSV.DAT","w+b");72

f=fopen("HosoSV.DAT","w+b");71

f=fopen("HosoSV.DAT","w+b");70

f=fopen("HosoSV.DAT","w+b");69

f=fopen("HosoSV.DAT","w+b");68

Question 4: Print how to read numbers

Print the screen how to read a positive integer smaller than 1000000. Example 726503 read: seventy-twenty-six thousand five hundred and three.

Sample code:

 f=fopen("HosoSV.DAT","w+b");67 

f=fopen("HosoSV.DAT","w+b");66

f=fopen("HosoSV.DAT","w+b");65

f=fopen("HosoSV.DAT","w+b");64

f=fopen("HosoSV.DAT","w+b");63

f=fopen("HosoSV.DAT","w+b");62

f=fopen("HosoSV.DAT","w+b");61

f=fopen("HosoSV.DAT","w+b");60

f=fopen("HosoSV.DAT","w+b");59

f=fopen("HosoSV.DAT","w+b");58

f=fopen("HosoSV.DAT","w+b");57

f=fopen("HosoSV.DAT","w+b");56

f=fopen("HosoSV.DAT","w+b");55

f=fopen("HosoSV.DAT","w+b");54

f=fopen("HosoSV.DAT","w+b");53

f=fopen("HosoSV.DAT","w+b");52

f=fopen("HosoSV.DAT","w+b");51

f=fopen("HosoSV.DAT","w+b");50

f=fopen("HosoSV.DAT","w+b");49

f=fopen("HosoSV.DAT","w+b");48

f=fopen("HosoSV.DAT","w+b");47

f=fopen("HosoSV.DAT","w+b");46

f=fopen("HosoSV.DAT","w+b");45

f=fopen("HosoSV.DAT","w+b");44

f=fopen("HosoSV.DAT","w+b");43

f=fopen("HosoSV.DAT","w+b");42

f=fopen("HosoSV.DAT","w+b");41

Question 5: Solving quadratic equations

Programming to solve the equation ax 2 + bx + c = 0, the real coefficients a, b, and c enter from the keyboard.

Sample code:

 f=fopen("HosoSV.DAT","w+b");40 

f=fopen("HosoSV.DAT","w+b");39

f=fopen("HosoSV.DAT","w+b");38

f=fopen("HosoSV.DAT","w+b");37

f=fopen("HosoSV.DAT","w+b");36

f=fopen("HosoSV.DAT","w+b");35

f=fopen("HosoSV.DAT","w+b");34

f=fopen("HosoSV.DAT","w+b");33

f=fopen("HosoSV.DAT","w+b");32

f=fopen("HosoSV.DAT","w+b");31

f=fopen("HosoSV.DAT","w+b");30

f=fopen("HosoSV.DAT","w+b");29

f=fopen("HosoSV.DAT","w+b");28

f=fopen("HosoSV.DAT","w+b");27

f=fopen("HosoSV.DAT","w+b");26

f=fopen("HosoSV.DAT","w+b");25

f=fopen("HosoSV.DAT","w+b");24

f=fopen("HosoSV.DAT","w+b");23

f=fopen("HosoSV.DAT","w+b");22

f=fopen("HosoSV.DAT","w+b");21

f=fopen("HosoSV.DAT","w+b");20

C ++ exercise # 2

Question 1: Check if 3 numbers are right next to the triangle, if there are any kind of triangle, calculate perimeter, area

Enter 3 real numbers a, b, c and check that these 3 numbers are 3 sides of a triangle? If there are three triangular edges, it is said which triangle is in the following triangle types: regular, square, square, weight, normal and circumference, area of ​​that triangle. Print results to the screen.

Sample code:

 f=fopen("HosoSV.DAT","w+b");19 

f=fopen("HosoSV.DAT","w+b");18

f=fopen("HosoSV.DAT","w+b");17

f=fopen("HosoSV.DAT","w+b");16

f=fopen("HosoSV.DAT","w+b");15

f=fopen("HosoSV.DAT","w+b");14

f=fopen("HosoSV.DAT","w+b");13

f=fopen("HosoSV.DAT","w+b");12

f=fopen("HosoSV.DAT","w+b");11

f=fopen("HosoSV.DAT","w+b");10

f=fopen("HosoSV.DAT","w+b");09

f=fopen("HosoSV.DAT","w+b");08

f=fopen("HosoSV.DAT","w+b");07

f=fopen("HosoSV.DAT","w+b");06

f=fopen("HosoSV.DAT","w+b");05

f=fopen("HosoSV.DAT","w+b");04

f=fopen("HosoSV.DAT","w+b");03

f=fopen("HosoSV.DAT","w+b");02

f=fopen("HosoSV.DAT","w+b");01

f=fopen("HosoSV.DAT","w+b");00

printf("Nhap so sv n=");99

printf("Nhap so sv n=");98

printf("Nhap so sv n=");97

Question 2: Calculate the number of years to save

A person needs to have a T amount, accumulate by depositing an initial deposit of S with an annual interest rate of P% by progressive method (the interest of each year is added to the principal) . Enter real numbers T, S, P and determine the number of years to save.

Sample code:

 printf("Nhap so sv n=");96 

printf("Nhap so sv n=");95

printf("Nhap so sv n=");94 printf("Nhap so sv n=");93

printf("Nhap so sv n=");92

printf("Nhap so sv n=");91

printf("Nhap so sv n=");90

printf("Nhap so sv n=");89

printf("Nhap so sv n=");88

printf("Nhap so sv n=");87

printf("Nhap so sv n=");86

printf("Nhap so sv n=");85

printf("Nhap so sv n=");84

printf("Nhap so sv n=");83

printf("Nhap so sv n=");82

printf("Nhap so sv n=");81

printf("Nhap so sv n=");80

printf("Nhap so sv n=");79

printf("Nhap so sv n=");78

Question 4: Find and print perfect numbers

Find and print the screen all perfect numbers do not exceed the number of given n input from the keyboard. The perfect number is the number equal to the sum of its divisors excluding the divisor that is the number itself. Example 6 is a perfect number because 6 = 1 + 2 + 3.

Sample code:

 printf("Nhap so sv n=");77 

printf("Nhap so sv n=");76

printf("Nhap so sv n=");75

printf("Nhap so sv n=");74

printf("Nhap so sv n=");73

printf("Nhap so sv n=");72

printf("Nhap so sv n=");71

printf("Nhap so sv n=");70

printf("Nhap so sv n=");69

printf("Nhap so sv n=");68

printf("Nhap so sv n=");67

printf("Nhap so sv n=");66

printf("Nhap so sv n=");65

printf("Nhap so sv n=");64

printf("Nhap so sv n=");63

printf("Nhap so sv n=");62

printf("Nhap so sv n=");61

printf("Nhap so sv n=");60

printf("Nhap so sv n=");59

printf("Nhap so sv n=");58

printf("Nhap so sv n=");57

Question 5: Find and print smaller prime numbers n

Find and print the screen all primes do not exceed the given number n entered from the keyboard. A prime number is a number that only has a divisor of 1 and that number itself.

Sample code:

 printf("Nhap so sv n=");56 

printf("Nhap so sv n=");55

printf("Nhap so sv n=");54

printf("Nhap so sv n=");53

printf("Nhap so sv n=");52

printf("Nhap so sv n=");51

printf("Nhap so sv n=");50

printf("Nhap so sv n=");49

printf("Nhap so sv n=");48

printf("Nhap so sv n=");47

printf("Nhap so sv n=");46

printf("Nhap so sv n=");45

printf("Nhap so sv n=");44

printf("Nhap so sv n=");43

printf("Nhap so sv n=");42

printf("Nhap so sv n=");41

printf("Nhap so sv n=");40

printf("Nhap so sv n=");39

Exercise C ++ No. 3

Question 1: Check the main number

Write a function that checks whether a number is righteous (the prime number is equal to the square of an integer); Whether a number test function is a Pythagorean number (the number of Pythons is the main number and is equal to the other 2 main numbers). In the main function enter a positive integer and use the function on the test is the main number? Pitago number?

Sample code:

 printf("Nhap so sv n=");38 

printf("Nhap so sv n=");37

printf("Nhap so sv n=");36

printf("Nhap so sv n=");35

printf("Nhap so sv n=");34

printf("Nhap so sv n=");33

printf("Nhap so sv n=");32

printf("Nhap so sv n=");31

printf("Nhap so sv n=");30

printf("Nhap so sv n=");29

printf("Nhap so sv n=");28

printf("Nhap so sv n=");27

printf("Nhap so sv n=");26

printf("Nhap so sv n=");25

printf("Nhap so sv n=");24

printf("Nhap so sv n=");23

printf("Nhap so sv n=");22

printf("Nhap so sv n=");21

printf("Nhap so sv n=");20

printf("Nhap so sv n=");19

printf("Nhap so sv n=");18

printf("Nhap so sv n=");17

printf("Nhap so sv n=");16

printf("Nhap so sv n=");15

printf("Nhap so sv n=");14 printf("Nhap so sv n=");13

printf("Nhap so sv n=");12

printf("Nhap so sv n=");11

printf("Nhap so sv n=");10

fwrite(&n,sizeof(int),1,f);56

fwrite(&n,sizeof(int),1,f);55

fwrite(&n,sizeof(int),1,f);54

fwrite(&n,sizeof(int),1,f);53

fwrite(&n,sizeof(int),1,f);52

fwrite(&n,sizeof(int),1,f);51 fwrite(&n,sizeof(int),1,f);50

fwrite(&n,sizeof(int),1,f);49

fwrite(&n,sizeof(int),1,f);48

fwrite(&n,sizeof(int),1,f);47

fwrite(&n,sizeof(int),1,f);46

fwrite(&n,sizeof(int),1,f);45

fwrite(&n,sizeof(int),1,f);44

fwrite(&n,sizeof(int),1,f);43

fwrite(&n,sizeof(int),1,f);42

fwrite(&n,sizeof(int),1,f);41 fwrite(&n,sizeof(int),1,f);40

i=1;3

i=1;2

i=1;1

i=1;0

do9

do8

do7

do6

do5 do4

do3

do2

do1

do0

{printf("So thu %d : ",i++); scanf("%d",&x);9

{printf("So thu %d : ",i++); scanf("%d",&x);8

{printf("So thu %d : ",i++); scanf("%d",&x);7

{printf("So thu %d : ",i++); scanf("%d",&x);6

{printf("So thu %d : ",i++); scanf("%d",&x);5 {printf("So thu %d : ",i++); scanf("%d",&x);4

{printf("So thu %d : ",i++); scanf("%d",&x);3

{printf("So thu %d : ",i++); scanf("%d",&x);2

{printf("So thu %d : ",i++); scanf("%d",&x);1

{printf("So thu %d : ",i++); scanf("%d",&x);0

fprintf(fp,"%d ",x);9

fprintf(fp,"%d ",x);8

fprintf(fp,"%d ",x);7

fprintf(fp,"%d ",x);6

fprintf(fp,"%d ",x);5 fprintf(fp,"%d ",x);4

fprintf(fp,"%d ",x);3

fprintf(fp,"%d ",x);2

fprintf(fp,"%d ",x);1

fprintf(fp,"%d ",x);0

printf("Tiep tuc nhap ? (c/k) : ");9

printf("Tiep tuc nhap ? (c/k) : ");8

printf("Tiep tuc nhap ? (c/k) : ");7

printf("Tiep tuc nhap ? (c/k) : ");6

printf("Tiep tuc nhap ? (c/k) : ");5 printf("Tiep tuc nhap ? (c/k) : ");4

printf("Tiep tuc nhap ? (c/k) : ");3

printf("Tiep tuc nhap ? (c/k) : ");2

printf("Tiep tuc nhap ? (c/k) : ");1

printf("Tiep tuc nhap ? (c/k) : ");0

fflush(stdin);9

fflush(stdin);8

fflush(stdin);7

fflush(stdin);6

fflush(stdin);5 fflush(stdin);4

fflush(stdin);3

fflush(stdin);2

fflush(stdin);1

fflush(stdin);0

t=getchar();9

t=getchar();8

t=getchar();7

t=getchar();6

t=getchar();5 t=getchar();4

t=getchar();3

t=getchar();2

t=getchar();1

t=getchar();0

}while ((t=='c')||(t=='C'));9

}while ((t=='c')||(t=='C'));8

}while ((t=='c')||(t=='C'));7

}while ((t=='c')||(t=='C'));6

}while ((t=='c')||(t=='C'));5 }while ((t=='c')||(t=='C'));4

}while ((t=='c')||(t=='C'));3

}while ((t=='c')||(t=='C'));2

}while ((t=='c')||(t=='C'));1

}while ((t=='c')||(t=='C'));0

fclose(fp);9

fclose(fp);8

fclose(fp);7

fclose(fp);6

fclose(fp);5 fclose(fp);4

fclose(fp);3

fclose(fp);2

fclose(fp);1

fclose(fp);0

fp=fopen("tepsn.dat","r");9

fp=fopen("tepsn.dat","r");8

fp=fopen("tepsn.dat","r");7

fp=fopen("tepsn.dat","r");6

fp=fopen("tepsn.dat","r");5 fp=fopen("tepsn.dat","r");4

fp=fopen("tepsn.dat","r");3

fp=fopen("tepsn.dat","r");2

fp=fopen("tepsn.dat","r");1

fp=fopen("tepsn.dat","r");0

ts=sd=0;9

ts=sd=0;8

ts=sd=0;7

ts=sd=0;6

ts=sd=0;5 ts=sd=0;4

ts=sd=0;3

ts=sd=0;2

ts=sd=0;1

ts=sd=0;0

if (!feof(fp))9

if (!feof(fp))8

if (!feof(fp))7

if (!feof(fp))6

if (!feof(fp))5 if (!feof(fp))4

if (!feof(fp))3

if (!feof(fp))2

if (!feof(fp))1

if (!feof(fp))0

{fscanf(fp,"%d",&x);9

{fscanf(fp,"%d",&x);8

{fscanf(fp,"%d",&x);7

{fscanf(fp,"%d",&x);6

{fscanf(fp,"%d",&x);5 {fscanf(fp,"%d",&x);4

{fscanf(fp,"%d",&x);3

{fscanf(fp,"%d",&x);2

{fscanf(fp,"%d",&x);1

{fscanf(fp,"%d",&x);0

max=min=x;9

max=min=x;8

max=min=x;7

max=min=x;6

max=min=x;5

Question 3: Write recursive function to find the greatest common convention

Write recursive function to find the greatest common divisor of 2 natural numbers; a function that finds the smallest common multiple of two natural numbers. The main function uses the written functions and can run multiple times to find the greatest common divisor and the smallest common multiple of different positive integer pairs. The request to check the input must be positive integers.

Sample code:

 max=min=x;4 

max=min=x;3

max=min=x;2

max=min=x;1

max=min=x;0

ts++;9

ts++;8

ts++;7

ts++;6

ts++;5

ts++;4

ts++;3

ts++;2

ts++;1

ts++;0

if (x>0) sd++;9

if (x>0) sd++;8

if (x>0) sd++;7

if (x>0) sd++;6

if (x>0) sd++;5

if (x>0) sd++;4

if (x>0) sd++;3

if (x>0) sd++;2

if (x>0) sd++;1

if (x>0) sd++;0

while (!feof(fp))9

while (!feof(fp))8

while (!feof(fp))7

while (!feof(fp))6

Question 4: Calculate the distance of the positive integer n

Write recursive function to calculate the factorial of the positive integer n. The main function uses this function and can run several times to calculate for many different numbers entered from the keyboard. The request to check the input data must be a positive integer. The formula calculates the factorial of n: n! = 1.3 . n if n is odd and n! = 2.4 . n if n is even.

Sample code:

 while (!feof(fp))5 

while (!feof(fp))4

while (!feof(fp))3

while (!feof(fp))2

while (!feof(fp))1

while (!feof(fp))0

{fscanf(fp,"%d",&x);9

{fscanf(fp,"%d",&x);8

{fscanf(fp,"%d",&x);7

{fscanf(fp,"%d",&x);6

{fscanf(fp,"%d",&x);5

{fscanf(fp,"%d",&x);4

{fscanf(fp,"%d",&x);3

{fscanf(fp,"%d",&x);2

{fscanf(fp,"%d",&x);1

{fscanf(fp,"%d",&x);0

if (max

if (min>x) min=x;9

if (max

if (min>x) min=x;8

if (max

if (min>x) min=x;7

if (max

if (min>x) min=x;6

if (max

if (min>x) min=x;5

Question 5: Write recursive function to solve the problem of Hanoi tower

Write recursive function to solve the problem of Hanoi tower: It is necessary to transfer n towers from position A to position B using position C as an intermediary. Requirements: Only one floor can be transferred at a time, only the A, B, C positions can be used to place the tower floors, not the raised floor on the small floor. The main function uses this function and can run several times to calculate for many different numbers entered from the keyboard.

Sample code:

 if (max 

if (min>x) min=x;4

if (max

if (min>x) min=x;3

if (max

if (min>x) min=x;2

if (max

if (min>x) min=x;1

if (max

if (min>x) min=x;0

if (x>0) sd++;9

if (x>0) sd++;8

if (x>0) sd++;7

if (x>0) sd++;6

if (x>0) sd++;5

if (x>0) sd++;4

if (x>0) sd++;3

if (x>0) sd++;2

if (x>0) sd++;1

if (x>0) sd++;0

ts++;9

ts++;8

ts++;7

ts++;6 ts++;5

ts++;4

ts++;3

ts++;2

ts++;1

ts++;0

}9

}8

}7

}6

}5

}4

}3

}2

}1

}0

}9

}8

}7 }6

}5

}4

}3

}2

}1

}0

if(x>0)sd--;9

if(x>0)sd--;8

if(x>0)sd--;7

if(x>0)sd--;6

if(x>0)sd--;5

if(x>0)sd--;4

if(x>0)sd--;3

if(x>0)sd--;2

if(x>0)sd--;1

if(x>0)sd--;0

ts--;//So nguyen sau cung duoc doc 2 lan9

ts--;//So nguyen sau cung duoc doc 2 lan8 ts--;//So nguyen sau cung duoc doc 2 lan7

ts--;//So nguyen sau cung duoc doc 2 lan6

ts--;//So nguyen sau cung duoc doc 2 lan5

ts--;//So nguyen sau cung duoc doc 2 lan4

ts--;//So nguyen sau cung duoc doc 2 lan3

ts--;//So nguyen sau cung duoc doc 2 lan2

ts--;//So nguyen sau cung duoc doc 2 lan1

ts--;//So nguyen sau cung duoc doc 2 lan0

fclose(fp);9

fclose(fp);8

fclose(fp);7

fclose(fp);6

fclose(fp);5

fclose(fp);4

fclose(fp);3

fclose(fp);2

fclose(fp);1

fclose(fp);0

printf("Tat ca co %d so nguyenn",ts);9
printf("Tat ca co %d so nguyenn",ts);8

printf("Tat ca co %d so nguyenn",ts);7

printf("Tat ca co %d so nguyenn",ts);6

printf("Tat ca co %d so nguyenn",ts);5

printf("Tat ca co %d so nguyenn",ts);4

printf("Tat ca co %d so nguyenn",ts);3

printf("Tat ca co %d so nguyenn",ts);2

printf("Tat ca co %d so nguyenn",ts);1

printf("Tat ca co %d so nguyenn",ts);0

printf("Trong do so luong so duong = %dn",sd);9

printf("Trong do so luong so duong = %dn",sd);8

printf("Trong do so luong so duong = %dn",sd);7

printf("Trong do so luong so duong = %dn",sd);6

printf("Trong do so luong so duong = %dn",sd);5

printf("Trong do so luong so duong = %dn",sd);4

printf("Trong do so luong so duong = %dn",sd);3

printf("Trong do so luong so duong = %dn",sd);2

printf("Trong do so luong so duong = %dn",sd);1

printf("Trong do so luong so duong = %dn",sd);0 printf("Max=%d, Min=%d",max,min);9

printf("Max=%d, Min=%d",max,min);8

printf("Max=%d, Min=%d",max,min);7

printf("Max=%d, Min=%d",max,min);6

printf("Max=%d, Min=%d",max,min);5

printf("Max=%d, Min=%d",max,min);4

printf("Max=%d, Min=%d",max,min);3

printf("Max=%d, Min=%d",max,min);2

printf("Max=%d, Min=%d",max,min);1

printf("Max=%d, Min=%d",max,min);0

getch();9

getch();8

getch();7

getch();6

getch();5

getch();4

getch();3

getch();2

getch();1 getch();0

}9

}8

}7

}6

}5

}4

}3

}2

}1

}0

if (max

if (min>x) min=x;9

if (max

if (min>x) min=x;8

if (max

if (min>x) min=x;7

if (max

if (min>x) min=x;6

if (max

if (min>x) min=x;5

if (max

if (min>x) min=x;4

if (max

if (min>x) min=x;3

if (max

if (min>x) min=x;2 if (max

if (min>x) min=x;1

if (max

if (min>x) min=x;0

if (x>0) sd++;9

if (x>0) sd++;8

if (x>0) sd++;7

if (x>0) sd++;6

if (x>0) sd++;5

if (x>0) sd++;4

if (x>0) sd++;3

if (x>0) sd++;2

if (x>0) sd++;1

if (x>0) sd++;0

ts++;9

ts++;8

ts++;7

ts++;6

ts++;5

ts++;4

ts++;3 ts++;2

ts++;1

ts++;0

}9

}8

}7

}6

}5

}4

}3

}2

}1

}0

}9

}8

}7

}6

}5

}4 }3

}2

}1

}0

if(x>0)sd--;9

if(x>0)sd--;8

if(x>0)sd--;7

if(x>0)sd--;6

if(x>0)sd--;5

if(x>0)sd--;4

if(x>0)sd--;3

if(x>0)sd--;2

if(x>0)sd--;1

if(x>0)sd--;0

ts--;//So nguyen sau cung duoc doc 2 lan9

ts--;//So nguyen sau cung duoc doc 2 lan8

ts--;//So nguyen sau cung duoc doc 2 lan7

ts--;//So nguyen sau cung duoc doc 2 lan6

ts--;//So nguyen sau cung duoc doc 2 lan5

C ++ exercise # 4

Question 1: Print the elements of the array as required

Enter the array of n real numbers, find and print the smallest, largest element, and calculate and print the arithmetic mean of the elements in the array. Print smaller, larger elements than the average.

Sample code:

 ts--;//So nguyen sau cung duoc doc 2 lan4 

ts--;//So nguyen sau cung duoc doc 2 lan3

ts--;//So nguyen sau cung duoc doc 2 lan2

ts--;//So nguyen sau cung duoc doc 2 lan1

ts--;//So nguyen sau cung duoc doc 2 lan0

fclose(fp);9

fclose(fp);8

fclose(fp);7

fclose(fp);6

fclose(fp);5

fclose(fp);4

fclose(fp);3

fclose(fp);2

fclose(fp);1

fclose(fp);0

printf("Tat ca co %d so nguyenn",ts);9

printf("Tat ca co %d so nguyenn",ts);8

printf("Tat ca co %d so nguyenn",ts);7

printf("Tat ca co %d so nguyenn",ts);6

printf("Tat ca co %d so nguyenn",ts);5

printf("Tat ca co %d so nguyenn",ts);4

printf("Tat ca co %d so nguyenn",ts);3
printf("Tat ca co %d so nguyenn",ts);2 printf("Tat ca co %d so nguyenn",ts);1

printf("Tat ca co %d so nguyenn",ts);0

printf("Trong do so luong so duong = %dn",sd);9

printf("Trong do so luong so duong = %dn",sd);8

printf("Trong do so luong so duong = %dn",sd);7

printf("Trong do so luong so duong = %dn",sd);6

printf("Trong do so luong so duong = %dn",sd);5

printf("Trong do so luong so duong = %dn",sd);4

printf("Trong do so luong so duong = %dn",sd);3

printf("Trong do so luong so duong = %dn",sd);2

printf("Trong do so luong so duong = %dn",sd);1

printf("Trong do so luong so duong = %dn",sd);0

printf("Max=%d, Min=%d",max,min);9

printf("Max=%d, Min=%d",max,min);8

printf("Max=%d, Min=%d",max,min);7

printf("Max=%d, Min=%d",max,min);6

printf("Max=%d, Min=%d",max,min);5

printf("Max=%d, Min=%d",max,min);4

printf("Max=%d, Min=%d",max,min);3

printf("Max=%d, Min=%d",max,min);2

printf("Max=%d, Min=%d",max,min);1

printf("Max=%d, Min=%d",max,min);0 getch();9

getch();8

getch();7

getch();6

getch();5

getch();4

getch();3

getch();2

getch();1

getch();0

}9

}8

}7

}6

}5

}4

}3

}2

}1

}0

#include9

#include8 #include7

#include6

#include5

#include4

#include3

#include2

#include1

#include0

#include9

#include8

#include7

#include6

#include5

#include4

#include3

#include2

#include1

#include0

#include9

#include8

#include7

#include6 #include5

#include4

#include3

#include2

#include1

#include0

void main()9

void main()8

void main()7

void main()6

void main()5

void main()4

void main()3

void main()2

void main()1

void main()0

{char i,s[30];9

{char i,s[30];8

{char i,s[30];7

{char i,s[30];6

{char i,s[30];5

{char i,s[30];4 {char i,s[30];3

{char i,s[30];2

{char i,s[30];1

{char i,s[30];0

FILE *f;9

FILE *f;8

FILE *f;7

FILE *f;6

FILE *f;5

FILE *f;4

FILE *f;3

FILE *f;2

FILE *f;1

FILE *f;0

clrscr();9

clrscr();8

clrscr();7

clrscr();6

clrscr();5

clrscr();4

clrscr();3

clrscr();2 clrscr();1

clrscr();0

f=fopen("DSSV.TXT","w");9

f=fopen("DSSV.TXT","w");8

f=fopen("DSSV.TXT","w");7

f=fopen("DSSV.TXT","w");6

f=fopen("DSSV.TXT","w");5

f=fopen("DSSV.TXT","w");4

f=fopen("DSSV.TXT","w");3

f=fopen("DSSV.TXT","w");2

f=fopen("DSSV.TXT","w");1

f=fopen("DSSV.TXT","w");0

i=1;9

i=1;8

i=1;7

i=1;6

i=1;5

i=1;4

i=1;3

i=1;2

i=1;1

i=1;0 printf("Nhap ho ten cua tung hoc sinh, ket thuc go Entern");9

printf("Nhap ho ten cua tung hoc sinh, ket thuc go Entern");8

printf("Nhap ho ten cua tung hoc sinh, ket thuc go Entern");7

printf("Nhap ho ten cua tung hoc sinh, ket thuc go Entern");6

printf("Nhap ho ten cua tung hoc sinh, ket thuc go Entern");5

printf("Nhap ho ten cua tung hoc sinh, ket thuc go Entern");4

printf("Nhap ho ten cua tung hoc sinh, ket thuc go Entern");3

printf("Nhap ho ten cua tung hoc sinh, ket thuc go Entern");2

printf("Nhap ho ten cua tung hoc sinh, ket thuc go Entern");1

printf("Nhap ho ten cua tung hoc sinh, ket thuc go Entern");0

do9

do8

do7

do6

do5

do4

do3

do2

do1

do0

{printf("Ho ten hoc sinh thu %d : ",i++);9

{printf("Ho ten hoc sinh thu %d : ",i++);8 {printf("Ho ten hoc sinh thu %d : ",i++);7

{printf("Ho ten hoc sinh thu %d : ",i++);6

{printf("Ho ten hoc sinh thu %d : ",i++);5

{printf("Ho ten hoc sinh thu %d : ",i++);4

{printf("Ho ten hoc sinh thu %d : ",i++);3

{printf("Ho ten hoc sinh thu %d : ",i++);2

{printf("Ho ten hoc sinh thu %d : ",i++);1

{printf("Ho ten hoc sinh thu %d : ",i++);0

gets(s);9

gets(s);8

gets(s);7

gets(s);6

gets(s);5

gets(s);4

gets(s);3

gets(s);2

gets(s);1

gets(s);0

if (strlen(s)>0)9

if (strlen(s)>0)8

if (strlen(s)>0)7

if (strlen(s)>0)6 if (strlen(s)>0)5

if (strlen(s)>0)4

if (strlen(s)>0)3

if (strlen(s)>0)2

if (strlen(s)>0)1

if (strlen(s)>0)0

{strcat(s,"n");9

{strcat(s,"n");8

{strcat(s,"n");7

{strcat(s,"n");6

{strcat(s,"n");5

{strcat(s,"n");4

{strcat(s,"n");3

{strcat(s,"n");2

{strcat(s,"n");1

{strcat(s,"n");0

fputs(s,f);9

fputs(s,f);8

fputs(s,f);7

fputs(s,f);6

fputs(s,f);5

fputs(s,f);4 fputs(s,f);3

fputs(s,f);2

fputs(s,f);1

fputs(s,f);0

}9

}8

}7

}6

}5

}4

}3

}2

}1

}0

}while (strlen(s)>0);9

}while (strlen(s)>0);8

}while (strlen(s)>0);7

}while (strlen(s)>0);6

}while (strlen(s)>0);5

}while (strlen(s)>0);4

}while (strlen(s)>0);3

}while (strlen(s)>0);2 }while (strlen(s)>0);1

}while (strlen(s)>0);0

fclose(f);9

fclose(f);8

fclose(f);7

fclose(f);6

fclose(f);5

fclose(f);4

fclose(f);3

fclose(f);2

fclose(f);1

fclose(f);0

clrscr();9

clrscr();8

clrscr();7

clrscr();6

clrscr();5

clrscr();4

clrscr();3

clrscr();2

clrscr();1

clrscr();0 f=fopen("DSSV.TXT","r");9

f=fopen("DSSV.TXT","r");8

f=fopen("DSSV.TXT","r");7

f=fopen("DSSV.TXT","r");6

f=fopen("DSSV.TXT","r");5

f=fopen("DSSV.TXT","r");4

f=fopen("DSSV.TXT","r");3

f=fopen("DSSV.TXT","r");2

f=fopen("DSSV.TXT","r");1

f=fopen("DSSV.TXT","r");0

printf("Danh sach hoc sinh doc tu tep :nn");9

printf("Danh sach hoc sinh doc tu tep :nn");8

printf("Danh sach hoc sinh doc tu tep :nn");7

printf("Danh sach hoc sinh doc tu tep :nn");6

printf("Danh sach hoc sinh doc tu tep :nn");5

printf("Danh sach hoc sinh doc tu tep :nn");4

printf("Danh sach hoc sinh doc tu tep :nn");3

printf("Danh sach hoc sinh doc tu tep :nn");2

printf("Danh sach hoc sinh doc tu tep :nn");1

printf("Danh sach hoc sinh doc tu tep :nn");0

i=1;9

i=1;8 i=1;7

i=1;6

i=1;5

i=1;4

i=1;3

i=1;2

i=1;1

i=1;0

while (fgets(s,30,f))9

while (fgets(s,30,f))8

while (fgets(s,30,f))7

while (fgets(s,30,f))6

while (fgets(s,30,f))5

while (fgets(s,30,f))4

while (fgets(s,30,f))3

while (fgets(s,30,f))2

while (fgets(s,30,f))1

while (fgets(s,30,f))0

{printf("%d. ",i++);9

{printf("%d. ",i++);8

{printf("%d. ",i++);7

{printf("%d. ",i++);6 {printf("%d. ",i++);5

{printf("%d. ",i++);4

{printf("%d. ",i++);3

{printf("%d. ",i++);2

{printf("%d. ",i++);1

{printf("%d. ",i++);0

puts(s);9

puts(s);8

puts(s);7

puts(s);6

puts(s);5

puts(s);4

puts(s);3

puts(s);2

puts(s);1

puts(s);0

}9

}8

}7

}6

}5

}4 }3

}2

}1

}0

fclose(f);9

fclose(f);8

fclose(f);7

fclose(f);6

fclose(f);5

fclose(f);4

fclose(f);3

fclose(f);2

fclose(f);1

fclose(f);0

getch();9

getch();8

getch();7

getch();6

getch();5

getch();4

getch();3

getch();2

Question 3: Enter, print array, count paragraphs according to criteria

Write a function to import arrays, a function that prints elements of an array to the screen, an increase in the number of paragraphs, a function that finds the longest increase in the array. The main function uses these functions to enter the element n array, print the array, print the number of increments and the longest increase in the array.

Sample code:

 getch();1 

getch();0

}9

}8

}7

}6

}5

}4

}3

}2

}1

}0

#include9

#include8

#include7

#include6

#include5

#include4

#include3

#include2

#include1

#include0

#include9

#include8

#include7

#include6

#include5

#include4

#include3

#include2

#include1

#include0

struct sv9

struct sv8

struct sv7

struct sv6

struct sv5

struct sv4

struct sv3

struct sv2

struct sv1

struct sv0

{char maso[10];9

{char maso[10];8

{char maso[10];7

{char maso[10];6

{char maso[10];5

{char maso[10];4

{char maso[10];3

{char maso[10];2

{char maso[10];1

Question 4: Enter, print, calculate 2 matrices

Write a function that imports the elements of a 2-dimensional matrix, a matrix printing function in column rows, a function that multiplies 2 matrices. The main function uses these functions to enter the MxN size matrix A and the NxP size matrix B. Print matrix A and B and matrix C are the product of 2 matrices A and B.

Sample code:

 {char maso[10];0 

char ht[25];9

char ht[25];8

char ht[25];7

char ht[25];6

char ht[25];5

char ht[25];4

char ht[25];3

char ht[25];2

char ht[25];1

char ht[25];0

float dtb;9

float dtb;8

float dtb;7

float dtb;6

float dtb;5

float dtb;4

float dtb;3

float dtb;2

float dtb;1

float dtb;0

};9

};8

};7

};6

};5

};4

};3

};2

};1

};0

void main()9

void main()8

void main()7

void main()6

void main()5

void main()4

void main()3

void main()2

void main()1

void main()0

{int i,n;9

{int i,n;8

{int i,n;7

{int i,n;6

{int i,n;5

{int i,n;4

{int i,n;3

{int i,n;2

{int i,n;1

{int i,n;0

float d;9

float d;8

float d;7

float d;6

float d;5

float d;4

float d;3

float d;2

float d;1

float d;0

Question 5: Enter, print square matrix, determinant

Write a function that imports elements of a square matrix of n-level, a matrix printing function according to the column row structure, a function of deterministic matrix matrix n. The main function uses these functions to enter the square matrix of n levels, prints the matrix, calculates and prints the determinant of that matrix.

Sample code:

 sv bg;9 

sv bg;8

sv bg;7

sv bg;6

sv bg;5

sv bg;4

sv bg;3

sv bg;2

sv bg;1

sv bg;0

FILE *f;9

FILE *f;8

FILE *f;7

FILE *f;6

FILE *f;5

FILE *f;4

FILE *f;3

FILE *f;2

FILE *f;1

FILE *f;0

clrscr();9

clrscr();8

clrscr();7

clrscr();6

clrscr();5

clrscr();4

clrscr();3

clrscr();2

clrscr();1

clrscr();0

f=fopen("HosoSV.DAT","w+b");9

f=fopen("HosoSV.DAT","w+b");8

f=fopen("HosoSV.DAT","w+b");7

f=fopen("HosoSV.DAT","w+b");6

f=fopen("HosoSV.DAT","w+b");5

f=fopen("HosoSV.DAT","w+b");4

f=fopen("HosoSV.DAT","w+b");3

f=fopen("HosoSV.DAT","w+b");2

f=fopen("HosoSV.DAT","w+b");1

f=fopen("HosoSV.DAT","w+b");0

printf("Nhap so sv n=");9

printf("Nhap so sv n=");8

printf("Nhap so sv n=");7

printf("Nhap so sv n=");6

printf("Nhap so sv n=");5

printf("Nhap so sv n=");4

printf("Nhap so sv n=");3

printf("Nhap so sv n=");2

printf("Nhap so sv n=");1

printf
Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile