May 2022

Data Science has become quite an attractive field today. Not just is it very profitable, but it also provides huge utility to many other fields. Besides, data science can also be used to predict possibilities, determine new trends, prescribe behaviour, and make any predictions based on hidden patterns.

Among researchers and students, there is huge interest in the field, for this reason, so many courses are available online. Thus, in this post, we will check out the difference between Datacamp and Dataquest, these are two solid choices for data science. Now, let us compare to check out which is a better learning platform for you.

Dataquest vs Datacamp is self-learning data science class, which run on monthly and yearly subscriptions. Their courses are entirely delivered on the internet platform. Both the schools provide multiple career tracks that include a focus on Python or R and portfolio projects. Suppose you complete your course completely, then the tracks take students to complete the beginner’s course to Data Scientist or Data Analyst. But, the question is which is the best school to choose –Datacamp or Dataquest? Let us break down how Datacamp and Dataquest compare to one another in the terms of curriculum, career focus, learning style, and cost.

What is Dataquest?

dataquest

Dataquest is a self-paced learning course providing 24-week online data science courses for aspiring data scientists and data analysts. Dataquest mainly focuses on R and Python with a bit more emphasis on the data analysis.

Being an online learning resource, Dataquest is dedicated to teaching candidates data science. This has different skill and career paths, letting you choose the learning plan that is modified to your individual requirements.

An objective of this online platform is to offer you with best learning resources and tools that are equipped with some helpful information, which can give you the skills you need to become a professional in data science.

Courses Offered

Dataquest provides a wide range of courses, and some of them are focused on:

  • Python
  • R
  • Git
  • SQL
  • Kaggle
  • Machine Learning

You have access to specific paths. Dataquest provides these 4:

  • Data Analyst (Python)
  • Data Analyst (R)
  • Data Engineer
  • Data Scientist (Python)

Dataquest has got the benefit of offering several courses all along with the hands-on approach for ensuring students know what they are learning. With Dataquest, one biggest priority is the application, thus there are various opportunities you can apply what you have learned. They offer office hours so that you will reach out to the data scientists for any kind of help, and be an important part of the active Slack community.

Make a note that the beginner courses are offered for free, however, Dataquest has got two paid plans. Their first deal is around $29 per month, and the second one is $49 per month.

Dataquest Pros

  • Best-quality content
  • Great for beginners
  • Convenient interface for the practice
  • Possibility to switch from a particular course 
  • Active and large community

Dataquest Cons

  • Less content 
  • A bit expensive 
  • System bugs
  • Might not be very good for the middle and advanced users

What is DataCamp?

datacamp

Just like Dataquest, DataCamp is the self-learning online platform made to teach various data skills and provides you with a wide range of skills and career paths. But, on DataCamp, the paths are known as tracks. This platform has video tutorials, more than 50 curated learning paths, as well as real-life projects that offer better knowledge and understanding.

DataCamp begins courses with the instructional video explaining in detail the concepts you will use in an accompanying exercise. Additionally, DataCamp instructors are experts in the field and educators at the master’s or PhD level. With an exciting pedigree of instructors, DataCamp can be the best choice for you if you are more of a visual learner.

Courses Offered

Available courses cover the following disciplines:

  • SQL
  • R
  • Python
  • Shell
  • Spreadsheets
  • Git

Their R courses are highly detailed and comprehensive, offering you access to everything that you will need to know, though for the SQL there is just an introductory one, and a highly desired one. With Datacamp school, you can use career tracks. They are specifically designed syllabuses to accommodate users with specific goals. At present, there are seven available paths:

  • Data Scientist (R)
  • R Programmer
  • Quantitative Analyst (R)
  • Data Analyst (R)
  • Data Analyst (Python)
  • Data Scientist (Python)
  • Python Programmer

Datacamp Pros

  • Better content 
  • Constant updates of their content
  • Can switch from one course to another like SQL to Python
  • Higher projects 
  • Convenient interface for practice and no special program is required
  • Great for beginners
  • Free plan accessible & cheaper premium plan
  • Active and large community

Datacamp Cons

  • Might not be very good for middle and advanced users
  • Customer support isn’t helpful

Dataquest vs Datacamp

Dataquest Datacamp
Languages supported 2: Python, R Languages supported 3: Python, R, SQL
Text-based Video-based
Dataquest focuses on basic graphs DataCamp moves on complex graph types
Dataquest offers active Slack community Datacamp has a community page, and Slack chat comes with paid plans
Dataquest prepares their students for career change Datacamp offers upskilling & career tracks
Dataquest teaches autonomy while pointing students to documentation and concepts Datacamp’s curriculum has short video lessons & tutorials, later moving to project work

