Tuesday, December 8, 2020

Learn recursion for beginners.

 Learn recursion for beginners.


Recursion is a function that call itself. It is an important concept. Recursion should must have a base condition that stop it from further calling.


General syntax of recursion.


void fun(int x)

{

        //  logic

}

int main()

{

      fun(x);

     return 0;

}


When we call the recursion then printing is done at two time;

  1. Printing at calling time.
  2. Printing at returning time.


Printing at calling time:



#include<stdio.h>

void fun(int x)

{

if(x>0)

{

printf("%d",x);

fun(x-1);

}

}

int main()

{

int x = 3;

fun(x);

return 0;

}


Printing at returning time:


#include<stdio.h>
void fun(int x)
{
if(x>0)
{
fun(x-1);
printf("%d",x);
}
}
int main()
{
int x = 3;
fun(x);
return 0;
}


Difference between loop and recursion:


1. Loop is repetitive statement.
2. Recursion is also repetitive statement.But loop will have ascending phase and recursion will have both ascending and descending phase.




Types of recursion:

  1. Tail recursion
  2. Head recursion
  3. Tree recursion
  4. Indirect recursion
  5. Nested recursion


 1.Tail recursion:

This is type of recursion where everything performed at calling time.Function will not do anything at returning time.

Program:

#include<stdio.h>

void fun(int x)

{

if(x>0)

{

printf("%d",x);

fun(x-1);

}

}

int main()

{

int x = 3;

fun(x);

return 0;

}


2.Head recursion:


This type of recursion will perform everything at returning time.This will not do anything at calling time.

If the function is performing something at returning time it can't be easily converted into loop but it can be converted.

Program that explain head recursion:


#include<stdio.h>
void fun(int x)
{
if(x>0)
{
fun(x-1);
printf("%d",x);
}
}
int main()
{
int x = 3;
fun(x);
return 0;
}


3. Tree recursion.


In this type of recursion a function is called multiple time.

Program that explain tree recursion:


#include<stdio.h>
void fun(int x)
{
if(x>0)
{
printf("%d",x);
fun(x-1);
fun(x-1);
}
}
int main()
{
int x = 3;
fun(x);
return 0;
}


4. Indirect recursion.


In indirect recursion there may be more than one function calling each other in circular fashion.So that the first function calls second one and then second function calls third one and then third function again callback first function.


Then it become a cycle so it become recursion.


5. Nested recursion.

This is basically recursion inside recursion.


#include<stdio.h>

int fun(int n)

{

if(n>100)

{

return n-10;

}

else

{

return fun(fun(n+10));

}

}

int main()

{

int x = 3;

int d = fun(x);

printf("%d",d);

return 0;

}

Web development for beginners.

 Web development for beginners.


This course will make you an expert in web development.But before moving on this advance topic you should be very well versed with your fundamentals of programming.Because it will boost your journey to become full stack web developer.


This course is designed for absolute beginner covering all aspect of web development.Here you will find all topic covering all aspect of web development.


Before knowing what is a full stack web developer or what work a full stack developer does,we should know what is frontend and backend


What is frontend?


Let's understand it with very simple example we all are aware from facebook,when we type facebook.com in our web browser it redirects us to official website of facebook.Where it wither tells us to login or signup.This is frontend part of facebook.So basically frontend part communicate with clients. The part which communicate with client is called as frontend part.


What is backend?



Let's continue with our facebook example while we enter our details like name,email,password.We must imagine where all these data goes.All these data gets stored inside a database.So that again when we logged in, facebook can authenticate a valid user and must identifies every user as independent identity.

So this part come into playing with data.This is what a backend developer does.


So know i hope you all must be aware from frontend and backend part in brief. Now come to our main topic we should now in position to know what is a full stack we developer.So a developer which can handle both frontend and backend part is called as a full stack web developer.This is what we will cover in this course. 


Tools that we required to become a frontend web developer


There are very basic tools or you can say a frontend web developer should must know these tools.
These are :

  1. HTML
  2. CSS
  3. JAVASCRIPT


