Programming Articles - Page 2092 of 3366

Count all sorted rows in a matrix in C++

Ayush Gupta
Updated on 17-Feb-2020 10:27:25

256 Views

In this tutorial, we will be discussing a program to find the number of all sorted rows in a matrix.For this we will be provided with m*n matrix. Our task is to count all the rows in the given matrix that are sorted either in ascending or descending order.Example Live Demo#include #define MAX 100 using namespace std; //counting sorted rows int count_srows(int mat[][MAX], int r, int c){    int result = 0;    for (int i=0; i

Count all the columns in a matrix which are sorted in descending in C++

Ayush Gupta
Updated on 17-Feb-2020 10:23:45

194 Views

In this tutorial, we will be discussing a program to find the number of columns in a matrix which are sorted in descending.For this we will be provided with a matrix. Our task is to count the number of columns in the matrix having elements sorted in descending order.Example Live Demo#include #define MAX 100 using namespace std; //counting columns sorted in descending order int count_dcolumns(int mat[][MAX], int r, int c){    int result = 0;    for (int i=0; i0; j--)          if (mat[i][j-1] >= mat[i][j])             break;       if ... Read More

Count all the numbers in a range with smallest factor as K in C++

Ayush Gupta
Updated on 17-Feb-2020 10:20:56

177 Views

In this tutorial, we will be discussing a program to find the numbers in a range with the smallest factor as K.For this we will be provided with a range [a,b]. Our task is to count the numbers in the given range who have their smallest factor as K.Example Live Demo#include using namespace std; //checking if K is a prime bool if_prime(int k){    if (k

Count all subsequences having product less than K in C++

Ayush Gupta
Updated on 17-Feb-2020 10:17:03

370 Views

In this tutorial, we will be discussing a program to find the number of sub sequences having product less than K.For this we will be provided with non-negative array and a value k. Our task is to find all the subsequences in the array having product less than k.Example Live Demo#include using namespace std; //counting subsequences with product //less than k int count_sub(vector &arr, int k){    int n = arr.size();    int dp[k + 1][n + 1];    memset(dp, 0, sizeof(dp));    for (int i = 1; i

Handling the Divide by Zero Exception in C++

Ayush Gupta
Updated on 17-Feb-2020 10:14:15

9K+ Views

In this tutorial, we will be discussing how to handle the divide by Zero exception in C++.Division by zero is an undefined entity in mathematics, and we need to handle it properly while programming so that it doesn’t return at error at the user end.Using the runtime_error classExample Live Demo#include #include using namespace std; //handling divide by zero float Division(float num, float den){    if (den == 0) {       throw runtime_error("Math error: Attempted to divide by Zero");    }    return (num / den); } int main(){    float numerator, denominator, result;    numerator = 12.5;    denominator = 0;    try {       result = Division(numerator, denominator);       cout

How arrays are passed to functions in C/C++

Ayush Gupta
Updated on 17-Feb-2020 10:09:38

171 Views

In this tutorial, we will be discussing a program to understand how arrays are passed to functions.In the case of C/C++, the arrays are passed to a function in the form of a pointer which provides the address to the very first element of the array.Example Live Demo#include //passing array as a pointer void fun(int arr[]){    unsigned int n = sizeof(arr)/sizeof(arr[0]);    printf("Array size inside fun() is %d", n); } int main(){    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8};    unsigned int n = sizeof(arr)/sizeof(arr[0]);    printf("Array size inside main() is %d", n);   ... Read More

JShell in Java 9?

raja
Updated on 17-Feb-2020 05:05:11

241 Views

JShell is a new concept introduced in Java 9 version. It provides Java with REPL (Read-Eval-Print-Loop) ability. By using JShell, we can test the java-based logic and expressions without compiling it. REPL acts as an immediate feedback loop and has a great effect on productivity in that particular language.Step 1: Open Command Prompt and type JShell.Microsoft Windows [Version 6.3.9600] (c) 2013 Microsoft Corporation. All rights reserved. C:\Users\User>JShell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell>Step 2: Type /help (to view JShell commands) in the JShell command window once it starts running.jshell> /help | Type ... Read More

Which attributes have added to @Deprecated annotation in Java 9?

raja
Updated on 21-Feb-2020 12:14:47

663 Views

There are two new parameters or attributes added to @Deprecated annotation in Java 9. Those parameters are Since and forRemoval, both of these two parameters are optional with a default value when we can't specify it.SinceThis string parameter specifies the version in which the API became deprecated. The default value of this element is an empty string.Syntax@Deprecated(since="")forRemovalThis boolean parameter specifies whether the API is intended to be removed in a future release or not. The default value is false when we can't specify it.Syntax@Deprecated(forRemoval=)Examplepublic class DeprecatedAnnotationTest {    public static void main(String[] args) {       DeprecatedAnnotationTest test = new DeprecatedAnnotationTest();       test.method1();   ... Read More

What are the CompletableFuture API improvements in Java 9?

raja
Updated on 21-Feb-2020 12:15:49

313 Views

CompletableFuture API is used for asynchronous programming in Java. It means that we can write non-blocking code by running a task on a separate thread than the main() thread and notify the main() thread about its progress, completion or failure. Java 9 introduces a few improvements in CompletableFuture API,  they are: "Support for timeouts and delays", "Improved support for subclassing" and "Addition of new factory methods".Support for timeouts and delayspublic CompletableFuture orTimeout(long timeout, TimeUnit unit) The above method has been used to specify if the task does not complete within a certain period of time the program stops and throws TimeoutException.public CompletableFuture completeOnTimeout(T value, long timeout, ... Read More

Working with csv files in Python Programming

Pradeep Elance
Updated on 14-Feb-2020 07:51:42

2K+ Views

The CSV file or comma separated values file are one of the most widely used flat files to store and hare data across platforms. The columns are separated by comma and there is optional header row also which will indicate the name of each column. Python can read the CSV files using many modules. In this article we will see how the CSV library in python can be used to read and write a CSV file. We can also see the pandas library onl to read the CSV file.Reading CSV file using csv moduleWe can get the CSV file from ... Read More

Advertisements