Signing up with the Datacamp is very rewarding as all their lessons are made to be very simple and interactive. Videos are provided that will help you know more easily. The video lectures are not very long. They’re relevant and short to their given exercise. Every lesson has got intuitive examples that are incorporated to deepen your knowledge. Their $29 price point makes it quite an affordable choice.

However, there is a problem that you must know about: there is not much additional assistance beyond what’s offered in a lesson. Datacamp’s assignments are not open-ended which means there is no incentive to devise any creative solutions.

The post Dataquest vs DataCamp 2022 – Which is Better? appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/oSz7lgT

Suppose you call your friend for some help and at that time he is busy with some work. He told you that he will callback you after some time. This process is called callback and when it comes to programming, the process of calling back a function from another function is called callback.

To understand this let us suppose there is a function A doing some work, and there is a function B doing some other work. When we call function A in our main code and in function A we also called function B then it is called callback function because here function A is calling function B in its code.

Calling of function from a function is done by using function pointers. Function pointers are pointers that hold the address of execution of another function.

We will see some examples to better understand this.

Example 1:

#include <stdio.h>
#include <stdlib.h>

// Function 1
void func1 () {
    printf("I am in function 1\n") ;
}

// Function 2
void func2(void (*fptr) ()) {
    printf("I am in Function 2\n") ;
    fptr() ;  // Callback function 
    printf("I am again in Function 2\n") ;
}

int main() {

    // Declare a function pointer
    void (*ptr) ;

    // Assign func1 to ptr
    ptr = func1 ;

    // call the func2
    func2(ptr) ;
    return 0 ;
}

Output:

PS C : \ Users \ ASUS \ Desktop \ Crazy Programmer Work > cd " c : \ Users \ ASUS \ Desktop \ Crazy Programmer Work \ " ; if ( $? ) { gcc test.c -o test } ; if ($?) { . \ test }
I am in Function 2
I am in function 1
I am again in Function 2

Here we can see that in function 2, first we are printing some statements and then we are calling function 1 in it. This process is called the callback function where an existing function calls another function in it. We can see that after function 1 is executed, execution control again comes to function 2 and executes all the remaining statements in function 2.

We can use callback methods for writing some efficient programs.

Now let’s see another example where we are going to see some functions and how we are calling another function in that function and we will see how the callback method helps us in writing a smaller number of codes for the same problem statements.

Example 2:

#include <stdio.h>
#include <stdlib.h>

// Function to return the sum of 2 numbers
int sum(int a, int b) {
    return a + b ;
}

// function to greet hello to user and call the sum function to 
// print the sum of two numbers. It implements the callback method.
void greetHello(int (*fptr) (int, int)) {
    printf("Hello from Crazy Programmer\n") ;
    printf("Sum of 7 and 5 is %d\n", fptr(5, 7)) ;
}

// Function to greet Good morning to user and call the sum function
// to print the sum of 2 number. It implements the callback method.
void greetUser(int (*fptr) (int, int)) {
    printf("Good Morning from Crazy Programmer\n") ;
    printf("Sum of 7 and 5 is %d\n", fptr(5, 7)) ; 
}

// main function
int main() {

    // Declare a function pointer to store the address of another function
    int (*ptr)(int, int) ;
    // assign sum function to function pointer
    ptr = sum ;

    // call the greethello function and pass ptr as argument in it.
    greetHello(ptr) ;
    printf("\n") ;
    // call the greetUser function and pass ptr as argument in it.
    greetUser(ptr) ;
    return 0 ;
}

Output:

PS C : \ Users \ ASUS \ Desktop \ Crazy Programmer Work > cd " c : \ Users \ ASUS \ Desktop \ Crazy Programmer Work \ " ; if ( $? ) { gcc test.c -o test } ; if ($?) { . \ test }
Hello from Crazy Programmer
Sum of 7 and 5 is 12

Good Morning from Crazy Programmer
Sum of 7 and 5 is 12

In this example, we can see that we have used 3 functions to demonstrate to working of callback method. In function greethello we can see that we have called the sum function to print the sum of 2 numbers.

In greetUser function, we are calling the sum function to print the sum of 2 numbers.

In both of the functions, we are demonstrating the callback method.

