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;
}