Trending November 2023 # Basic Syntax Of Mariadb Logs With Examples # Suggested December 2023 # Top 15 Popular

You are reading the article Basic Syntax Of Mariadb Logs With Examples updated in November 2023 on the website Minhminhbmm.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested December 2023 Basic Syntax Of Mariadb Logs With Examples

Definition of MariaDB Logs

MariaDB server uses a different log file such as error log file, binary log file, general query log, and slow query log files. As per our requirement, we can change the status of log files that enable and disable log files. The main purpose of a log file is that to store different data during the different operation, for example, if we consider error log file, the error log file is used to store the critical error occurred during the MariaDB server operation, table corruption and start and stop information. If we consider SQL errors it can also be used in different log files by using the SQL_ERROR plugin.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax:

set global log type = value;

Explanation:

show global variables like 'log file name';

Explanation:

In the above example, we use show global variable command to see the log file, here we use log file name means you can use any log file name to see the details of a specified log file.

How Logs works in MariaDB?

Now let’s see how logs work in MariaDB as follows. Basically, MariaDB uses different log files let’s see one by one.

1. Error Log

In this log file, it contains all records of critical errors that occurred during the different operations of the server like a corrupted table, which service start and stop information. SQL error is also used in a separate log file using the SQL_ERROR_LOG plugin.

Now let’s see how we can write error logs to a file.

When we need to configure an error log to write a log file at that time we must need to set the log_error system variable. By using a system variable we can configure a specific file name, if we don’t use specified file name to the configuration at that time log will be written to chúng tôi file in the directory and this is by default directory.

We can set the log_error system variable by using the server option group. For example to write error log in by default log file that is ${hostname}.err. We need to configure the following line as follows.

[mariadb] …… log_error

If we need to configure a specific file name as a log_error system variable and this file doesn’t have an absolute path then it uses a relative path to the datadir directory. Now see the following example of a configured error log that would be written to the chúng tôi file from datadir directory.

[mariadb] …… log_error = mariadb.err

See in above example path is a relative path but some it also uses absolute path. For example:

[mariadb] …… log_error = C:Program Files (x86)MariaDB 10.5includemysqlmariadb.err.

We can also use another path to configure the error log file that is to set log – basename option which is configured by MariaDB.

2. General Query Log

The general query log file is used to store all details about every SQL query received from the client-side as well as all connected and disconnected client information.

Now see how we can enable the general query log as follows.

The general query log is to be disabled by default. To enable the general log file then we need to set the general_log system variable to 1 and it also changes dynamically.

For Example: 

set global general_log = 1;

We can also set general_log file by using the server option group. For example:

[mariadb] ……….. general_log

Now see how we can configure the general query log file name as follows.

set global general_log_file = 'mariadb.log';

We can also set the general_log_file by using the server option group from the file option. for example:

[mariadb] …………….. general_log general_log_file = mariadb.log

In the above example, we use a relative path but it also uses an absolute path.

Let’s see how we select the destination file for the general query log as follows.

It can be written to a file on disk or it can be written on the general_log table in the MySQL database. For selecting the destination file for output we use log_output system variable.

set global log_output = 'specified file name'; 3. Slow Query Log

In this type of log file, the slow query log file is used to store records of SQL queries that take a long time to execute. In this type of query, the password then slow query log also contains the password.

Now let’s see how we can enable the slow query log as follows.

To enable the slow query log file we use the slow_query_log system variable that means we set the global variable is 1 as follows.

set global slow_query_log = 1

We can also set it by using the server option group from the file option.

Configuration of the slow query log by using the file name as follows.

We can configure the slow query log by using a filename that means we need to set a slow_query_log_file system variable by using the relative path as well as an absolute path, same like the above-mentioned types.

4. Binary Log Examples

Let’s see the different examples of MariaDB log as follows.

Suppose we need to show log error at that time we use the following statement.

show global variables like 'log_error';

Explanation:

In the above example, we use the show variable command to show log error. The final output of the show databases queries we illustrate by using the following snapshot.

Now how we can set the global general log by using the following statement.

set global general_log = 1;

Explanation:

The final output of the show databases queries we illustrate by using the following snapshot.

In this way, we can set all log types as per requirement.

Conclusion

We hope from this article you have understood about the MariaDB Logs. From this article, we have learned the basic syntax of MariaDB Logs and we also see different examples of MariaDB Logs. From this article, we learned how and when we use MariaDB Logs.

Recommended Articles

