Wednesday, 8 September 2021

Introduction of python

Python is a high-level and most popular programming language. it was created by Guido van Rossum, and released on February 20, 1991.

Uses of python:-

It is used for general-purpose programming like

·         Mathematics

·         System scripting

·         Software development

·         Web development

Why python?

  •          Python works on different-different platforms like Windows, Mac, Linux, etc.
  •          It has a simple syntax.
  •          It has a syntax that allows developers to write the program with fewer lines than some other programming language.
  •          It has an object-orientated way or a functional way.

What can do python?

  •          It can connect to the database system and also read and modify files.
  •         It is used on the server to create the server-side application.
  •          It is used alongside software to create workflows.
  •          It is used to handle big data and performed complex mathematics.

Syntex in python:-

The syntax is the set of rules that defines how a Python program will be written and interpreted by both runtime systems and human readers.

  •       Python uses new lines to complete commands, as opposed to other programming languages which often use semicolons or parentheses.

  •          It relies on indentation, using whitespace, to define the scope of the loop, function, and classes. Other programming languages often use curly-brackets for this purpose.

Example:-

print("Hello Python")

Tuesday, 18 May 2021

Linear Recursion in C

If a recursive function is calling itself for only once then, the recursion is linear.
Pseudocode:-
fun(int n)
{


    if (n > 0)
    {


        ...
        fun(n - 1);     // Calling itself only once


        ...
    }


}
Note: The fun() is calling itself for only once.


 
Understanding linear recursion by a simple problem
C program to find a cube of the positive number using Recursion.
#include <stdio.h>
 


int fun(int n)
{


    static int x;
    if (n > 0)


    {
        x++;


        return fun(n - 1) + x * x;
    }


}
int main()


{
    int a;


    printf("number ");
    scanf("%d", &a);


    printf("%d", fun(a));
    return 0;


}
Output:-






 Tracing the above Recursion:-













C program to find the factorial of a positive number using Recursion.


#include <stdio.h>
 


int fun(int n)
{


    if (n == 0)
    {


        return 1;
    }


    else
    {


        return fun(n - 1) * n;
    }


}
 


int main()
{


    int x;
    printf("number ");


    scanf("%d", &x);
    printf("%d\n", fun(x));


    return 0;

}


Output:-