C++ program for the Array Index with same count of even or odd numbers on both sides?

sudhir sharma
Updated on 04-Oct-2019 08:27:33

219 Views

Finding the array index with the same count of even or odd number is a number that has equal number of either numbers or odd number on both sides of it i.e. no.s at left = no.s right.Here, we need a few definitions that are related to the concept, Array − A container of elements of same data type.Array Index − The position of an element is called its index. Index of array always start from 0.Even number − A number that is divisible by 2.Odd number − A number that is not divisible by 2.A whole number can either ... Read More

Display specific name from a table with repeated individual FirstName and LastName using LIKE clause twice

AmitDiwan
Updated on 04-Oct-2019 08:26:25

57 Views

Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(30) ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName) values('John Smith'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentName) values('David Miller'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentName) values('Carol Taylor'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentName) values('John Doe'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentName) values('Chris Brown'); Query OK, 1 row ... Read More

How to extract only the numbers from a text field in MySQL?

AmitDiwan
Updated on 04-Oct-2019 08:23:53

804 Views

Let us first create a table −mysql> create table DemoTable (    Number text ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('7364746464, -'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('-, 8909094556'); Query OK, 1 row affected (0.23 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+--------------+ | Number | +--------------+ | 7364746464, - | | -, 8909094556 | +--------------+ 2 rows in set (0.00 sec)Following is ... Read More

Array elements with prime frequencies in C++?

sudhir sharma
Updated on 04-Oct-2019 08:22:18

163 Views

Array is a container of elements of same data type.Prime Frequencies means that the number of occurrence of the element of the array is a prime number.So, based on these definitions the problem to find array elements with prime frequencies. We are given a string of array. We have to find the frequency of characters and check if frequency is prime and then count elements that have prime frequencies.Let’s take an example, Input: str = “helloworld” Output: 2ExplanationCount of occurrences of characters are −h -> 1 e -> 1 l -> 3 o -> 2 w-> 1 r -> 1 ... Read More

MySQL query to convert height format to centimeters?

AmitDiwan
Updated on 04-Oct-2019 08:15:01

396 Views

For this, use the CAST() method in MySQL. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentHeight varchar(40) ) ; Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentHeight) values('5\'10\"'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentHeight) values('4\'6\"'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentHeight) values('5\'8\"'); Query OK, 1 row affected (0.10 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output ... Read More

Array elements that appear more than once in C?

sudhir sharma
Updated on 04-Oct-2019 08:13:33

812 Views

Array is a container of elements of Same data types length needs to be defined beforehand. And an element can appear in any order and any number of times in an array. so in this program we will find elements that appear more than once in an array.Problem description − We have given an array arr[] in which we have to find which of the element are repeating in the array an app to print them.Let’s take an example to understand this better.Example, Input: arr[] = {5, 11, 11, 2, 1, 4, 2} Output: 11 2ExplanationWe have an array arr ... Read More

How to sum varchar column and display the count in MySQL?

AmitDiwan
Updated on 04-Oct-2019 08:09:55

549 Views

For this, use GROUP BY along with COUNT(*). Let us first create a table −mysql> create table DemoTable (    EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    EmployeeGender varchar(40) ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(EmployeeGender) values('MALE'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(EmployeeGender) values('FEMALE'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable(EmployeeGender) values('FEMALE'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable(EmployeeGender) values('FEMALE'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable(EmployeeGender) values('MALE'); Query ... Read More

Array element with minimum sum of absolute differences in C++?

sudhir sharma
Updated on 04-Oct-2019 08:08:14

260 Views

This program is to find minimum absolute difference of the array given we have an array which have distinct element.To learn this concept better let’s rebrush the things that required, Array is a container of elements of same data type. The length of an array needs to be predefined.absolute difference is the absolute value of the difference between two numbers i.e. the difference will always be positive, negative values will be converted to positive.The sum of minimum absolute difference of each element has to be found the minimum absolute solute difference formula isMinimum Absolute Difference (a) = min(abs(a – arr[j])) ;where 1 ... Read More

Format date with DATE_FORMAT() and STR_TO_DATE() in MySQL

AmitDiwan
Updated on 04-Oct-2019 08:01:09

219 Views

Let us first create a table −mysql> create table DemoTable (    DueDate varchar(100) ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('August 04, 2019'); Query OK, 1 row affected (0.25 sec)Display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output −+----------------+ | DueDate | +----------------+ | August 04, 2019 | +----------------+ 1 row in set (0.00 sec)Following is the query to format date −mysql> set @stringToDate=(select date_format(str_to_date(DueDate, '%M %d, %Y'), '%Y-%m-%d') from ... Read More

The abs(), labs(), llabs() functions in C/C++

sudhir sharma
Updated on 04-Oct-2019 08:00:18

800 Views

What are Integer Functions in C Library?Integer functions are those functions which returns the exact value of an integer. C only supports integer values. In this function the nearest integer which is less than or equal to the argument returns to this function.Types of Integer functions −int = abs (int n); long = labs (long n); long long = llabs (long long n);where n = integer valueWhat is abs(), labs(), llabs() functions ?They are defined as (C Standard General Utilities Library) header file. They give the exact value of integer that is input to them as their argument.abs() function ... Read More

Advertisements