We hope that this EDUCBA information on “MariaDB Logs” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

You're reading Basic Syntax Of Mariadb Logs With Examples

Syntax And Examples Of Sql Ceiling

Introduction to SQL Ceiling

SQL Ceiling function is the mathematical function available in SQL that is used for the numeric type of values. These numeric values can be either integers or floating-point numbers. If the numeric value is formatted inside the string type of value as parameter then that value is also allowed for Ceiling function. In short, any value or expression that can be deduced to the numeric value can be used as a parameter to the Ceiling() mathematical function in SQL. This function helps us retrieve the minimum integer value that is greater or equivalent to the passed value.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

In this article, we will learn about how Ceiling function can be used to retrieve the integral value not less than the passed numeric value or expression, its syntax, and some of the examples that can help to make the implementation of the Ceiling() function easy and understandable.

The below is the syntax for the mathematical Ceiling() function in SQL –

Ceiling(expressionOrNumber);

expressionOrNumber: expressionOrNumber can be any integer or floating-point value or even a decimal value. In case if this numeric value is wrapped into strings then these string values are also acceptable. Other than the direct specification of numeric value any expression that will ultimately deduce to a numeric value is also allowed as a parameter to the Ceiling() function.

Return value: The return value of the Ceiling() function is the smallest integer value that is greater than or equal to the value that is passed as the parameter to the function. The type of the return value is dependent on the data type of the value that is passed as the parameter to the Ceiling() function. In case if the parameter is or integer data type then the return value is also of integer type. While in other cases if the deduced value of the parameter of the direct specification of the value of the parameter is of floating-point type then the datatype of the return value is of the floating-point data type itself.

Examples of SQL Ceiling

Following are the examples are given below:

1. Using Ceiling() function with Positive Values

We will consider the positive numeric value say 3.59 and then use the Ceiling function to retrieve the smallest integer value that is greater than or equivalent to the 3.59 value. Let us execute the following SQL query statement and observe the output –

SELECT Ceiling(3.59);

Output:

Let us consider one more example of positive value. But in this example, we will use an expression that will evaluate to the value that is of numeric type. Simply consider the expression 5 * 1.65 whose actual value is 8.25 and use this expression in Ceiling() function to retrieve minimum integral value greater than passed value using following query statement –

SELECT Ceiling(5 * 1.65);

Output:

Now, we will consider a positive number wrapped as a string and use it as a parameter to Ceiling() function. For example, consider “56.569” value that is used in the following manner –

SELECT Ceiling(56.569);

Output:

2. Using Ceiling() Function with Negative Values

We will consider the negative numeric value say -65.55 and then use the Ceiling function to retrieve the smallest integer value that is greater than or equivalent to the -65.55 value. Let us execute the following SQL query statement and observe the output –

SELECT Ceiling(-65.55);

Output:

Let us consider one more example of a negative value. But in this example, we will use an expression that will evaluate to the value that is of numeric type. Simply consider the expression 8 * -91.65 whose actual value is −733.2 and use this expression in Ceiling() function to retrieve minimum integral value greater than passed value using following query statement –

SELECT Ceiling(8 * -91.65);

Output:

Now, we will consider a negative number wrapped as a string and use it as a parameter to Ceiling() function. For example, consider “-98.154″value that is used in the following manner –

SELECT Ceiling(-98.154);

Output:

3. Using Ceiling() Function with Values in The Table

Let us now see how we can use the Ceiling() function in the query statements on the values of the columns of the table. We will create one table named workers using following query statement –

CREATE TABLE `workers` ( `developer_id` int(11) NOT NULL AUTO_INCREMENT, `team_id` int(11) NOT NULL, `name` varchar(100) DEFAULT NULL, `position` varchar(100) DEFAULT NULL, `technology` varchar(100) DEFAULT NULL, `salary` int(11) DEFAULT NULL, PRIMARY KEY (`developer_id`), UNIQUE KEY `name` (`name`) ) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=latin1;

Output:

INSERT INTO `workers` VALUES (1,1,'Payal','Developer','Angular',30000), (2,1,'Heena','Developer','Angular',10000), (3,3,'Vishnu','Manager','Maven',25000), (4,3,'Rahul','Support','Digital Marketing',15000), (5,3,'Siddhesh','Tester','Maven',20000), (6,7,'Siddharth','Manager','Java',25000), (7,4,'Brahma','Developer','Digital Marketing',30000), (8,1,'Arjun','Tester','Angular',19000), (9,2,'Nitin','Developer','SQL',20000), (10,2,'Ramesh','Administrator','SQL',30000), (11,2,'Rohan','Admin',NULL,20000), (12,2,'Raj','Designer',NULL,30000);

