Install Go Lang latest version 1.15.5 in ubuntu

Download and install

we can install the Go Lang in very easy and simple steps in Linux(Ubuntu)

1. Download Go

2. Install Go

3. Check version of Go

1. Download Go.

Use Curl or wget to download the current binary for Go from the official download page.


sudo wget https://golang.org/dl/go1.15.5.linux-amd64.tar.gz


 If Wget or curl not install, install wget and curl first.


2. Go install.


Extract the archive you downloaded into /usr/local, creating a Go tree in /usr/local/go by below command.

Important: This step will remove a previous installation at /usr/local/go, if any, prior to extracting. Please back up any data before proceeding.

For example, run the following.

sudo tar -C /usr/local -xzf go1.15.5.linux-amd64.tar.gz



Add the go binary path to .bashrc file /etc/profile. Add /usr/local/go/bin to the PATH environment variable.

You can do this by adding the following line to your $HOME/.profile or /etc/profile (for a system-wide installation): 
 
export PATH=$PATH:/usr/local/go/bin

After adding the PATH environment variable, you need to apply changes immediately by running the following command.

source ~/.bashrc

3. Check version of Go

 
Verify that you've installed Go by opening a command prompt and typing the following command: 
 
go version

 

You can also install go from the snap store too.


sudo snap install --classic --channel=1.15/stable go



Remove Go Lang from the system completely: 

To remove an existing Go installation from your system delete the go directory. This is usually /usr/local/go under Linux.


 sudo rm -rf /usr/local/go 

 sudo nano ~/.bashrc # remove the entry from $PATH 

 source ~/.bashrc

Python: triangle of stars partten proramming.

 Question:

write a program in python to print the triangle of stars.

Answer:

=====Code  =========

num=int(input("Enter the number ::"))
i=1
for i in range(num):
    for j in range(i+1):
        print("* " , end = ' ')
    print(" ")

 

====== output is ======

HP-Notebook:~$ python3 pyramid.py

Enter the number :: 5
*   
*  *   
*  *  *   
*  *  *  *   
*  *  *  *  *   

Description:

The num is a variable which stores the value input if user.  

num=int(input("Enter the number ::"))

we have applied two loops. 

- First loop: Normal loop statement

- Second Loop: Nested Loop statement(loop inside the loop).

First loop:

First Loop will tell that how many rows will be there in the triangle.  the iteration of this loop will change the line for printing the stars  as shown in the output.

Second Loop:

Second loop will tell that how many starts will be print in single line ( one iteration of first loop ).

At the end normal print function used for change the line. it is under the first loop.

print(" ")

 

C: Sum of two integer numbers.

Question:

Write a program to find the sum of two integer numbers.

Answer:


#include<stdio.h>
int main() {    

    int number1, number2, sum;
    
    printf("Enter First integers: ");
    scanf("%d", &number1);
    
    printf("Enter Second integers: ");
    scanf("%d", &number2);

    // calculating sum
    sum = number1 + number2;      
    
    printf("Sum of two numbers: %d + %d = %d \n", number1, number2, sum);
    return 0;
} 
 


Output is:


In below screen shoot, we have shown that how to compile C file(add.c) and run over linux(Ubuntu)
system.
 

C: Search an element from array.

Question:

 Write a program to find the element of array.

 Answer:

 Here  we have mentioned three ways by which we can find the element of array.

1- By using General method.

2- By using function

3- By using recursion

 

1- By using General method:

Code: -------------------------------------------

#include <stdio.h>
int main()
{
    int a[10000],i,n,key;     //Defines variables and given the size of array

    printf("Enter size of the  array : ");
    scanf("%d", &n);
    printf("Enter elements in array : ");
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
     printf("Enter the key : ");
    scanf("%d", &key);

    for(i=0; i<n; i++)
    {
        if(a[i]==key)
        {
printf("Element %d found at %d index of array \n",key,i);
            return 0;
        }

    }

printf("Element  is not  found in array");
}

------------------------------------------------------
 Output is:

Desktop/C_Pro$ vi searchelement.c
Desktop/C_Pro$ gcc searchelement.c -o searchelement
Desktop/C_Pro$ ./searchelement
Enter size of the  array : 5
Enter elements in array : 12
13
14
16
17
Enter the key : 16
Element 16 found at 3 index of array
 
 
2- By using function:


Code:---------------------------------------------

#include <stdio.h>
int search(int *a,int n,int key)  //Function definition.
{
int i;
    for(i=0; i<n; i++)                //match key will each element of array.
    {
        if(a[i]==key)
        {
             return 1;
        }
 
    }
    
return 0;          
      
}
 
  
int main()
{
    int a[10000],i,n,key;   //Defines variables and given the size of array
  
    printf("Enter size of the  array : ");
    scanf("%d", &n);
    printf("Enter elements in array : ");
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
     printf("Enter the key : ");
    scanf("%d", &key);
    
     if(search(a,n,key))      //Function call
     printf("Element found ");
     else
     printf("Element is not found ");
    
    
}
------------------------------------------------------
 
 

3- By using recursion:
 
Code:----------------------------------------------

#include <stdio.h>
int search(int *a,int i,int n,int key)
{
    if(i<n)
    {
     if(a[i]==key)
     return 1;
    
     return search(a,i+1,n,key);
    
}
    
return 0;          
      
}
 
  
int main()
{
    int a[10000],i,n,key;      //Defines variables and given the size of array
  
    printf("Enter size of the  array : ");
    scanf("%d", &n);
    printf("Enter elements in array : ");
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
     printf("Enter the key : ");
    scanf("%d", &key);
    
     if(search(a,0,n,key))            //recursion, call itself again again till certain con.. 
     printf("Element found ");
     else
     printf("Element is not found ");
    
    
}
--------------------------------------------- 





Note:
Execute above code online. below link will  take you on online compiler.
 

Python: Write a program to find the reverse of given number.

 

Question: 
Write a program in python to find the reverse of given number.
 
Answer:
 
num=int(input("Enter the number:"))     # At this point we have taken an integer value from console.
 
 rev=(rev*10+num%10)         
# At this point we are finding the last number of integer stored in the "num" and that last number is added in previous 10th place of  "rev"(rev*10).
 
num=num//10      
# At this point last digit will be removed from number. "//" removed remainder from the number .
                               
code
---------------------------------------------------
num=int(input("Enter the number:"))
rev=0
while(num>0):
    rev=(rev*10+num%10)
    num=num//10
print("reverse =",rev)
 
---------------------------------------------------  

Output is:
 
Enter the number:98765123
reverse= 32156789

********************************************
Above code can also be write as below in simplest way:

---------------------------------------------------------
num=int(input("Enter the number:"))
reverse = 0
remainder = 0
while(num>0):
    remainder = num%10
    reverse = reverse*10 + remainder
    num = num//10

print("reverse=",reverse)
 
---------------------------------------------------------

Note:

you could run the above commands on online compiler. go to the below link and copy pest the code there and play with code to understand.

Link: https://www.programiz.com/python-programming/online-compiler/

C: Write a program to check whether a given number is integer or float.

 write a program to check whether a given number is integer or float.

C: Write a code for checking if a given input is an integer value or not.

 

Write a code for checking if a given input is an integer value or not.

 

Code

---------------------------------------------------------

#include <iostream>
using namespace std;
bool isNumeric(string str) {
   for (int i = 0; i < str.length(); i++)
      if (isdigit(str[i]) == false)
      return false; //when one non numeric value is found, return false
   return true;
}
int main() {
   string str;
   cout << "Enter a string: ";
   cin >> str;
   if (isNumeric(str))
      cout << "This is a Number" << endl;
   else
      cout << "This is not a number";
}
-------------------------------------------- 
Output

Enter a string: 5687 

This is a Number

Output

Enter a string: deve124

This is not a number

 

Java: Java-Programming Exercise

 

 

Java: Java-Programming Exercise

In this section, we have placed the list of java programs for doing some basic practices for beginners and experienced. solutions are also provided. please click the link shared below under each questions.

1- write a program to find the Fibonacci Series till max given number.

Answer: please click the below link.

Link:


2- 

Answer: please click the below link.

Link: 


3- 

Answer: please click the below link.

Link: 


4- 

Answer: please click the below link.

Link: 


5- 

Answer: please click the below link.

Link: 





Python: Python-Programming Exercise

 

Python: Python-Programming Exercise

In this section, we have placed the list of Python programs for doing some basic practices for beginners and experienced. solutions are also provided. please click the link shared below under each questions.

*******************************************

