Restoring Division Algorithm Implementation In C

This is a dynamic program for the implementation of the Restoring division Algorithm in the C.Restoring Division uses Left Shift Operations, Twos’ Compliment and Binary Addition. Screenshots [Demo]: The Code #include<stdio.h>#include<malloc.h>int *a,*q,*m,*mc,*c,n,d;int powr(int x,int y){ int s=1,i; for(i=0;i<y;i++) s=s*x; return s;}void print(int arr[],int n){ int i; for(i=0;i<n;i++) printf(“%d “,arr[i]);}void bin(int n, int arr[]){ int r, i = 0; do{ r = n % 2; n /= 2; arr[i] = r; i++; }while(n > 0); }void set(int array[], int x){ int i,tmp[20]={0}; for(i = x -1; i >=0; i–) tmp[x-1-i]=array[i]; for(i=0;i<x;i++)…

Read More

Shuffle the characters of a string in Java

This is a program which accepts a string using the BufferdReader and InputStreamReader class, and then shuffle the characters present inside the string and generate a new string which is displayed in the console. Basically the characters of the string are stored in a Character List using the for each loop. Then the characters in that list is randomly removed and appended in a StringBuilder object output. Screenshots [Demo] The Code: import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.Collections;import java.util.List;import java.util.Random;class Brain{ public static void main(String []as)throws IOException { BufferedReader br=new BufferedReader(new…

Read More

Binary Addition in C

This is a dynamic program which accepts two integer from the console and convert them to Binary Numbers.After converting them, they are added and the result is then displayed in the console ! Binary addition is highly necessary because computer only understands the addition.  Whether in case of  multiplication it’s repetitive addition, in case of  division it is repetitive division and for subtraction it is the addition of the two’s compliment of the other number. Screenshots [DEMO] The Code: #include<stdio.h>#include<malloc.h>int *q,*m,*c,n,d,siz;int powr(int x,int y){ int s=1,i; for(i=0;i<y;i++) s=s*x; return s;}void…

Read More

Sort using algorithm header

The below program takes an array as input and prints the sorted array. The header <algorithm> defines a collection of functions especially designed to be used on ranges of elements.sort function takes two arguments. The arguments are the start index and end index of array. This header file does not work in c. It can be only used in C++. Output :  Code : #include<iostream>#include<algorithm>using namespace std;int main(){ int n; cout<<“Enter number of elements you want to sort : “; cin>>n; int a[n]; for(int i=0;i<n;i++) cin>>a[i]; sort(a,a+n); for(int i=0;i<n;i++) cout<<a[i]<<” “; return 0;}

Read More

Encryption Hackerrank Solution

This is the solution for the Encryption problem in the implementation section of the Algorithm domain. In this An English text needs to be encrypted using the following encryption scheme.First, the spaces are removed from the text. Let L be the length of this text. Then, characters are written into a grid, whose rows and columns have the following constraints: ⌊L−−√⌋≤rows≤column≤⌈L−−√⌉, where ⌊x⌋ is floor function and ⌈x⌉ is ceil function Screenshots[Demo] The Code: import mathdef perform(x,row,col): row=int(row) col=int(col) mat=[[” for i in range(0,col)]for j in range(0,row)] str=” k=0 for…

Read More

A simple Login Frame using awt in java

This is a simple program written in java that will be useful to create a simple login frame of any website or any java application. The main theme of this logic is to use the AWT framework design. No doubt, the login frame designing way is a bit older, but still one can easily understand and implement though. So have a look at the code.Sample Output:  Required Code: import java.awt.*;import java.awt.event.*;class LoginFrame extends Frame implements ActionListener{ Label l1,l2; TextField tf1,tf2; Button b1; String status=””; LoginFrame() { this.setVisible(true); this.setSize(500,500); this.setBackground(Color.green); this.setTitle(“Login…

Read More

Create a Tic tac toe game using c++

The following program is the source code of a game called tic tac toe. The program is implemented using c++. Code : #include<iostream>#include<windows.h>using namespace std;char a[9]={‘1′,’2′,’3′,’4′,’5′,’6′,’7′,’8′,’9’};char c1,c2;void draw_board(){ cout<<“nn”; cout<<” “<<a[0]<<” | “<<a[1]<<” | “<<a[2]<<” “; cout<<endl<<” | | “; cout<<“n——-|——-|——-“; cout<<endl<<” “<<a[3]<<” | “<<a[4]<<” | “<<a[5]<<” “; cout<<endl<<” | | “; cout<<“n——-|——-|——-“; cout<<endl<<” “<<a[6]<<” | “<<a[7]<<” | “<<a[8]<<” “; cout<<endl<<” | | “;}int check_res(){ if(a[0]==a[1] && a[1]==a[2]) { if(a[0]==c1) return 1; else return 2; } else if(a[0]==a[3] && a[3]==a[6]) { if(a[0]==c1) return 1; else return 2; } else if(a[0]==a[4]…

Read More

A Simple Encryption and Decryption Program [Cryptography]

In this post you can learn the basic concept of Cryptography. This program accepts a string as the input and performs encryption with the key provided by the programmer. This is a basic Encryption method so it just involves changing each single character of the String with some simple algebric operations with the key. It can be added with each and every single character of the string, so can be subtracted or divided. But note Your have to apply reverse method. Sample Outputs: The Code: #include<iostream>#include<cstring>using namespace std;void encrypt(string *s,int…

Read More

Python program to find the binary equivalent of any decimal

This is a simple program in python to find the binary equivalent of any given decimal base number. This basically takes input as a decimal base number and coverts it into binary base and prints it. Sample Outputs: The Code: def bin(x): b=”” if(x==0): #The Binary equivalent of decimal 0 is 0 b=str(0) while(x>0): b=b+str(x%2) #Typecasting an Integer to String x=x/2 b=b[::-1] #Reverse the String print binp=input()bin(inp) Description:firstly input is taken from the keyboard and stored in inp variable. Then this variable is passed to bin() from where operations are…

Read More

Decimal to octal conversion

The following program takes a decimal number as an input and prints its octal equivalent. This program is implemented using c. Code: #include<stdio.h>int main(){ int n,a[100],i,j; printf(“Enter a decimal number : “); scanf(“%d”,&n); for (i=0;n!=0;i++) { a[i]=n%8; n=n/8; } printf(“The octal equivalent is : “); for (j=i-1;j>=0;j–) { printf(“%d”,a[j]); } return 0;} Output:

Read More