Let’s suppose that you want to implement a feature in which a function greet hello and print the sum of 2 numbers to any user and in another scenario a function greet good morning and print the sum of 2 numbers to the user.

Generally, to implement the above scenario we have to write 2 different functions. Both of the function contains some code that will be similar in it. To overcome this problem, we are using callback function so that no function contains duplicate code. And the implementation can be seen from the above example.

Conclusion

Callback function in c programming means that we want to call a different function from another function. This will help us to write clean and non-duplicate code. The callback method is very useful when we want to use a function in another function and avoid the rewriting of the same function.

The post Callback Function in C appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/QS4ALue

ETL (Extract, Transform and Load) pipeline process is an automated development. It takes raw data files from multiple sources, extracts information useful for analysis, transforms it into file formats that can serve business analytics or statistical research needs, and loads it into a targeted data repository.

ETL pipelines are designed to optimize and streamline data collection from more than a  source and reduce the time used to analyze data. They are also designed to convert these data into useful formats before transferring them to a targeted system for maximal utilization.

Regardless of the efficiencies ETL pipelines offer, the whole purpose is lost if they cannot be built quickly and subtly. This article gives a quick guide on the necessary steps needed to build an ETL pipeline process.

Building an ETL Pipeline Process

ETL Pipeline Process

When you build an ETL pipeline, the process must be in the ETL order, i.e.

Extraction is the act of extracting data from a data pool, such as an open-source target website.

Transformation is a stage where extracted data collected in multiple formats is structured into a unique format and then transferred to a target system.

Loading is the final stage where data is uploaded to a database to be analyzed to generate an actionable output.

The ETL pipeline process is all about data extraction, copying, filtering, transforming, and loading. But when building the process, we must go through some essential details, which are as follows:

Create and Copy Reference Data

Having available raw data at your disposal can aid your vast data sourcing and solve problems in a shorter time. But if raw data is not available, you will have to create a set of data called your ‘reference data’, including a set of restricted values that your data may contain. For example, in a geographic data field, as you will specify the countries allowed, copy those data as raw records to work on while keeping the source/reference data.   

Dedicate Specific Connectors and Extract Data from Available Sources

Distinct tools that establish the connection are required for data extraction from sources. Data can be stored using file formats like JSON, CSV, XML, API, etc. To systematize processing correctly, you must extract it all from a range of relational/non-relational database file format sources and convert it to a specific format to succeed in the ETL pipeline building process.

Cross-check and Filter Data

Keep relevant data and discard data that exceeds the required data range. Analyze rejected data to identify causes for rejection and make necessary adjustments to source data. For example, if you need data from the past 12 months and reject data older than 12 months to validate data, filter data by extracting off inaccurate records and null columns, etc.

Data Transformation

Data transformation is the most crucial part of the ETL pipeline process, especially when it is not automatic. The transformation process entails translating data into the desired form according to individual data use. Data must be cleansed of duplicates, checked for integrity of data standards, aggregated data, and made ready for use. Also, functions can be programmed to facilitate automation during data transformation. 

Stage and Store the Transformed Data

Though It is not recommended to load transformed data into target systems directly for storage or use, instead, take the necessary step of data staging. The staging level is where data diagnostics reports are generated, and data is enabled for easy data recall in case of any havoc or malfunction. When that data is ready, it can be transferred to a target database.  

Sequential Data Scheduling

Scheduling is the final stage of the ETL pipeline building process. For effective automation, it is crucial to schedule the data sequentially to load monthly, weekly, daily, or any custom time range. The data loading schedules can include a sequential time stamp to determine the load date quickly for record purposes. For efficient task automation, scheduling should be done to avoid performance and memory issues.  

Conclusion

In building an effective ETL pipeline process, there is more than one method (batch processing and real-time stream processing) and data integration software that can be used. Whichever method you choose, building the ETL pipeline process in the above-listed order is the way to guarantee a successful operation.

The post Quick Guide to Building an ETL Pipeline Process appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/myVFaSg

Since 2015, the Software as a Service (SaaS) industry has grown to an estimated value of $31.5 billion. In 2022, it is expected to grow by up to $171.9 billion, according to the research. This means more companies are building SaaS products. After all, cloud computing makes SaaS products cost-efficient, scalable, and reliable. Are you looking to create Software as a Service (SaaS) products for your company? Then, this blog is for you. Read on.

What is a SaaS Application?

How to Build a SaaS Product from Scratch