1.HTML


This is what a web developer should must know.Without HTML
you can't consider any web page or web application.This should be known by every web developer.HTML is used to structure our web page.The page that you are seeing right now is structure using HTML.


2.CSS


This is used to give style to web page.Without CSS our web page might not looks so good and interactive as compared to when we use CSS to designed our web page.

So you can consider CSS as web styler who style our web page.


3.JAVASCRIPT


This is used to add interactivity with our web page.Have you ever seen when we click on button then modals open up or when we click on drop-down menu then it will display all element.All these things are implemented using javascript.

As i think according to today market skills every one should must know javascript.Because javascript is used every where in web application from frontend to backend.


Tools that we required to become a frontend web developer


To become backend web developer there are many popular language you can pick up any one and just learn it thoroughly.

In this course we will learn two most popular backend language:

  1. PHP
  2. Node.js

Find whether an element is present in an array or not.

 Find whether an element is present in an array or not.


Question: Write a program to find whether an element is present in an array or not?

Explanation: 

        A[10] = {10,20,30,40,50,60},ele = 60

    

   We have to find whether element 60 is present in our array or not.


Programs:


#include<iostream>

using namespace std;

int main()

{

int A[10] = {10,20,30,40,50,60},pos,ele,flag=0;

cout<<"Enter an element to search:"<<endl;

cin>>ele;

for(int i=0;i<6;i++)

{

if(A[i] == ele)

{

flag = 1;

break;

}

}

if(flag==1)

{

cout<<"Element found";

}else{

cout<<"Element not found";

}

return 0;

}

FInd index of an element in array.

 Find index of an element in array.


Question: write a program to find index of an element in array ?

Explanation:

A[10] = {10,20,30,40,50,60},ele = 60.

Answer: 5

Because element 60 is present at index 5.


Program:


#include<iostream>

using namespace std;

int main()

{

int A[10] = {10,20,30,40,50,60},pos,ele,flag=0;

cout<<"Enter an element to search:"<<endl;

cin>>ele;

for(int i=0;i<6;i++)

{

if(A[i] == ele)

{

pos = i;

flag = 1;

break;

}

}

if(flag==1)

{

cout<<"Element found"<<pos;

}else{

cout<<"Element not found";

}

return 0;

}

Deletion in an array for beginner for free.

 Deletion in an array.


For example:


After deletion: A[] = {10,20,30,40,50,60};

Delete an element at index = 3.

After deletion:  A[] = {10,20,30,50,60};


Programs:


#include<iostream>

using namespace std;

int main()

{

int A[10] = {10,20,30,40,50,60},delPos = 3;

for(int i=delPos+1;i<6;i++)

{

A[i-1] = A[i];

}

for(int i=0;i<5;i++)                                                

{

cout<<A[i]<<endl;

}

return 0;

}

Insertion in an array for beginner in c++.

 Insertion in an array.

For example:

Before insertion:  A[] = {10,20,30,40,50,60};

Insert an element = 100 at position index = 3.

After insertion: A[] = {10,20,30,100,40,50,60};


Program:


#include<iostream>
using namespace std;
int main()
{
int A[10] = {10,20,30,40,50,60},position = 3,element = 100;
for(int i=5;i>= position;i--)
{
A[i+1] = A[i];
}
A[position] = element;
for(int i=0;i<7;i++)
{
cout<<A[i]<<endl;
}
return 0;
}

Arrays for beginners for free.

Array.


Array is basically a contiguous memory allocation of same data type.It can't be of different data type.

It is a homogeneous continuous memory allocation.


We will learn about:

  1. What is an Array
  2. Declaring and initializing
  3. Accessing array element

1.What is an array:


Array is basically a contiguous memory allocation of same data type.It can't be of different data type.

It is a homogeneous continuous memory allocation.


2.Declaring and initializing:


int A[5];

The above statement is used for declaring an array.

int A[5] = {1,2,3,4,5};

The above statement is used for initialing an array.


Program to illustrate difference between declaring and initializing:


#include<iostream>
using namespace std;
int main()
{
int A[5];
int B[5] = {1,2,3,4,5};
for(int i=0;i<5;i++)
{
cout<<"Enter element for array A";
cin>>A[i];
}
for(int i=0;i<5;i++)
{
cout<<A[i]<<" ";
}
cout<<endl;
for(int i=0;i<5;i++)
{
cout<<B[i]<<" ";
}
return 0;
}

3.Accessing array element:

We can access array element with their position index.

Program that will explain how to access array element:


#include<iostream>
using namespace std;
int main()
{
int A[5];
for(int i=0;i<5;i++)
{
cout<<"Enter element for array A";
cin>>A[i];
}
for(int i=0;i<5;i++)
{
cout<<A[i]<<" ";
}
return 0;
}


Programs on array:




Data structure and algorithm for beginner for free

 Data structure and algorithm for free


In this blog you will get to know each data structure and algorithm in details for free.This course is designed absolutely for free for beginners.Each topic is explain in depth for free for beginners.


But before moving to understand each topic in depth we should know fundamentals of programming.So prerequisite of this course would be familiar with fundamentals of programming like how to take input,outout,loops,functions.


If you don't know you can click here to learn fundamental of programming for free in depth. 


But before moving to know what is data structure and algorithm we should definitely know what is programming.


Programs:


A program is set of instructions which perform some operations on data.Data is important part of program.When a program executes it operates on some data.


Data structure and algorithm:


How we organise data in main memory during execution of program this is known as data structure and algorithm.This become very important part for any program that you they are organizing their data so that it could be used very effectively.How our program is using our data.What is complexity of our program.These are very important factor when we designed an algorithm to solve our problem.


So we can say that data structure is all about how you are going to store your data in your main memory so that it could be effectively used by your programs.

Now in this course you will get to know each data structure and algorithm in depth for free.

Here we are going to use C as our fundamental language to implement our data structure.Because if you will use C++ then you have STL to do everything and similarly for java we have collection class.

If you want to learn C in depth then click here.

C is not having any built in data structure.That's why we are going to use this because it is not sufficient to know data structure.It become very important for us how to implement them also.

Types of data structure:


  1. Physical data structure
  2. Logical data structure

1.Physical data structure


These are type of data structure which helps in how to organise your data in main memory.

Example of physical data structure.

  1. Arrays
  2. Matrices
  3. Linked list

2.Logical data structure


These are type of data structure which helps in how data can be utilized very effectively.

Example of logical data structure.

  1. Stack
  2. Queues
  3. Trees
  4. Graph
  5. Hashing

We will discuss each of them in depth.Here is topic wise links of each data structure.
Happy coding...

  1. Array
  2. Recursion
  3. Matrices
  4. Linked list
  5. Stack
  6. Queues
  7. Trees
  8. Graph
  9. Hashing


Saturday, December 5, 2020

Simple pattern 6 in C++ language.

 Simple pattern 6 in C++ language.



In this blog we will learn to print simple pattern in C++.It is very simple pattern printing.It is fundamental part of programming.


We are going to print below pattern:


Question: Write a program in c++ that take input from user and print following pattern till user input?

                   1
              1   2
        1    2   3
   1   2    3   4


solution:


#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
int count = 1;
for(int j=1;j<=n;j++)
{
if(j >= n-i+1)
{
cout<<count++;
}
else
{
cout<<" ";
}
}
cout<<endl;
}
return 0;
}

Simple pattern 5 in C++.

Simple pattern 5 in C++.


In this blog we will learn to print simple pattern in C++.It is very simple pattern printing.It is fundamental part of programming.


We are going to print below pattern:


Question: Write a program in c++ that take input from user and print following pattern till user input?


1

1 2

2 3 4

4 5 6 7

7 8 9 10 11

11 12 13 14 15 16


solution:


#include<iostream>
using namespace std;
int main()
{
int n,now=1,prev=1;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
prev = now;
cout<<now++<<" ";
}
now = prev;
cout<<endl;
}
return 0;
}