Output:

Now we will calculate the average salary using the following query statement –

SELECT avg(salary) from workers;

Output:

If we want to retrieve the average salary in integer format with the greatest value that is greater than or equivalent to the average value using Ceiling() function using the following query statement –

SELECT Ceiling (avg(salary)) from workers;

Output:

Conclusion

Mathematical function Ceiling() is used rounding numeric values in SQL. We can retrieve the minimum value in integer format that is greater or equivalent to the passed numeric number or expression whose results can be either floating value of an integer or decimal value. The working of Ceiling() function is exactly different than Floor() function. Though both of them are used for rounding. Ceiling() funtion rounds up while Floor() function rounds down the numeric value.

Recommended Articles

We hope that this EDUCBA information on “SQL Ceiling” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Working Of Python Uuid With Examples

Introduction to Python UUID

In this article, we will discuss Python UUID which is a Python module used for implementing or generating the universally unique identifiers and is also known as GUID globally unique identifiers. Python UUID module generates the identifiers randomly which have the value of 128 bit long and these identifiers are useful for documents or information in computer systems, apps, hosts, and many different situations that will use unique identifiers. This Python UUID module provides different immutable Objects and different versions of functions such as uuid1(), uuid3(), uuid4(), uuid5() which are used for generating UUID’s of versions 1, 3, 4, and 5.

Start Your Free Software Development Course

Working of Python UUID with Examples

In Python, there is a library or module which is inbuilt and is used for generating unique identifiers that are universal or global and this module is known as UUID, this module can also generate different versions of UUIDs and these modules are immutable which means their value cannot be altered once generated. UUID is mainly composed of 5 components with fixed lengths and each component is separated by a hyphen and uses read attributes to define the UUID string. This Python UUID is implemented based on RFC 4211 which includes different algorithms and information regarding the unique identifiers that are to be generated along with the required versions of UUIDs. In Python, this module provides various functions for different versions such as uuid1(), uuid3(), uuid4() and uuid5().

In Python, the UUID module provides various read-only attributes such as:

UUID.bytes which includes a 16-byte string.

UUID.fields which includes fields like time, clock_seq, node, etc.

UUID.hex can hold the 32-bit hexadecimal string.

UUID.int can hold 128-bit integer

UUID.Safe this attribute tells us the uuid version used is safe or not.

Examples of Python UUID

In the below section let us see a few examples of the use of function uuid1(), uuid3(), uuid4() and uuid5() using Python UUID module which is mainly used for generating UUID using MAC address. We will also see how the UUID looks like which means the structure of UUID.

Example #1

But we should note that when using uuid1() it might display network details such as the network address of the computer in UUID so it is not so safe to use uuid1() as it may arise privacy problems because it uses the systems MAC address. Let us see a simple example.

Code:

import uuid print("Progam to demonstrate uuid1() function:") print("n") uuid_version_1 = uuid.uuid1() print("UUID of version one is as follows", uuid_version_1)

Output:

In the above program, we can see the uuid1() function is used which generates the host id, the sequence number is displayed. We can compute these function values using the MAC address of the host and this can be done using the getnode() method of UUID module which will display the MAC value of a given system. Say for example

print(hex(uuid.getnode())) Example #2

Code:

import uuid print("Program to demonstrate uuid4() function:") print("n") unique_id = uuid.uuid4() print ("The unique id generated using uuid4() function : ") print (unique_id)

Output:

In the above program, we can see a unique id is generated using uuid4(). The uuid4() generates id using cryptographically secure random number generators hence there is less chance of collision.

Now we will see uuid3() and uuid5() where we saw a generation of UUID using random numbers now we will see how to generate UUIDs using names instead of random numbers using uuid3() and uuid5() which uses cryptographic hash values such as MD5 or SHA-1 to combine values with the names like hostnames, URLs, etc. In general, uuid3() and uuid5() versions are hashing namespace identifiers with a name, and few namespaces are defined by UUID module such as UUID.NAmESPACE_DNS, UUID.NAmESPACE_URL, etc. Now let us see an example below.

Example #3

Code:

