Saturday, October 31, 2020

swap nums

p> Dear readers,

Today we will try to perform swapping the numbers exercise in python, c and c++:

So there are two Logical ways used:

Logic 1:

Here :

1.copy elements from number_1 into a temporary variable 

2. copy number 2 to number_1 

3. copy number_1 from (temporary variable) to number_2

so example:

number_1 = 10

number_2 = 12

Step 1. temporary variable = 10

Step 2.number_1 = 12

Step3.number_2 = 10(from temporary  variable) 

number_1 = 12

and 

number_2 =10

Logic 2:

Note: This is more programmer oriented logic

1.number_1 = number_1 + number_2 ---> [1]

2.number_2 = number_1 - number_2 => using [1]: number_1 + number_2 - number_2 == number_1 --> [2]

3.number_1 = number_1 - number2 => using [2] and [1]:  number_1 +number_2 - number_1 == number_2 

example

number_1 = 10, number_2 = 12

1,number_1 = 10 + 12 = 22

2.number_2 = 22 - 12 = 10(10 + 12 - 12)

3.number_1 = 22 - 10 = 12(10 + 12 - (22 - 12))==>(34-22)==>(12)

number_1 = 12 ,number_2 = 12

Lets Code now

#1. Python

# swapping number logic
num1 = int(input('enter first number:\n'))
num2 = int(input('enter first number:\n'))
print(f'numbers before swap a:{num1} and b:{num2} ')
# Logic is used here
temp = num1
num1 = num2
num2 = temp
print(f'\nnumbers after swap a:{num1} and b:{num2} ')
#This is second Logic
num1 = int(input('enter first number:\n'))
num2 = int(input('enter first number:\n'))
print(f'numbers before swap a:{num1} and b:{num2} ')
num1 = num1 + num2
num2 = num1 - num2
num1 = num1 - num2
print(f'\nnumbers after swap a:{num1} and b:{num2} ')

#2.C++

#include <iostream>
using namespace std;

int main()
{
    int num1, num2, temp;

    cin >> num1 >> num2;
    cout << "Before swapping num1 = " << num1 << ", num2 = " << num2  << endl;
    //Logic is used here
    temp = num1;
    num1 = num2;
    num2 = temp;

    cout << "\nAfter swapping num1 = " << num1 << ", num2 = " << num2 << endl;
    //here is second Logic
    cout<<"\nTry with Second Logic:\n"<<endl;

    cin >> num1 >> num2;

    cout << "Before swapping num1 = " << num1 << ", num2 = " << num2  << endl;
    //Logic is used here
    num1 = num1 + num2;
    num2 = num1 - num2;
    num1 = num1 - num2;

    
    cout << "\nAfter swapping num1 = " << num1 << ", num2 = " << num2 << endl;

    return 0;
}

# C

#include<stdio.h>

int main(){
    int num1 ,num2,temp;
    printf("enter number1 and number2:\n");
    scanf("%d%d",&num1,&num2);
    printf("numbers before swap are num1 :%d num2:%d",num1,num2);
    // logic used here
    temp = num1;
    num1 = num2;
    num2 = temp;
    
    printf("\nnumbers after swap are num1 :%d num2:%d\n",num1,num2);
    //Second Logic
    printf("Try with the second Logic...\n");
    
    printf("enter number1 and number2:\n");
    scanf("%d%d",&num1,&num2);
    printf("numbers before swap are num1 :%d num2:%d",num1,num2);

    // logic used here
    num1 = num1 + num2;
    num2 = num1 - num2;
    num1 = num1 - num2;
    
    printf("\nnumbers after swap are num1 :%d num2:%d",num1,num2);


}

Friday, October 30, 2020

Hello World

 Hello World!!

Dear Readers,

Today I would share simple hello world programs from popular computer languages, like Python, C ,

Java, C++ . This blog is meant to express the simplicity and strength of Python programming language

1. Python 

# Hello world in Python 
print 'hello world!'

2. C

/* hello world in c */
#include <stdio.h>

int main() {
  printf("Goodbye, World!");
  return 0;
}

3. Java

// Hello World in Java
public class Main {
    public static void main(String[] args){
        System.out.println("Hello World!");
    }
}

4. C++

// Hello world in C++
#include<iostream>
using namespace std;

int main(){
cout<<"Hello World!"<< std::endl;
return 0;
}

Thursday, October 29, 2020

Different languages

 Dear Readers,

Todays Blog would be a brief introduction about MAJOR programming languages :

Types of Programming Languages

The different types of programming languages are discussed below.

Types of Programming Paradigms

The importance of different Programming Languages

Python Language

Python is powerful... and fast plays well with others runs everywhere is friendly & easy to learn is Open. Python is a programming language that lets you work more quickly and integrate your systems more effectively. You can learn to use Python and see almost immediate gains in productivity and lower maintenance costs.


WHY TO LEARN PYTHON:

  • Web and Internet Development
  • Database Access
  • Desktop GUIs
  • Scientific & Numeric
  • Education
  • Network Programming
  • Software & Game Development
Disadvantages:
  • Speed. Python is slower than C or C++. 
  • Mobile Development. Python is not a very good language for mobile development . 
  • Memory Consumption. Python is not a good choice for memory intensive tasks. 
  • Database Access. Python has limitations with database access . 
  • Runtime Errors.
Python Language


    

Java Language

