This is a post in which you will get the basic knowledge about the parallel programming concept. In this post we going to use the OpenMP model. This program is implemented in the C Language. Basically this programs demonstrates how the thread gets executed in different Cores of the processor. In this case, this program is executed in a Quad Core CPU, so it displays 4 threads from 0-3. Screenshots[Demo] Here the threads are executed randomly on each cores on the basics of their availability. This method by which threads…
Read MoreMonth: August 2015
Hackerrank Caeser Cipher Solution
The below program is the solution of Caeser Cipher in implementation domain. You can get the program HERE. Output : Code : #include<iostream>using namespace std;int main(){ int x,t,m; cin>>x; string s; cin>>s; cin>>t; while(t>26) { t=t-26; } for(int i=0;i<s.length();i++) { m=s[i]+t; if(islower(s[i])) { if(m>122) { m=m-122; m+=96; } } else if(isupper(s[i])) { if(m>90) { m=m-90; m+=64; } } //cout<<m; if(isalpha(s[i])) cout<<(char)m; else cout<<s[i]; } return 0;} Bikash Narayan PandaDeveloper, Tinkere, a proud Dad.. love to spend my available time playing with Tech!! wglabz.in
Read MoreNon Restoring Division Algorithm Implementation in C
This is a Dynamic program for the implementation of the NON RESTORING Division Algorithm in C Language. Non 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–)…
Read MoreBinary Multiplication 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 multiplied by repetitive addition and the result is then displayed in the console !Binary Multiplication is highly necessary because computer only understands the addition. In case of multiplication it’s repetitive addition. 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 bin(int n, int arr[]){ int r, i = 0; do{ r = n % 2; n /= 2; arr[i] = r; i++;…
Read MoreShuffle 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 MoreBinary 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 MoreSort 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 MoreEncryption 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