import uuid print("Program to demonstrate uuid3() and uuid5() is as follows:") print("n") for hostname in hosts_sample: print("Hostname specified is as follows: ",hostname) print('tThe SHA-1 value of the given hostname:', uuid.uuid5(uuid.NAMESPACE_DNS, hostname)) print('tThe MD5 value of the given hostname :', uuid.uuid3(uuid.NAMESPACE_DNS, hostname)) print("n")

In the above program, we can see we are using uuid3() and uuid5() functions which generate UUID at different times but with the same namespace and same name. In the above program, we have two different hostnames and we are iterating using for loop. We can specify any number of hostnames and can iterate it using for loop.

As UUID is a unique universal identifier there are some privacy issues as we saw in the above section uuid1() compromises with privacy as it uses systems MAC address whereas uuid4() doesn’t compromise with privacy hence it uses a random number generator for generating UUIDs. Therefore we can say uuid1() is not safe to use and uuid4() is safer than uuid1(). Therefore to check if the UUID functions are safe in the latest Python version 3.7 an instance of UUID such as is_safe attribute is used to check for UUID is safe or not. UUIDs are used in various applications such as in web apps, database systems, etc. In Python, we can convert UUID to string and vice versa using str class and we can obtain string format removing the hyphen that is used for separation of components in UUID using string method replace() by replacing “-” with “” say for example

UUID_id = uuid.uuid1() str_uuid = str(UUID_id). replace("-", "")

And similarly, we can convert the string back to UUID using UUID instance such as follows:

uuid_id = uuid.UUID(string) Conclusion

In this article, we conclude that UUID is a unique universal identifier and is also known as a global identifier. In this article, we also saw the Python UUID module to generate the identifiers using a few uuid functions of different versions and we also saw different uuid() versions such as uuid1(), uuid3(), uuid4(), and uuid5() with examples and their privacy terms. In this, we also saw different read attributes, safety checks for uuid() function, and also saw the conversion of UUID to string and vice versa.

Recommended Articles

This is a guide to Python UUID. Here we also discuss the introduction and working of python uuid along with different examples and its code implementation. You may also have a look at the following articles to learn more –

Functions Of C# Startswith() With Examples

Introduction to C# StartsWith()

Web development, programming languages, Software testing & others

Syntax:

The syntax of C# StartsWith() method is as follows:

public bool StartsWith(String string_name);

where string_name is the name of the string which is matched for the beginning instance of the given string.

Working of C# StartsWith()

Working of C# StartsWith() method is as follows:

Whenever there is a need to determine if the beginning of any string matches the beginning of the given string, we make use of the StartsWith() method in C#.

The StartsWith() method in C# is a string method that returns a Boolean value, which is either true or false.

The StartsWith() method returns true if the string matches the beginning instance of the given string.

The StartsWith() method returns false if the string matches the beginning instance of the given string.

Examples of C# StartsWith()

Following are the examples as given below:

Example #1

C# program to demonstrate the use of StartsWith() method to check if the beginning of any string matches the beginning of the given string:

using System; public class check { public static void Main(string[] args) { string string1 = "Welcome to C#"; bool bval1 = string1.StartsWith("Welcome"); bool bval2 = string1.StartsWith("w"); Console.WriteLine("The string Welcome matches the beginning instance of the given string Welcome to C#: {0}", bval1); Console.WriteLine("The string w matches the beginning instance of the given string Welcome to C#: {0}", bval2); } }

Output:

In the above program, a class called check is defined. Then the main method is called within which a string variable is defined to store the string value which is checked to see if there is a match of beginning instance in this string with reference to the other string compared. Then StartsWith() method is used to check if there is a match to the beginning instance of the given string with reference to the other string passed as a parameter to it. The first string Welcome is checked against the given string Welcome to C# to find if there is a beginning instance in Welcome to C# matching the string Welcome and the output returned is True because Welcome is present in Welcome to C# whereas when w is checked against the given string Welcome to C# to find if there is a beginning instance in Welcome to C# matching the string w and the output returned is False because w is not present in Welcome to C#.

Example #2

Example 2: C# program to demonstrate the use of StartsWith() method to check if the beginning of any string matches the beginning of the given string:

using System; public class check { public static void Main(string[] args) { string string1 = "Learning is fun"; bool bval1 = string1.StartsWith("l"); bool bval2 = string1.StartsWith("Learning"); Console.WriteLine("The string l matches the beginning instance of the given string Welcome to C#: {0}", bval1); Console.WriteLine("The string Learning matches the beginning instance of the given string Welcome to C#: {0}", bval2); } }

Output:

In the above program, a class called check is defined. Then the main method is called within which a string variable is defined to store the string value which is checked to see if there is a match of beginning instance in this string with reference to the other string compared. Then StartsWith() method is used to check if there is a match to the beginning instance of the given string with reference to the other string passed as a parameter to it. The first string l is checked against the given string Learning if fun to find if there is a beginning instance in Learning is fun matching the string l and the output returned is False because l is not present in Learning is fun whereas when Learning is checked against the given string Learning is fun to find if there is a beginning instance in Learning is fun matching the string Learning and the output returned is True because Learning is present in Learning is fun.

The StartsWith() method is used to check the beginning instance of a given string with the reference to the other string considering the case of the letters as well.

The StartsWith() method can be used to check the beginning instance of a given string with reference to many strings at once by making use of for each loop.

Recommended Articles

This is a guide to C# StartsWith(). Here we also discuss the introduction and working of c# startswith() along with different examples and its code implementation. You may also have a look at the following articles to learn more –

Working Of Cut() Function Pandas With Examples

Introduction to Pandas cut()

Web development, programming languages, Software testing & others

For example, let us say we have numbers from 1 to 10. Here, we categorize these values and differentiate them as 2 groups. These groups are termed as bins. Hence, we differentiate these set of values are bin 1 = 1 to 5 and bin 2 = 5 to 10. Now, once we have these two bins, we decide which values are greater and which are smaller. So, the numbers from 1 to 5 are smaller than the numbers from 5 to 10. Hence, these smaller numbers are termed as ‘Lows’ and the greater numbers are termed as ‘Highs’.

This method is called labelling the values using Pandas cut() function. Use cut once you have to be compelled to section and type information values into bins. This operate is additionally helpful for going from an eternal variable to a categorical variable. As an example, cut may convert ages to teams getting on supports binning into associate degree equal variety of bins, or a pre-specified array of bins.

Syntax of Pandas cut()

Given below is the syntax of Pandas cut():

Pandas.cut(x, duplicates='raise', include_lowest = false, precision = 3, retbins = false, labels = none, right = true, bins)

Parameters of above syntax:

‘x’ represents any one dimensional array which has to be put into bin.

duplicates represents the edges in the bin which are not unique values and thus returns a value error if not assigned as raise or drop.

include_lowest represents the values which have to be included as lowest values.

precision parameter is always represented as an integer values as it is the exact value which has to be displayed and stored by the bin numbers.

retbins are always represented as Boolean values and these are the parameters which help the user to choose which are the useful bins.

labels just helps to represent and categorize the bins as highs or lows. They can be Boolean or arrays.

right parameter checks if the bin is present in the rightmost edge or not and they are represented as Boolean values and assigned to either true or false.

bins just help to categorize the data and if it is an integer then the range for all values is defined as ‘a’ and this ‘a’ describes the minimum and maximum values. If the bin values are a series of scalar arrays then, the bins are not formed in a sequential format and finally the interval index defines whether the bins are overlapping or falling on one another or they are produced in a proper format in the output.

How cut() Function works in Pandas?

Given below shows how cut() function works in Pandas:

Example #1

Utilizing Pandas Cut() function to segment the numbers into bins.

Code:

import numpy as np import pandas as pd df_num1 = pd.DataFrame({'num': np.random.randint(1, 30, 20)}) print(df_num1) df_num1['num_bins'] = pd.cut(x=df_num1['num'], bins=[1, 5, 10, 15, 30]) print(df_num1) print(df_num1['num_bins'].unique())

In the above program, we see how to categorize the values into different bins. First we import numpy and pandas and then define the different integer values and finally add pandas.cut() function to categorize these values as bins and finally print them as a separate column and also print the unique values in the bins and thus the output is generated.

Example #2

Utilizing Pandas cut() function to label the bins.

import numpy as np import pandas as pd df_num1 = pd.DataFrame({'number': np.random.randint(1, 50, 30)}) print(df_num1) df_num1['numbers_labels'] = pd.cut(x=df_num1['number'], bins=[1, 25, 50], labels=['Lows', 'Highs'], right=False) print(df_num1) print(df_num1['numbers_labels'].unique())

Output:

Here, we do the same as previous but along with categorizing into bins, we also categorize these bins ad label them as highs and lows. We first import pandas and numpy packages in python. We later assign the values for the bins and by making use of pandas.cut() function, we differentiate the numerical values into bins and finally see which numbers are greater and which are smaller. So, the greater numbers are termed as highs and the smaller numbers are termed as lows.