1-  Write a program to find the Fibonacci series with certain number of count.

Answer: please click the below link.

Result:

Enter the value of 'n': 10
0

1

1

2

3

5

8

13

21

34

Link: https://writeprogramin.blogspot.com/2021/04/python-fibonacci-sequence.html


2- Write a program to find the reverse of given number.

Answer: please click the below link.

Link: https://writeprogramin.blogspot.com/2021/04/python-write-program-to-find-reverse-of.html


3- write a program in python to print the triangle of stars.

Answer: please click the below link.

Enter the number :: 5
*   
*  *   
*  *  *   
*  *  *  *   
*  *  *  *  *  

Link:https://writeprogramin.blogspot.com/2021/04/python-triangle-of-stars-partten.html


Answer: please click the below link.

Link: 


5- 

Answer: please click the below link.

Link: 




C: C-Programming Exercise

C: C-Programming Exercise

In this section, we have placed the list of C programs for doing some basic practices for beginners and experienced. solutions are also provided. please click the link shared below under each questions.

*******************************

1- C program to print pyramid of triangle:

Answer: please click the below link.

Output:


Link:https://draft.blogger.com/blog/post/edit/4414337148028306636/6843421424660007569


2- Write a program to find the element of array.

Answer: please click the below link.

Output is:

Enter size of the  array : 5
Enter elements in array : 12
13
14
16
17
Enter the key : 16
Element 16 found at 3 index of array

 

Link: https://draft.blogger.com/blog/post/edit/4414337148028306636/7929215823725374484


3- Write a program to find the sum of two integer numbers and compile that over linux operation system.

Answer: please click the below link.

 


Output is:


In below screen shoot, we have shown that how to compile C file(add.c) and run over linux(Ubuntu)
system.
 

 

Link: https://draft.blogger.com/blog/post/edit/4414337148028306636/6211307688637386107


4- Write a code for checking if a given input is an integer value or not.

Answer: please click the below link.

Output

Enter a string: 5687 

This is a Number

Output

Enter a string: deve124

This is not a number

 

Link: https://draft.blogger.com/blog/post/edit/4414337148028306636/1343992793524398568


5- 

Answer: please click the below link.

Link: 



Python: Fibonacci sequence

 Fibonacci sequence:

Here we will look, that how to find the Fibonacci series/ Fibonacci sequence is  for certain given number.

1- Below line will take input from console. For type conversion we have placed "int" at starting point. so that it will store an integer number in "getNumFromConsole" variable.

getNumFromConsole = int(input("Enter the value of 'n': "))
 
If "int" is removed from above line then it will take string only.

After that we have taken some variables and assign some initial values. these initial values will be use in use when first iteration of loop will be executed. 
 

in below code under loop, we have just swapped the values of variable a and b. when first iteration of loop will execute, then all initial value will be in use and calculate the sum.

when second iteration of loop will execute, then sum will print and last stored value of b moved to variable a and value of sum will move to variable b, after that sum will be calculated as per the assign value.

 while(count < getNumFromConsole):
    print(sum)
    count = count + 1                    #increment loop count
    a = b
    b = sum
    sum = a + b 

 

Below table shows loop iteration how swapping of value is getting placed at every loop iteration.




Print SumVariable a Variable bVariable sum = a+bLoop_Iteration
0 0 1 1 Loop_1st Iteration All initial value is taken
1 0 1 1 Loop_2nd Iteration
1 1 1 2 Loop_3th  Iteration
2 1 2 3 Loop_4th  Iteration
3 2 3 5 Loop_5th  Iteration
5 3 5 8 Loop_6th  Iteration
8 5 8 13 Loop_7th  Iteration
13 8 13 21 Loop_8th  Iteration
21 13 21 34 Loop_9th  Iteration
34 21 34 55 Loop_10th  Iteration

 
 
 
Code:
============================


# python/bin/ 

getNumFromConsole = int(input("Enter the value of 'n': "))

a = 0                 #First variable 

b = 1                 #Second variable 

sum = 0 

count = 0                     #For the use of loop initial point. 

print("Fibonacci Series: ") 

while(count < getNumFromConsole):
    print(sum)
    count = count + 1                    #increment loop count
    a = b
    b = sum
    sum = a + b

==========================

Result:

Enter the value of 'n': 10


0

1

1

2

3

5

8

13

21

34