A SaaS application refers to a software licensed Software as a Service application. Using the SaaS approach, companies can market their applications as a service where customers can subscribe. These services are hosted with the help of the cloud, which means the application or customer data doesn’t have to be physically installed on the computer. 

Here are some key benefits of SaaS applications:

  • There is no need to buy expensive hardware, which makes it very cost-efficient.
  • SaaS applications can be upgraded or even downgraded, making SaaS applications scalable.
  • Cloud service providers ensure customers’ data is stored in a safe and secure place using encryption strategies.
  • Since the cloud is a network of various servers, even if one server goes down, the app won’t shut down. 

Here are some more benefits of SaaS architecture for companies and developers:

  • Lower up-front costs mean developers can attract a large customer base.
  • As potential customers subscribe to the product regularly, developers can make consistent revenue. 
  • Companies can offer a trial period, allowing customers to identify if the application can fulfill their needs. 
  • Users can get new features and updates without purchasing new versions of the applications.

Tips for Building SaaS Products Efficiently

A SaaS application allows service developers to gain a stable source of income through user subscriptions, which allow them to regularly update their applications. But this doesn’t mean customers will be willing to subscribe to any SaaS product. 

Some products might be able to cater to only a specific group of consumers, such as industry professionals. Other products might have subscription-free alternatives. 

This is why many companies wonder how to build a SaaS product that not only operates well but also fulfills its purpose. Are you also wondering how to make Software as a Service product and tap into cloud technology? Below you will find some tips for building result-driven cloud-based applications:

1. Offer a Service that Your Customers Want

With so many SaaS products available in the market, customers simply won’t sign up for every application. This is why companies should identify what their customers want and optimize their service accordingly. 

For instance, if a customer wants to edit an Instagram image, they won’t subscribe to an application because they might only want to do it one time. Plus, there are many free online tools that offer the same service.

But if a customer wants to edit a video using complicated tools as part of their job, they would be willing to make monthly payments for a SaaS product. 

This shows that a SaaS business model works best when the application:

  • Help customers save money
  • Provide recurring services
  • Supports a larger user base

2. Do Market Research

You might have a revolutionary idea, but it is possible someone else has already worked upon it. Instead of getting swept up in the SaaS hype, you should conduct market research and identify your competitors to ensure your service is unique and innovative. 

Are your competitors wondering how to develop SaaS product? Are they providing exactly the same services as you want to offer? Your product can only stand out in the market if it offers far more benefits than those offered by your competitors. 

3. Choose the Right Technology Stack

Obviously, you can’t ignore the technical steps for developing a SaaS product. And the first step to building a Saas product is to select a technology stack to run the web app. To do this, you will need various tools for the front-end application, such as JavaScript or HTML. For the server-side, your team will have to employ programming languages like PHP, JavaScript, or Ruby. 

A SaaS product is incomplete without a proper database. You can choose either MySQL or PostgreSQL as your back-end storage. Finally, you will have to choose a server for your application, such as Nginx or Apache. Your choices will depend upon your product’s scalability, potential profits, and costs. 

Final Takeaway

By relying on cloud applications and building SaaS products, many companies have managed to grow significantly. However, before developing the product, you should conduct all the required research, test the product, and ensure it is profitable in the long run.  

The post Tips for Building SaaS Products Efficiently appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/VaRfSAC

In python, we can have many types of errors in our code. One of the most common errors is TypeError: list indices must be integers or slices, not str. In this article, we are going to see what causes this error and how can we fix this error.

This error mostly comes when we are working with lists in python. Whether we are printing the contents of a list or modifying any value at a particular position in the list. In this article, we will discuss some points to remember when working with lists so that the probability of occurring these types of errors will be much less.

Case 1:

# Declare a List
l1 = [10, 20, 30, 40, 50]

# Get Index input from User
index = input("Enter the Index at which you want to change value: ")

# Get the number from user
number = int(input("Enter the final value you want in list : "))

# Update the value in list
l1[index] = number

# Print the list after updation
print(f"Updated list is : {l1}")

Output:

PS C : \ Users \ ASUS \ Desktop \ Crazy Programmer Work > python -u " c : \ Users \ ASUS \ Desktop \ Crazy Programmer Work \ test.py "
Enter the Index at which you want to change value: 3
Enter the final value you want in list : 76
Traceback (most recent call last):
  File "c : \ Users \ ASUS \ Desktop \ Crazy Programmer Work \ test.py ", line 13, in <module>
    l1[index] = number