Conclusion

Use cut after you rephased the sorted values into bins. This operation is additionally helpful for going from endless variable to a categorical variable. For instance, cut might convert ages to teams old-time ranges. Supports binning into Associate in Nursing equal variety of bins, or a pre-specified array of bins. The specific bins are solely go back only when the parameter retbins = true. Hence, for sequence bins which consist of scalar arrays, this will end up as the last array of the present bin. So, when duplicates=drop, the bins drop out the array which are non-unique and hence ends up offering adequate number of bins.

Recommended Articles

We hope that this EDUCBA information on “Pandas cut()” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Examples Of C++ Algorithm With Detail Explanation

Introduction to C++ Algorithm

algorithm::adjacent_find(): Points the first occurrence of two identical consecutive numbers.

algorithm::all_of(): Returns true if the numbers lie under the range of first and last elements.

algorithm::binary_search(): Checks if the “value to be searched” is present in the sorted sequence or not.

algorithm::copy(): This function helps in copying a range of elements from one location to the new location.

algorithm::count_if(): This function returns the number of occurrences of particular elements if the condition mentioned in “if condition” is satisfied.

Explanation of C++ Algorithm

C++ provides versions of these algorithms in the namespace std::ranges. Algorithms are the vast topic that covers topics from searching, sorting to min/max heaps. These can be categorized as:

1. Heap: In such types, we construct a heap to find out the max or min value of the sequence. This used the data structure of trees to achieve its output.

2. Binary Search: This C++ algorithm divides the whole sequence into two parts iteratively until it finds the actual value we are searching from the targeted sequence. It is a highly effective algorithm as it reduces time by half. The preliminary condition to use this C++ algorithm is that the sequence provided to it should be sorted in any order.

3. Sorting: There are different types of sorting that can be used to generate the sorted sequence. They are insertion sort, bubble sort, selection sort, heap sort, quick sort, merge sort. Some of these algorithms work on the principle of “divide and rule” like merge and quick sort. These are quick and efficient in comparison to others although uses more memory in their operations.

4. Simple Operations Over the Sequence: Algorithms can be used to perform simple operations like replace, remove, reverse the numbers in a sequence. There are many ways to reach this output using different algorithms all aiming to achieve the same output.

5. Non-modifying Operations: Some operations like search, find, count the number of elements in the sequence. These operations do not modify the data values of the element but function around these elements.

Example of Algorithms with Steps

Here are some examples of the C++ algorithm with steps explained below:

Example #1

Algorithm

Steps are given below:

Start

Accept num1, num 2

Sum= num1+ num2

Display sum

Stop

Example #2

Write a C++ algorithm to determine if a student is pass or fail based on the grades. Grades are the average of total marks obtained in all the subjects.

Algorithm

Steps are given below:

Start

Input Marks1, Marks2, Marks3, Marks4

Grade= (Marks1+Marks2+Marks3+Marks4)/4

If (Grade<50) then

Print “Fail”

Else

Print “Pass”

End if

Stop

Example #3

Bubble sort- This is the C++ algorithm to sort the number sequence in ascending or descending order. It compares the nearest two numbers and puts the small one before a larger number if sorting in ascending order. This process continues until we reach a sequence where we find all the numbers sorted in sequence.

Implementation of the above C++ algorithm

Here is the example of the C++ algorithm with code implementation given below:

Code:

void swap(int *p1, int *p2) { int temp = *p1; *p1 = *p2; *p2 = temp; } void bSort(int arrnumbers[], int n) { int i, j; bool check; for (i = 0; i < n-1; i++) { check = false; for (j = 0; j < n-i-1; j++) { { swap(&arrnumbers[j], &arrnumbers[j+1]); check = true; } } if (check == false) break; } } void print(int arrnumbers[], int sizeofarray) { int i; for (i=0; i < sizeofarray; i++) printf(“%d “, arrnumbers[i]); } int main() { int arrnumbers[] = {5, 6, 1, 0, 2, 9}; int n = sizeof(arrnumbers)/sizeof(arrnumbers[0]); bSort(arrnumbers, n); printf(“Sorted array: n”); print(arrnumbers, n); return 0; }

Output:

Conclusion Recommended Articles

This is a guide to the C++ Algorithm. Here we discuss the introduction and detailed explanation of the C++ algorithm along with the various examples and code implementation. You may also look at the following articles to learn more –

Update the detailed information about Basic Syntax Of Mariadb Logs With Examples on the Minhminhbmm.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!