Simple pattern 4 in C++.

Simple pattern 4 in C++.


In this blog we will learn to print simple pattern in C++.It is very simple pattern printing.It is fundamental part of programming.


We are going to print below pattern:


Question: Write a program in c++ that take input from user and print following pattern till user input?


1

2   3

4   5    6

7    8    9   10


solution:


#include<iostream>
using namespace std;
int main()
{
int n,count=1;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
cout<<count++<<" ";
}
cout<<endl;
}
return 0;
}

 

Simple pattern3 in C++.

Simple pattern 3 in C++.


In this blog we will learn to print simple pattern in C++.It is very simple pattern printing.It is fundamental part of programming.


We are going to print below pattern:


Question: Write a program in c++ that take input from user and print following pattern till user input?


1

2   1

3    2    1

4    3    2   1


solution:


#include<iostream>

using namespace std;

int main()

{

int n;

cin>>n;

for(int i=1;i<=n;i++)

{

int x = i;

for(int j=1;j<=i;j++)

{

cout<<x--<<" ";

}

cout<<endl;

}

return 0;

}  

Simple pattern2 in C++.

Simple pattern2 in C++.


In this blog we will learn to print simple pattern in C++.It is very simple pattern printing.It is fundamental part of programming.


We are going to print below pattern:


Question: Write a program in c++ that take input from user and print following pattern till user input ?


1

2   2

3    3    3

4    4    4   4 


solution:


#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
cout<<i<<" ";
}
cout<<endl;
}
return 0;
}

Friday, December 4, 2020

Simple pattern1 in C++.

 Simple pattern1 in C++.


In this blog we will learn to print simple pattern in C++.It is very simple pattern printing.It is fundamental part of programming.


We are going to print below pattern:


Question: Write a program in c++ that take input from user and print following pattern till user input ?

1

1    2

1    2    3

1    2    3    4

1    2    3    4    5


solution:


#include<iostream>

using namespace std;

int main()

{

int n;

cin>>n;

for(int i=1;i<=n;i++)

{

for(int j=1;j<=i;j++)

{

cout<<j<<" ";

}

cout<<endl;

}

return 0;

}


If you want to learn c++ in depth then do visit: learn c++ in depth.

Function in C++ language.

 Learn programming for free


Function in C++ language.



Function is basically a block of statement which is used to perform some specific task.


In C++  language we have 4 type of function.When we declare a function then it tells the compiler about return type of function,parameter of function and it's function name.


In C++ language we divide large program into blocks and call them as and when they required.

We will discuss function in depth in this blog.


Types of function.


  1. Function without parameter and without return type.
  2. Function without parameter and with return type.
  3. Function with parameter and without return type.
  4. Function with parameter and with return type.

We will discuss each of them with very basic example:


1.Function without parameter and without return type:


#include<iostream.h>

using namespace std;

void sum()
{
int a,b,sum=0;
cout<<"Enter first number:";
cin>>a;
        cout<<"Enter second number:";
cin>>b;
sum = a+b;
cout<<sum;
}

int main()
sum();
return 0; 
}


2.Function without parameter and with return type:


#include<iostream.h>

using namespace std;

int sum()
{
int a,b,sum=0;
cout<<"Enter first number:";
cin>>a;
cout<<"Enter second number:";
cin>>b;
sum = a+b;
return sum;
}
int main()
int x = sum();
cout<<x;
return 0; 
}


3.Function with parameter and without return type:


#include<iostream.h>

using namespace std;

void sum(int a,int b)
{
int sum = a+b;
cout<<sum;
}
int main()
int a,b;
        cout<<"Enter first number:";
cin>>a;
cout<<"Enter second number:";
cin>>b;

sum(a,b);
return 0; 
}

4.Function with parameter and with return type:

#include<iostream.h>

using namespace std;

int sum(int a,int b)
{
int sum = a+b;
return sum;
}
int main()
int a,b,x = 0;
         cout<<"Enter first number:";