TypeError: list indices must be integers or slices, not str

In the above example, we have initialized a list of five numbers and we want to change the value of a particular index. We get out the index and value entered by the user and in the last operation, we are going to print the updated list. When we run the code and enter the respective value then we are getting the error. It states that the list indices must be integers or slices, not str it means that the index value we have passed in our code should be an integer.

We often make this mistake because we all know that the input function takes input as a string and if we want to use it as an integer then we have to convert it into an integer first, then we can use the index value and we will be able to perform our operation successfully.

Solution:

# Declare a List
l1 = [10, 20, 30, 40, 50]

# Get Index input from User and convert it to integer
index = int(input("Enter the Index at which you want to change value: "))

# Get the number from user
number = int(input("Enter the final value you want in list : "))

# Update the value in list
l1[index] = number

# Print the list after updation
print(f"Updated list is : {l1}")

Output:

PS C : \ Users \ ASUS \ Desktop \ Crazy Programmer Work > python -u " c : \ Users \ ASUS \ Desktop \ Crazy Programmer Work \ test.py "
Enter the Index at which you want to change value: 3
Enter the final value you want in list : 76
Updated list is : [10, 20, 30, 76, 50]

As we can see that after converting the index value into an integer, we are successfully able to perform the desired operation. We can see that the value at 4th index has been changed to 76.

Case 2:

We are given with a list of words and we want to create a new string with all the words from the list and create a proper sentence and then print it.

# initialise a list of words
list1 = ["This", "article", "is", "written", "by", "crazy", "programmer"]

# initialise an empty string
new_string = ""

# initialist index with 0
index = 0

# run a loop through the list and add all the words in a string
while index < len(list1):
    new_string = new_string + " " + list1[new_string]
    index = index + 1

# print the new combined words
print(new_string)

When we run our code then we will get some error.

Output:

PS C : \ Users \ ASUS \ Desktop \ Crazy Programmer Work > python -u " c : \ Users \ ASUS \ Desktop \ Crazy Programmer Work \ test.py "
Traceback (most recent call last):
  File "c : \ Users \ ASUS \ Desktop \ Crazy Programmer Work \ test.py ", line 70, in <module>
    new_string = new_string + " " + list1[new_string]
TypeError: list indices must be integers or slices, not str

Here the same error occurred. It means we have to re examine the index value passed to the list in our program. We have to make sure that the index value should be in an integer only, to run our code perfectly. In line 70 we can see that the index we have passed to our list is a string. At this point, many programmers does not realize the mistake in the code and they spend 1 to 2 hours in debugging it. In our program, we know that new_string is a string so we cannot pass it as an index. We have identified the error.

Solution:

# initialize a list of words
list1 = ["This", "article", "is", "written", "by", "crazy", "programmer"]

# Initialize an empty string
new_string = ""

# initialize index with 0
index = 0

# run a loop through the list and add all the words in a string
while index < len(list1):
    new_string = new_string + " " + list1[index]
    index = index + 1

# print the new combined words
print(new_string)

Output:

PS C : \ Users \ ASUS \ Desktop \ Crazy Programmer Work > python -u " c : \ Users \ ASUS \ Desktop \ Crazy Programmer Work \ test.py "
 This article is written by crazy programmer

We can see that our program is running successfully. We have fixed our code.

Conclusion

Whenever we see that error named TypeError: list indices must be integers or slices, not str. Then without making any changes in the code, firstly we have to figure out the uses of lists in our program, after that, we have to figure out where we are going to print the content of the lists or we are going to make any changes in the list.

If either of the cases is happening we have to check whether the index value passed in the list is an integer or not. It will give the error when the index value passed in the list is a string type. So we have to check it and fix it if it is not integer type.

The post Solve TypeError: list indices must be integers or slices, not str in Python appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/oZNjmXW

In any programming language loops play an important role in building our logic and successfully implementing it. In this article, we are going to see nested for loop in C++.

Nested for loop means a for loop inside another for loop. Let’s see the syntax first and after that, we will some examples.

Syntax:

for ( size_t i = 0; i < count; i++ )
    {
        for ( size_t i = 0; i < count ; i++ )
        {
            /* code */
        }
    }

Here we can see the syntax of nested for loop. We can modify the inner contents as per our wish but the main structure of the for loop should remain the same.

Let’s see some examples of nested for loop.

Example 1:

In the first example, we are going to print a 5 x 4 matrix using a nested for loop, which we often see in mathematics.

