C++ program to find two numbers with sum and product both same as N

Ayush Gupta
Updated on 03-Oct-2019 11:00:48

450 Views

In this tutorial, we will be discussing a program to find two numbers (say ‘a’ and ‘b’) such that botha+b = N and a*b = N are satisfied.Eliminating ‘a’ from both the equations, we get a quadratic equation in ‘b’ and ‘N’ i.eb2 - bN + N = 0This equation will have two roots which will give us the value of both ‘a’ and ‘b’. Using the determinant method to find the roots, we get the value of ‘a’ and ‘b’ as, $a= (N-\sqrt{N*N-4N)}/2\ b= (N+\sqrt{N*N-4N)}/2 $Example Live Demo#include //header file for the square root function #include using namespace ... Read More

MySQL query to get count of each fileid entry in a table with Id and FileIDs?

AmitDiwan
Updated on 03-Oct-2019 08:56:35

47 Views

Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FileID int ) AUTO_INCREMENT=100; Query OK, 0 rows affected (1.36 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FileID) values(50); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(FileID) values(60); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(FileID) values(50); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(FileID) values(70); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(FileID) values(60); Query OK, 1 row affected (0.28 sec) mysql> ... Read More

What are the differences between JavaScript and PHP cookies?

Anvi Jain
Updated on 03-Oct-2019 08:09:22

540 Views

JavaScript CookiesUsing JavaScript cookies is the most efficient method of remembering and tracking preferences, purchases, commissions, and other information required for better visitor experience or site statistics.PHP CookiesCookies are text files stored on the client computer and they are kept for tracking purpose. PHP transparently supports HTTP cookies.How JavaScript cookies work?Your server sends some data to the visitor's browser in the form of a cookie. The browser may accept the cookie. If it does, it is stored as a plain text record on the visitor's hard drive. Now, when the visitor arrives at another page on your site, the browser ... Read More

How to define methods for an Object in JavaScript?

Nancy Den
Updated on 03-Oct-2019 08:07:09

71 Views

Methods are the functions that let the object do something or let something is done to it. There is a small difference between a function and a method – at a function is a standalone unit of statements and a method is attached to an object and can be referenced by this keyword.Methods are used for everything from displaying the contents of the object to the screen to performing complex mathematical operations on a group of local properties and parameters. Here’s an example showing how to use the write() method of the document object to write any content on the document.document.write("This ... Read More

How can I delete all cookies with JavaScript?

Vrundesha Joshi
Updated on 03-Oct-2019 08:06:06

1K+ Views

To delete all cookies with JavaScript, you can try to run the following code. Here, we’re using an array and the split() method to get all the cookies and finally delete themExampleLive Demo                    var num = 1;          function addCookie(){             document.cookie = num+" = "+num;             num++;          }          function listCookies(){             var result = document.cookie;             document.getElementById("list").innerHTML = result;          }          function removeCookies() {             var res = document.cookie;             var multiple = res.split(";");             for(var i = 0; i < multiple.length; i++) {                var key = multiple[i].split("=");                document.cookie = key[0]+" =; expires = Thu, 01 Jan 1970 00:00:00 UTC";             }          }                     ADD       LIST COOKIES       REMOVE       Cookies List          

Create a table if it does not already exist and insert a record in the same query with MySQL

AmitDiwan
Updated on 03-Oct-2019 07:57:55

903 Views

Use CREATE TABLE IF NOT EXISTS for this as shown in the below syntax −create table if not exists yourTableName (    yourColumnName1 dataType,    yourColumnName2 dataType,    yourColumnName3 dataType,    .    .    N ) as select yourValue1 as yourColumnName1 , yourValue2 as yourColumnName2 , yourValue3 as yourColumnName3, .............................N;Let us first create a table and insert value if the table does not already exist −mysql> create table if not exists DemoTable (    id int,    FirstName varchar(20),    LastName varchar(20) ) as select 100 as id, 'John' as FirstName , 'Smith' as LastName; Query OK, 1 row ... Read More

SUM a column based on a condition in MySQL

AmitDiwan
Updated on 03-Oct-2019 07:55:03

423 Views

Let us first create a table −mysql> create table DemoTable (    CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ProductAmount int,    CustomerCountryName varchar(10) ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ProductAmount, CustomerCountryName) values(190, 'US'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable(ProductAmount, CustomerCountryName) values(200, 'UK'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(ProductAmount, CustomerCountryName) values(1500, 'AUS'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable(ProductAmount, CustomerCountryName) values(2010, 'US'); Query OK, 1 row affected (0.13 sec) mysql> insert into ... Read More

How to display a single quote text as a column value in MySQL?

AmitDiwan
Updated on 03-Oct-2019 07:51:46

177 Views

To display a single quote text, use double quotes like if you want to write You’ve, then write You've while inserting i.e. with double-quotes. Let us first create a table −mysql> create table DemoTable (    Note text ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('You''ve seen the Taj? When?'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('You''ve visited the US?'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the ... Read More

Updating blank cells to NULL will cause all cells to be NULL in MySQL?

AmitDiwan
Updated on 03-Oct-2019 07:49:27

63 Views

To update only blank cells to NULL, use NULLIF() in MySQL. Let us first create a table −mysql> create table DemoTable (    Name varchar(50) ); Query OK, 0 rows affected (1.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(''); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable values('David'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(''); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Mike'); Query OK, 1 row affected (0.15 ... Read More

How to implement MAX(distinct…) in MySQL and what is the difference without using DISTINCT?

AmitDiwan
Updated on 03-Oct-2019 07:47:26

2K+ Views

Let us see the first syntax, which uses DISTINCT in MAX() −select max(DISTINCT yourColumnName) from yourTableName;The second syntax is as follows. It isn’t using DISTINCT −select max( yourColumnName) from yourTableName;NOTE − Both the above queries give the same result with or without a DISTINCT keyword. MySQL internally converts MAX(yourColumnName) to DISTINCT keyword.Let us now see an example and create a table −mysql> create table DemoTable (    Number int ); Query OK, 0 rows affected (1.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(80); Query OK, 1 row affected (0.09 sec) mysql> insert into ... Read More

Advertisements