cin>>a;
cout<<"Enter second number:";
cin>>b;
x = sum(a,b);

cout<<x;
return 0; 
}

Function in C language.

Learn programming for free

Function in C language.


Function is basically a block of statement which is used to perform some specific task.


In c language we have 4 type of function.When we declare a function then it tells the compiler about return type of function,parameter of function and it's function name.


In C language we divide large program into blocks and call them as and when they required.

We will discuss function in depth in this blog.


Types of function.


  1. Function without parameter and without return type.
  2. Function without parameter and with return type.
  3. Function with parameter and without return type.
  4. Function with parameter and with return type.

We will discuss each of them with very basic example:


1.Function without parameter and without return type:


#include<stdio.h>
void sum()
{
int a,b,sum=0;
printf("Enter first number");
scanf("%d",&a);
printf("Enter second number");
scanf("%d",&b);
sum = a+b;
printf("Sum of two number is %d",sum);
}
int main()
sum();
return 0; 
}


2.Function without parameter and with return type:


#include<stdio.h>
int sum()
{
int a,b,sum=0;
printf("Enter first number");
scanf("%d",&a);
printf("Enter second number");
scanf("%d",&b);
sum = a+b;
return sum;
}
int main()
int x = sum();
printf("Sum of number is: %d",x);
return 0; 
}


3.Function with parameter and without return type:


#include<stdio.h>
void sum(int a,int b)
{
int sum = a+b;
printf("Sum of number is %d",sum);
}
int main()
int a,b;
printf("Enter first number");
scanf("%d",&a);
printf("Enter second number");
scanf("%d",&b);
sum(a,b);
return 0; 
}

4.Function with parameter and with return type:

#include<stdio.h>
int sum(int a,int b)
{
int sum = a+b;
return sum;
}
int main()
int a,b,x = 0;
printf("Enter first number");
scanf("%d",&a);
printf("Enter second number");
scanf("%d",&b);
x = sum(a,b);
printf("Sum of number is %d",x);
return 0; 
}

Do you want to learn c language in depth then visit:  learn c language in depth.

Thursday, December 3, 2020

Loops in C++.

 Learn programming for free


Loops in C++


In C++ loops is basically of three types.

  1. For loop
  2. while loop
  3. do while loop

We will learn all of them in depth with a question so that it becomes easy to learn and understand.


Question: Write a program in c language which will take input from user and print all number in between 1 to entered number?


1.For loop


#include<stdio.h>
int main()
{
int n,i=1;
cout<<"Enter a number";
cin>>n;
for(i=1;i<=n;i++)
{
cin>>i;
}
return 0;
}


Syntax of for loop is:

for(initialization;condition;increment/decrement)
{
    
        //logic

}

Explanation:

According to question user will enter a number and we need to print all number between 1 to that number.So we take input from user and inside for loop we initialize our for loop to start from 1 and go till entered number.For each iteration we increment i so that when matched conditions found it terminates for loop and comes out of loop.

And for each iteration we have printed the number.


2.While loop


#include<stdio.h>
int main()
{
int n,i=1;
cout<<"Enter a number";
cin>>n;
while(i<=n)
{
cout<<i;
i++;
}
return 0;
}

While loop is also called as entry controlled loop because it first checks the conditions.If conditions found to be true then only it enters in loop otherwise it skips the loop.

So in above example we have first initialize a variable i = 1.And before entering in while loop we checked the condition since 1<=n ( suppose n=10) then it will enter into loop and print that number.

One important point that we should keep in our mind that inside our while loop we must increment our variable otherwise it will lead to infinite loop condition.


3. do-while loop


#include<stdio.h>
int main()
{
int n,i=1;
cout<<"Enter a number";
cin>>n;
do
{
cout<<i;
i++;
}while(i<=n);
return 0;
}


do-while loop is called as exit-controlled loop because it first executes a statement then check conditions.If our initial condition is found to be false then also it will execute for once.That's why it is known as exit-controlled loop. 

If you want to learn c++ in depth then do visit: learn c++ in depth