#include <iostream>
using namespace std; 

int main(){

    int n = 5;
    int m = 4;

    for (int i = 0; i < n; i++){       // printing the row
        for (int j = 0; j < m; j++)    // printing the column
        {
            cout << j << " ";
        }
        cout << endl;

    }
    return 0;
}

Output:

PS C : \ Users \ ASUS \ Desktop \ Crazy Programmer Work > cd " c : \ Users \ ASUS \ Desktop \ Crazy Programmer Work \ "  ; if ($?) { g++ test.cpp -o test } ; if ($?) { . \ test }
0 1 2 3
0 1 2 3
0 1 2 3
0 1 2 3
0 1 2 3

Example 2:

In this example, we will be going to see how to take inputs using nested for loops and we will store the inputs in 2 dimension arrays. After that, we will print the 2 dimension array using nested for loop.

#include <iostream>
using namespace std;

int main(){

    int row = 3;
    int col = 3;
    int arr[3][3];
    int num;

    // Taking matrix input
    cout << "Enter Matrix Elements" << endl;
    for (int i = 0; i < row; i++){
        for (int j = 0; j < col; j++){
            cin >> num;
            arr[i][j] = num;
        }
    }

    // Printing the matrix
    cout << "Printing the Matrix : " << endl;
    for (int i = 0; i < row; i++){         // printing the row
        for (int j = 0; j < col; j++){     // printing the column
            cout << arr[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

Output:

PS C : \ Users \ ASUS \ Desktop \ Crazy Programmer Work > cd " c : \ Users \ ASUS \ Desktop \ Crazy Programmer Work \ "  ; if ($?) { g++ test.cpp -o test } ; if ($?) { . \ test }
Enter Matrix Elements
1 2 3
4 5 6
7 8 9
Printing the Matrix :
1 2 3
4 5 6
7 8 9

We can take inputs for any matrix using nested for loop. It helps us to easily demonstrate the internal working of how input is taken and stored in the array.

We can also write any conditions in the nested for loop, for example, let’s suppose we want to print only even numbers from the matrix or we want to print only odd numbers from the matrix.

We can also use break and continue statements in our nested loop.

If the break statement is in the inner for loop then it only stops the execution for the inner for loop. It will not affect the outer for loop.

The same happens with the continue statement also, if we have used the continue statement in the inner for loop then it only affects the inner loop, it has nothing to do with the outer for loop.

Example 3:

In this example we are going to see the use of break statement and continue statement in nested for loop.

Let’s suppose we want that while printing the array, if a number is negative then our loop stops and if a number is 0 then our loop excludes the number while printing.

Make sure to see the serial wise execution of the program, because in this example we are going to see the use of break and continue statements simultaneously.

#include <iostream>
using namespace std;

int main(){

    int row = 3;
    int col = 3;
    int arr[3][3];
    int num;

    // Taking matrix input
    cout << "Enter Matrix Elements" << endl;
    for (int i = 0; i < row; i++){
        for (int j = 0; j < col; j++){
            cin >> num;
            arr[i][j] = num;
        }
    }

    // Printing the matrix
    cout << "Printing the Matrix : " << endl;
    for (int i = 0; i < row; i++){   // printing the row
        for (int j = 0; j < col; j++){   // printing the column
            // break the loop if a number is negative
            if (arr[i][j] < 0)
                {
                break;
            }
            // Do not print the element if it is 0
            if (arr[i][j] == 0)
                {
                continue;
            }
            cout << arr[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}

Output:

PS C : \ Users \ ASUS \ Desktop \ Crazy Programmer Work > cd " c : \ Users \ ASUS \ Desktop \ Crazy Programmer Work \ "  ; if ($?) { g++ test.cpp -o test } ; if ($?) { . \ test }
Enter Matrix Elements
10 20 -54
14 0 -12
-18 87 0
Printing the Matrix :
10 20
14

As we can see in the output, we have used break and continue statement in the program, break statements stop the execution of inner loop that why in the case of third row we did not get any output.

Conclusion

Nested for loop means that a for loop in another for loop. We have seen the syntax of nested for loop and we have seen 3 examples on it. We have seen how to take inputs in nested for loop and print that input. Nested for loop is very useful when we are working with any type of matrices or we are trying to print any patterns. Nested for loop will be useful when we are working with any sorting algorithms.

The post C++ Nested for Loop appeared first on The Crazy Programmer.



from The Crazy Programmer https://ift.tt/FyqzrTt

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget