Replaying the old tune: BC/C++ language program programming learning: 10 basic algorithm science posts

The B|C language algorithm is the soul of building website programs and software. As an excellent website development program coder, only a comprehensive grasp of some basic algorithms will appear in the process of building website programs and writing codes in the future. Calm down.

1. Calculate the Fibonacci sequence

The Fibonacci sequence is also known as the Fibonacci sequence and the golden section sequence. It refers to such a sequence: 1, 1, 2, 3, 5, 8, 13, 21.

2. B/C language program system palindrome check

3. B/C language program system prime number check

1 is neither a prime number nor a composite number.

4. B/C language program to print pyramids and triangles

 Use * to create a triangle

5. Simple addition, subtraction, multiplication and division calculator for B/C language programs

C language source code:

}

 

6. Check whether a number can be expressed as the sum of two prime numbers

7. Recursively reverse the string

8. Realize the mutual conversion between binary and decimal

Source code:

#include <stdio.h>#include <math.h>int binary_decimal(int n);int decimal_binary(int n);int main()

{int n;char c;

printf("Instructions:n");

printf("1. Enter alphabet 'd' to convert binary to decimal.n");

printf("2. Enter alphabet 'b' to convert decimal to binary.n");

scanf("%c",&c);if (c =='d' || c == 'D')

{

printf("Enter a binary number: ");

scanf("%d", &n);

printf("%d in binary = %d in decimal", n, binary_decimal(n));

}if (c =='b' || c == 'B')

{

printf("Enter a decimal number: ");

scanf("%d", &n);

printf("%d in decimal = %d in binary", n, decimal_binary(n));

}return 0;

}int decimal_binary(int n) /* Function to convert decimal to binary.*/{int rem, i=1, binary=0;while (n!=0)

{

rem=n%2;

n/=2;

binary+=rem*i;

i*=10;

}return binary;

}int binary_decimal(int n) /* Function to convert binary to decimal.*/{int decimal=0, i=0, rem;while (n!=0)

{

rem = n%10;

n/=10;decimal += rem*pow(2,i);++i;

}return decimal;

}

 

9、使用多维数组实现两个矩阵的相加

10、矩阵转置

3421b3dc8305352156e4dac5885b17bf.jpeg

 


Guess you like

Origin blog.51cto.com/14454095/2666236