The Java language is a multi platform language that’s particularly helpful in networking. Of course, mostly this language is used on the web with Java applets. However, this language is used to design cross platform programs, Since it similar to C++ in structure and syntax. For C++ programmers, Java language is very easy to learn and it offers some advantages provided by object oriented  programming. Like reusability and it can be difficult to write efficient code in Java. But, nowadays the speed of the Java language has increased and 1.5 version offers some good features for easy program making.


Why Learn Java:

  • Java is a platform-independent language. We can write Java code in one platform and run it in another platform
  • Java is a general-purpose language with a wide range of applications. It's used for developing mobile and desktop applications, big data processing, embedded systems, and so on.
  • Java is an object-oriented programming language. It helps in code reusability. 
Disadvantages:
  • Java is slow and has a poor performance. Java is memory-consuming and significantly slower than native languages such as C or C++. 
  • Java provides not so attractive look and feels of the GUI. 
  • Java provides no backup facility.
  • Java requires significant memory space. 
  • Verbose and Complex codes.


          Java Language

          Java Language


          C++ Language

          The C++ language has an object oriented structure which is used in large projects. Programmers can collaborate one program into different parts or even one individual work on each part of the program. The structure of object oriented also permit code to be reused many times. This language is an efficient language. But, many programmers will disagree

          WHY TO LEARN C++:

          • C++ is used to develop games, desktop apps, operating systems, browsers, and so on because of its performance.
          • After learning C++, it will be much easier to learn other programming languages like Java, Python, etc.
          • C++ helps you to understand the internal architecture of a computer, how computer stores and retrieves information.
          Disadvantages :
          • It has no security.
          • Complex in a very large high-level program.
          • Used for platform specific application commonly.
          • For a particular operating system or platform, the library set has usually chosen that locks.
          • When C++ used for web applications complex and difficult to debug.
          • C++ can't support garbage collection.
          C++ Language

          C++ Language

          C Language

          The C language is a  basic programming language and it is a very popular language, particularly used in game programming, Because C language includes the additional packing of the C++, Every programmer uses this language because it makes programs faster . However the value of this language gives the reusability of C++ to get the slight increase in performance with C language.

          Why Learn C Programming :

          • C helps you to understand the internal architecture of a computer, how computer stores and retrieves information.
          • After learning C, it will be much easier to learn other programming languages like Java, Python, etc.
          • Opportunity to work on open source projects. Some of the largest open-source projects such as Linux kernel, Python interpreter, SQLite database, etc. are written in C programming.

          Disadvantages:

          • Concept of OBJECT ORIENTED PROGRAMMING. C is a very vast language, but it does not support the concept of OOPs (Inheritance, Polymorphism, Encapsulation, Abstraction, Data Hiding). ...
          • Run-time checking. 
          • Concept of namespace. 
          • Lack of Exception Handling. 
          • Constructor or destructor.
          • Low level of abstraction.
          C Language

          C Language

          Fortran Language

          Fortran language is a number crunching language and still it is used by scientists. This language allows different sizes of variables up to the memory limit in the machine. This language is suitable for engineers, who have to calculate values with high precision. Program in Fortran is inflexible and sometimes it makes difficult to read.

          WHY TO LEARN FORTRAN:

          •  used for such projects as the design of bridges and aeroplane structures
          •  it is used for factory automation control, for storm drainage design
          •  used for the analysis of scientific data 

          Disadvantages :

          • Lack of inherent parallelism. 
          • Lack of dynamic storage. 
          • Lack of numeric portability. 
          • Lack of user-defined data structures. 
          • Lack of explicit recursion. 
          • Reliance on unsafe storage and sequence association features.
          Fortran Language

          Fortran Language


          Photo Credits:

          Wednesday, October 28, 2020

          Random module

          Random Module

           
          Dear Readers,
          todays post is on random module
          
                                        Random Module Usage in Python
          
          Importing necessary libraries from random module

          from random import random,gauss,randrange,randint,sample,choice,choices,seed
          
          # Use seed to get same random number again and again as the output, without seeding you would get varied output everytime you run the program.
          
          seed(9)
          
          # for getting a random floating number always less than one
          
          print(random())
          
          # for getting intergers we use randint and randrange ,randint(start_value,stop_value) and randrange(start_value,stop_value)
          
          print(randint(0,9))
          print(randrange(0,1000))
          
          # get a random choice out of a list or a tuple using choice attribute , you can use choices to get a random sample as an output with specified size
          
          list1 = ['a','b','c','d','e','f','g','h']
          print(choice(list1))
          print(choices(list1,k=4)) # here k means size of the output/or number of random selections to be made and ouput is in list format
          
          # to get a gaussian number we use , gauss(mean,standard deviation) ['THIS IS OPTIONAL'] 
          
          print(gauss(10,2.5))
          
          # like random choices we can use random sample, like sample(list_name,size)
          
          list2 = [1,2,3,4,5,6,7]
          print(sample(list2,4)) # outputs list format only
          

          Tuesday, October 27, 2020

          Blogs

                                 Regular Python Blogs

          Dear Readers,

          python blogs picture


          I welcome you all to my blogs related to python programming language, I assure you it would be worth every second of your time you give to read my blogs . I would keep it short and regular so those who would love to get regularly updated would benefit the most out of my blogs.

          SO, with a shining hope of learning on the way through my blogs for you and for me as well while writing them for you I urge you to keep learning and growing.

          Linear Search algorithm

          Linear Search Algorithm Dear Readers, In this Blog today I would Share about Linear Search Algorithm a must know for everyone whether you wa...