Tribonacci Numbers in C++

Arnab Chakraborty
Updated on 25-Sep-2019 12:13:29

1K+ Views

Here we will see how to generate the Tribonacci numbers using C++. The Tribonacci numbers are similar to the Fibonacci numbers, but here we are generating a term by adding three previous terms. Suppose we want to generate T(n), then the formula will be like below −T(n) = T(n - 1) + T(n - 2) + T(n - 3)The first few numbers to start, are {0, 1, 1}Algorithmtribonacci(n): Begin    first := 0, second := 1, third := 1    print first, second, third    for i in range n – 3, do       next := first + ... Read More

MySQL SUM function to add decimal values

AmitDiwan
Updated on 25-Sep-2019 12:12:07

1K+ Views

Let us first create a table −mysql> create table DemoTable (    Money DECIMAL(7, 2) ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(100.67); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(199.33); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(500); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(400); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(800); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> ... Read More

Tetranacci Numbers in C++

Arnab Chakraborty
Updated on 25-Sep-2019 12:10:21

125 Views

Here we will see how to generate the Tetranacci numbers using C++. The Tetranacci numbers are similar to the Fibonacci numbers, but here we are generating a term by adding four previous terms. Suppose we want to generate T(n), then the formula will be like below −T(n) = T(n - 1) + T(n - 2) + T(n - 3) + T(n - 4)The first few numbers to start, are {0, 1, 1, 2}Algorithmtetranacci(n): Begin    first := 0, second := 1, third := 1, fourth := 2    print first, second, third, fourth    for i in range n – ... Read More

MySQL query to select a record with two exact values?

AmitDiwan
Updated on 25-Sep-2019 12:08:56

126 Views

For this, you can use GROUP BY HAVING clause. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value int ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values(600); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Value) values(600); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(Value) values(800); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Value) values(800); Query OK, 1 row affected (0.09 sec)Display all records from the table ... Read More

Display records on the basis of key-value pairs in MySQL

AmitDiwan
Updated on 25-Sep-2019 12:06:59

1K+ Views

For this, use JSON_OBJECTAGG(). Let us first create a table −mysql> create table DemoTable (    Id int,    FirstName varchar(100),    Age int ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 'John', 23); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(20, 'Carol', 21); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(10, 'Sam', 24); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(20, 'Chris', 20); Query OK, 1 row affected (0.13 sec)Display all records from the ... Read More

Sort the numbers according to their sum of digits in C++

Arnab Chakraborty
Updated on 25-Sep-2019 12:05:21

281 Views

In this section we will see how to sort numbers according to their sum of digits. So if a number has lesser sum of digits, then that will be placed at first, then next number will be placed with larger sum of digits.data = {14, 129, 501, 23, 0, 145}after sorting, they will be −data = {0, 14, 23, 501, 145, 129}Here we will create our own comparison logic to sort them. That comparison logic will be used in the sort function in C++ STL.Algorithmcompare(num1, num2): Begin    if sum of digits of num1 < sum of digits of num2, ... Read More

Python Implementing Web Scraping with Scrapy

Pavitra
Updated on 25-Sep-2019 12:04:21

134 Views

In this article, we will learn about the web scraping technique using the Scrappy module available in Python.What is web scraping?Web scraping is used to obtain/get the data from a website with the help of a crawler/scanner. Web scrapping comes handy to extract the data from a web page that doesn't offer the functionality of an API. In python, web scraping can be done by the help of various modules namely Beautiful Soup, Scrappy & lxml.Here we will discuss web scraping using the Scrappy module.For that, we first need to install Scrappy.Type in the terminal or command prompt>>> pip install ... Read More

How to calculate time based on seconds in MySQL?

AmitDiwan
Updated on 25-Sep-2019 11:51:59

113 Views

Let us first create a table −mysql> create table DemoTable (    Logouttime time ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('5:50:00'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('6:10:10'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('8:00:50'); Query OK, 1 row affected (0.14 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+------------+ | Logouttime | +------------+ | 05:50:00 | | 06:10:10 | | 08:00:50 ... Read More

Sort an array of strings according to string lengths in C++

Arnab Chakraborty
Updated on 25-Sep-2019 11:51:12

694 Views

Here we will see how to sort a list of strings based on their lengths. So if a string has less number of characters, then that will be placed first, then other longer strings will be placed. Suppose the strings arestr_list = {“Hello”, “ABC”, “Programming”, “Length”, “Population”}after sorting, they will be −str_list = {“ABC”, “Hello”, “Length”, “Population”, “Programming”}Here we will create our own comparison logic to sort them. That comparison logic will be used in the sort function in C++ STL.Algorithmcompare(str1, str2): Begin    if length of str1 < length of str2, then       return 1    return ... Read More

MySQL query to count the number of 0s and 1s from a table column and display them in two columns?

AmitDiwan
Updated on 25-Sep-2019 11:49:21

409 Views

For this, you can use the aggregate function SUM(). Let us first create a table −mysql> create table DemoTable (    isMarried tinyint(1) ); Query OK, 0 rows affected (0.84 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(0); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(1); Query OK, 1 row affected (0.19 sec) mysql> ... Read More

Advertisements