Quantcast
Channel: The Crazy Programmer
Viewing all 761 articles
Browse latest View live

Review of Stackify Retrace

$
0
0

Stackify Retrace is basically an Application Performance Management (APM) tool. It is one of the best APM tool available in the market.

What is APM?

As the name suggests an APM smoothens the development process of a software application by monitoring performance of the code, the dependencies on applications, tracing transactions, analyzing web performance or any other function related to improving the efficiency of the coded application.

For coders, it is requisite to own a reliable APM to examine the code, detect bugs in no-time, identifying the stack slowing the code down, effortlessly creating custom dashboards and monitoring all the other hindrances that needs to be eliminated or altered for developing a smooth application.

Stackify Retrace

Stackify Retrace - Application Performance Management (APM) Tool

Below are some features and usage of this AMP tool.

  • This APM is purely dedicated in monitoring codes of Java and .NET!
  • Provides transaction tracing at code-level with details information about the bug as shown in the image below.

Stackify Retrace 1

  • To simplify troubleshooting bugs, this app provides details of server and application logs. Windows Events, Web server logs, Syslog, and all application logs are supported by it.

Stackify Retrace 2

  • Switching between log statements and the complete transaction trace is extremely swift.

Stackify Retrace 3

  • Monitoring the full application or a single web page is possible; Satisfaction score, Requests per minute, HTTP error %, Avg Page Load time can be monitored.

Stackify Retrace 4

  • Stackify Retrace also offers alerts and notification scheme, by which you can also receive alerts through e-mails, SMS or slack.
  • Option for creating dashboards that can be custom designed by you and also be made public so that it is easy to share it with our mates and colleagues.

Stackify Retrace 5

  • You can create your own custom metrics as well by writing a small code; with Stackify Retrace analyzing Performance counters and mBeans has also been facilitated.

Stackify Retrace 7

  • Not only tracking errors has been simplified by this APM, but also all the details about the errors which include- ‘the reason why the error occurred? At what point it started? How often this error occurs?’ is provided by it.

Stackify Retrace 8

  • Identifying the slow parts of the stack is another feature that this APM provides.

Stackify Retrace 9

  • The monitoring performed is quick- 100/errors or 100/logs per minutes can be monitored.
  • Unlike other APM, the Stackify Retrace not only tells the problems in the code but also provide all kind of details associated with the problems and methods to solve those problems.

Where to Get it?

  • You can try this APM for free for a time-span of 14 days, download it from https://stackify.com/retrace/.
  • Two APM’s are available on the site – Retrace Dev/Test (suitable for Pre-pod box), Retrace Production (suitable for apps in production).
  • Retrace Dev/Test is available for $10/ month and Retrace Production is available for $25/month (single-core), $50/month (multi-core).

Tried the Stackify Retrace APM yet? The website assures that the users have rated this particular APM with a 5 star rating, take a free trial today and let us know your experience with this particular APM in the comment section below. Strengthen the performance of your application today and The Crazy Programmer wishes all the coder friends a very Happy Coding!

The post Review of Stackify Retrace appeared first on The Crazy Programmer.


Hamming Code in C and C++

$
0
0

Here you will get program for hamming code in C and C++.

Hamming code is a popular error detection and error correction method in data communication. Hamming code can only detect 2 bit error and correct a single bit error which means it is unable to correct burst errors if may occur while transmission of data.

Also Read: Checksum Program in C and C++

Hamming code uses redundant bits (extra bits) which are calculated according to the below formula:-

2r ≥ m+r+1

Where r is the number of redundant bits required and m is the number of data bits.

R is calculated by putting r = 1, 2, 3 … until the above equation becomes true.

R1 bit is appended at position 20

R2 bit is appended at position 21

R3 bit is appended at position 22 and so on.

These redundant bits are then added to the original data for the calculation of error at receiver’s end.

At receiver’s end with the help of even parity (generally) the erroneous bit position is identified and since data is in binary we take complement of the erroneous bit position to correct received data.

Respective index parity is calculated for r1, r2, r3, r4 and so on.

Hamming Code in C and C++

Image Source

Advantages of Hamming Code

  1. Easy to encode and decode data at both sender and receiver end.
  2. Easy to implement.

Disadvantages of Hamming Code

  1. Cannot correct burst errors.
  2. Redundant bits are also sent with the data therefore it requires more bandwidth to send the data.

Program for Hamming Code in C

#include<stdio.h>

void main() {
    int data[10];
    int dataatrec[10],c,c1,c2,c3,i;

    printf("Enter 4 bits of data one by one\n");
    scanf("%d",&data[0]);
    scanf("%d",&data[1]);
    scanf("%d",&data[2]);
    scanf("%d",&data[4]);

    //Calculation of even parity
    data[6]=data[0]^data[2]^data[4];
	data[5]=data[0]^data[1]^data[4];
	data[3]=data[0]^data[1]^data[2];

	printf("\nEncoded data is\n");
	for(i=0;i<7;i++)
        printf("%d",data[i]);

    printf("\n\nEnter received data bits one by one\n");
    for(i=0;i<7;i++)
        scanf("%d",&dataatrec[i]);

    c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0];
	c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0];
	c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0];
	c=c3*4+c2*2+c1 ;

    if(c==0) {
		printf("\nNo error while transmission of data\n");
    }
	else {
		printf("\nError on position %d",c);
    	
		printf("\nData sent : ");
        for(i=0;i<7;i++)
        	printf("%d",data[i]);
        
		printf("\nData received : ");
        for(i=0;i<7;i++)
        	printf("%d",dataatrec[i]);
		
		printf("\nCorrect message is\n");

		//if errorneous bit is 0 we complement it else vice versa
		if(dataatrec[7-c]==0)
			dataatrec[7-c]=1;
        else
			dataatrec[7-c]=0;
		
		for (i=0;i<7;i++) {
			printf("%d",dataatrec[i]);
		}
	}
}

Program for Hamming Code in C++

#include<iostream>

using namespace std;

int main() {
    int data[10];
    int dataatrec[10],c,c1,c2,c3,i;

    cout<<"Enter 4 bits of data one by one\n";
    cin>>data[0];
    cin>>data[1];
    cin>>data[2];
    cin>>data[4];

    //Calculation of even parity
    data[6]=data[0]^data[2]^data[4];
	data[5]=data[0]^data[1]^data[4];
	data[3]=data[0]^data[1]^data[2];

	cout<<"\nEncoded data is\n";
	for(i=0;i<7;i++)
        cout<<data[i];
    
	cout<<"\n\nEnter received data bits one by one\n";
    for(i=0;i<7;i++)
        cin>>dataatrec[i];

    c1=dataatrec[6]^dataatrec[4]^dataatrec[2]^dataatrec[0];
	c2=dataatrec[5]^dataatrec[4]^dataatrec[1]^dataatrec[0];
	c3=dataatrec[3]^dataatrec[2]^dataatrec[1]^dataatrec[0];
	c=c3*4+c2*2+c1 ;

    if(c==0) {
		cout<<"\nNo error while transmission of data\n";
    }
	else {
		cout<<"\nError on position "<<c;
		
		cout<<"\nData sent : ";
		for(i=0;i<7;i++)
        	cout<<data[i];
        
		cout<<"\nData received : ";
        for(i=0;i<7;i++)
        	cout<<dataatrec[i];
        
		cout<<"\nCorrect message is\n";
        
		//if errorneous bit is 0 we complement it else vice versa
		if(dataatrec[7-c]==0)
			dataatrec[7-c]=1;
        else
		 	dataatrec[7-c]=0;
		for (i=0;i<7;i++) {
			cout<<dataatrec[i];
		}
	}
	
	return 0;
}

Output

Enter 4 bits of data one by one
1
0
1
0

Encoded data is
1010010

Enter received data bits one by one
1
0
1
0
0
1
0

No error while transmission of data

Code Source: http://scanftree.com/programs/c/implementation-of-hamming-code/

This article is submitted by Rahul Maheshwari. You can connect with him on facebook.

Comment below if you have any queries related to above hamming code program in C and C++.

The post Hamming Code in C and C++ appeared first on The Crazy Programmer.

Movavi Screen Capture Studio – Easily Record and Edit Videos From Your Screen

$
0
0

Screen recording has become increasingly popular in recent years but its most visible use tends to still be in the how-to guides and tutorials involving digital products that you may have encountered. However having the ability to record videos from your screen can actually do much more than that, and you could use it to save webinars, online streaming videos, Skype calls, and so on.

Because of its versatility, it makes sense to have a screen recorder around that you can turn to if and when you need to capture any footage from your screen. That is precisely what Movavi Screen Capture Studio will do for you – with the added benefit of also having its very own built-in video editor so that you can tweak and improve your video after the fact.

Movavi Screen Capture Studio

Intuitive and Beginner-Friendly

If you’re worried about how difficult it will be to learn how to use Movavi Screen Capture Studio – there’s no need to be. Contrary to what you may expect it is an extremely intuitive software that prioritizes the user experience.

Part of Movavi Screen Capture Studio’s intuitive design is reflected in its clean and simple user interface that divides all its features into tabs that will let you easily navigate and find what you require. The other part is its controls that use common and familiar actions such as dragging elements into place, adjusting sliders, or just clicking the appropriate button.

In short you could be a complete beginner and still take full advantage of the features that Movavi Screen Capture Studio has to offer. The only thing that you’ll need is a bit of time and a willingness to experiment – and everything else will come almost naturally.

Comprehensive Features

Within Movavi Screen Capture Studio are numerous features that generally fall into two camps. The first will let you fully adjust and control the recording parameters and encompass areas such as defining the capture area, selecting the audio source, capturing keyboard and mouse actions, or setting the frame rate.

Despite the amount of control Movavi Screen Capture Studio provides, you may still want to edit your video after recording it. On that front you’ll also find a comprehensive set of features in its editor that will let you:

  • Split videos into segments to trim out unnecessary parts.
  • Merge video clips together and arrange the sequence in which they appear.
  • Improve the quality of your videos and fix common problems such as blurry, pixelated or interlaced footage.
  • Apply filters and special effects to transform and stylize the visual appearance of your videos.
  • Insert text elements and customize them to create unique captions, subtitles or watermarks.
  • Include background music or voiceovers by adding audio tracks to your video.

Honestly that is just the tip of the iceberg, but you should be starting to see how Movavi Screen Capture Studio will let you not only record footage from your screen, but also edit it to the exact shape and form that you require. Be sure to visit its homepage and see what it can do for yourself.

The post Movavi Screen Capture Studio – Easily Record and Edit Videos From Your Screen appeared first on The Crazy Programmer.

Difference between Preemptive and Non-Preemptive Scheduling in OS

$
0
0

Here you will learn about difference between preemptive and non-preemptive scheduling in os.

Preemptive Scheduling

Preemptive Scheduling means once a process started its execution, the currently running process can be paused for a short period of time to handle some other process of higher priority, it means we can preempt the control of CPU from one process to another if required.

A computer system implementing this supports multi-tasking as it gives the user impression that the user can work on multiple processes.

It is practical because if some process of higher priority is encountered then the current process can be paused to handle that process.

Examples:- SRTF, Priority, Round Robin, etc.

Non-Preemptive Scheduling

Non-Preemptive Scheduling means once a process starts its execution or the CPU is processing a specific process it cannot be halted or in other words we cannot preempt (take control) the CPU to some other process.

A computer system implementing this cannot support the execution of process in a multi task fashion. It executes all the processes in a sequential manner.

It is not practical as all processes are not of same priority and are not always known to the system in advance.

Examples:- FCFS, SJF, Priority, etc.

Difference between Preemptive and Non-Preemptive Scheduling in OS

Image Source

Difference between Preemptive and Non-Preemptive Scheduling in OS

Preemptive Scheduling Non-Preemptive Scheduling
Processor can be preempted to execute a different process in the middle of execution of any current process. Once Processor starts to execute a process it must finish it before executing the other. It cannot be paused in middle.
CPU utilization is more compared to Non-Preemptive Scheduling. CPU utilization is less compared to Preemptive Scheduling.
Waiting time and Response time is less. Waiting time and Response time is more.
The preemptive scheduling is prioritized. The highest priority process should always be the process that is currently utilized. When a process enters the state of running, the state of that process is not deleted from the scheduler until it finishes its service time.
If a high priority process frequently arrives in the ready queue, low priority process may starve. If a process with long burst time is running CPU, then another process with less CPU burst time may starve.
Preemptive scheduling is flexible. Non-preemptive scheduling is rigid.
Ex:- SRTF, Priority, Round Robin, etc. Ex:- FCFS, SJF, Priority, etc.

This article is submitted by Rahul Maheshwari. You can connect with him on facebook.

Comment below if you have any queries related to above tutorial for difference between preemptive and non-preemptive scheduling in os.

The post Difference between Preemptive and Non-Preemptive Scheduling in OS appeared first on The Crazy Programmer.

RSA Algorithm in C and C++ (Encryption and Decryption)

$
0
0

Here you will learn about RSA algorithm in C and C++.

RSA Algorithm is used to encrypt and decrypt data in modern computer systems and other electronic devices. RSA algorithm is an asymmetric cryptographic algorithm as it creates 2 different keys for the purpose of encryption and decryption. It is public key cryptography as one of the keys involved is made public. RSA stands for Ron Rivest, Adi Shamir and Leonard Adleman who first publicly described it in 1978.

RSA makes use of prime numbers (arbitrary large numbers) to function. The public key is made available publicly (means to everyone) and only the person having the private key with them can decrypt the original message.

RSA Algorithm Block Diagram

Image Source

Working of RSA Algorithm

RSA involves use of public and private key for its operation. The keys are generated using the following steps:-

  1. Two prime numbers are selected as p and q
  2. n = pq which is the modulus of both the keys.
  3. Calculate totient = (p-1)(q-1)
  4. Choose e such that e > 1 and coprime to totient which means gcd (e, totient) must be equal to 1, e is the public key
  5. Choose d such that it satisfies the equation de = 1 + k (totient), d is the private key not known to everyone.
  6. Cipher text is calculated using the equation c = m^e mod n where m is the message.
  7. With the help of c and d we decrypt message using equation m = c^d mod n where d is the private key.

Note: If we take the two prime numbers very large it enhances security but requires implementation of Exponentiation by squaring algorithm and square and multiply algorithm for effective encryption and decryption. For simplicity the program is designed with relatively small prime numbers.

Below is the implementation of this algorithm in C and C++.

Program for RSA Algorithm in C

//Program for RSA asymmetric cryptographic algorithm
//for demonstration values are relatively small compared to practical application

#include<stdio.h>
#include<math.h>

//to find gcd
int gcd(int a, int h)
{
    int temp;
    while(1)
    {
        temp = a%h;
        if(temp==0)
        return h;
        a = h;
        h = temp;
    }
}

int main()
{
    //2 random prime numbers
    double p = 3;
    double q = 7;
    double n=p*q;
    double count;
    double totient = (p-1)*(q-1);

    //public key
    //e stands for encrypt
    double e=2;

    //for checking co-prime which satisfies e>1
    while(e<totient){
    count = gcd(e,totient);
    if(count==1)
        break;
    else
        e++;
    }

    //private key
    //d stands for decrypt
    double d;

    //k can be any arbitrary value
    double k = 2;

    //choosing d such that it satisfies d*e = 1 + k * totient
    d = (1 + (k*totient))/e;
    double msg = 12;
    double c = pow(msg,e);
    double m = pow(c,d);
    c=fmod(c,n);
    m=fmod(m,n);

    printf("Message data = %lf",msg);
    printf("\np = %lf",p);
    printf("\nq = %lf",q);
    printf("\nn = pq = %lf",n);
    printf("\ntotient = %lf",totient);
    printf("\ne = %lf",e);
    printf("\nd = %lf",d);
    printf("\nEncrypted data = %lf",c);
    printf("\nOriginal Message Sent = %lf",m);

    return 0;
}

Program for RSA Algorithm in C++

//Program for RSA asymmetric cryptographic algorithm
//for demonstration values are relatively small compared to practical application

#include<iostream>
#include<math.h>

using namespace std;

//to find gcd
int gcd(int a, int h)
{
    int temp;
    while(1)
    {
        temp = a%h;
        if(temp==0)
        return h;
        a = h;
        h = temp;
    }
}

int main()
{
    //2 random prime numbers
    double p = 3;
    double q = 7;
    double n=p*q;
    double count;
    double totient = (p-1)*(q-1);

    //public key
    //e stands for encrypt
    double e=2;

    //for checking co-prime which satisfies e>1
    while(e<totient){
    count = gcd(e,totient);
    if(count==1)
        break;
    else
        e++;
    }

    //private key
    //d stands for decrypt
    double d;

    //k can be any arbitrary value
    double k = 2;

    //choosing d such that it satisfies d*e = 1 + k * totient
    d = (1 + (k*totient))/e;
    double msg = 12;
    double c = pow(msg,e);
    double m = pow(c,d);
    c=fmod(c,n);
    m=fmod(m,n);

    cout<<"Message data = "<<msg;
    cout<<"\n"<<"p = "<<p;
    cout<<"\n"<<"q = "<<q;
    cout<<"\n"<<"n = pq = "<<n;
    cout<<"\n"<<"totient = "<<totient;
    cout<<"\n"<<"e = "<<e;
    cout<<"\n"<<"d = "<<d;
    cout<<"\n"<<"Encrypted data = "<<c;
    cout<<"\n"<<"Original Message sent = "<<m;

    return 0;
}

Output

RSA Algorithm in C and C++ (Encryption and Decryption)

This article is submitted by Rahul Maheshwari. You can connect with him on facebook.

Comment below if you have any queries related to above program for rsa algorithm in C and C++.

The post RSA Algorithm in C and C++ (Encryption and Decryption) appeared first on The Crazy Programmer.

Why Array Indexing Starts with 0 in C?

$
0
0

Why array indexing starts with 0 in C, C++, Java and most of other programming languages is one of the common confusion among programmers.

In this article I will tell you the reason behind it.

Array in C

Image Source

Why Array Indexing Starts with 0 in C?

Lets try to understand this by taking one example in C. We can declare an array of size 5 in following way.

int a[5];

Here a itself is a pointer which contains the memory location of first element of the array.

Now for accessing the first element we will write a[0] which is internally decoded by compiler as *(a + 0).

In the same way the second element can be accessed by a[1] or *(a + 1). As a contains the address of first element so for accessing second element we have to add 1 to it. Thats why here we have written *(a +1).

Now lets assume that array indexing starts with 1 instead of 0. In this case for accessing the first element we have to write a[1] which is internally decoded as *(a + 1 – 1).

Observe here that we have to perform one extra operation i.e. subtraction by 1. This extra operation will greatly decrease the performance when the program is big.

Thats why to avoid this extra operation and improve the performance, array indexing starts with 0 in C, C++, Java, etc.

Comment below if you have any queries regarding above article. Do share it if you found this information valuable.

The post Why Array Indexing Starts with 0 in C? appeared first on The Crazy Programmer.

Operating System Interview Questions and Answers

$
0
0

Here you will get list of 60+ commonly asked operating system interview questions and answers. These os questions are helpful for freshers as well as experienced.

1. What is operating system?

Operating system can be defined as an interface between user’s program and hardware.

2. What is main purpose of operating system?

The main purpose of OS is to manage hardware and software resources and provides common services for our programs. It provides a suitable platform to execute our program (jobs).

3. What are different types of operating system?

There are generally two types of operating system which are as follows:

  1. Batch Operating System.
  2. Multiprogramming Operating System

Now this Multiprogramming Operating System can be broadly classified as:

  •  Multitasking Operating System
  • Multiprocessing Operating System
  • Real Time Operating System

4. What are different components of operating system?

The main components of operating system are:

  1. Kernel
  2. Process Management
  3. File System
  4. Memory Management
  5. I/O Management

Thus operating system is not an individual component but it has may sub components as stated above which makes our job easier.

5. What are the goals of OS?

Basically there are two goals of Operating System, those are:

  1. Primary : Convenience
  2. Secondary : Efficiency

6. Explain the different types of Operating System?

  • Batch Operating System:

In this type of Operating System all the jobs are submitted to computer at once and are executed in the order of submission without any preemption (means no job can be taken out until they complete).

  • Multiprogramming Operating System

It’s an extension of Batch OS where several jobs would be in the main memory at once and would be executed in some order for some specified amount of time.

Now we will look into its sub types:

  • Multi-tasking Operating System:

In this type of Operating System more than one task are executed simultaneously on a single processor machine. In fact there is a switching of CPU among the processes (jobs) at a very sharp pace that it seems to done parallel to the end user.

  • Multiprocessing Operating System:

It is the ability of an operating system to execute more than one process simultaneously on a multi-processor machine. In this, a computer uses more than one CPU at a time.

  • Real Time Operating System:

In such operating System there is a specified time allotted for each job. It’s useful in critical application like military, satellite etc.

7. What is kernel?

Kernel is the core part of the Operating System responsible for managing the communication between the software (user level applications) and the hardware (CPU, disk memory etc.). The main tasks of the kernel are:

  • Process management
  • Device management
  • Memory management
  • Interrupt handling
  • I/O communication
  • File system etc.

8. What are different types of kernel?

We have three important types of kernel named:

  • Monolithic Kernel:

It can be seen as a whole kernel that is full-fledged kernel, with all the services running.

Example: UNIX

  • Micro Kernel:

It is kernel with a limited services that is with some important services running.

Example: QNX-real time OS

  • Hybrid Kernel:

It combines the aspect of both monolithic as well as micro kernel.

Example: Microsoft NT kernel

9. What is user space and kernel space?

These are two important region of a memory.

User space: It is a region of memory where normal user processes run (i.e. everything other than Kernel).

Kernel space: It is a region of memory where code of kernel resides and executes. It is considered to be privileged part of a memory invoked by system calls. It is also known as System space.

10. What is process?

A running program is called as a process or it’s an active instance of program that is under execution.

A process is an entity created by Operating system to execute the program.

In Linux, we can use “ps” command to see running process.

Example: Any .exe in windows OS is a process like skype.exe etc

11. What are different type of process?

There are two types of process that is i) user space process and ii) Kernel space process.

12. What is difference between a program and a process?

A program is a set of instructions that are to perform a designated task, whereas the process is an operation which accepts the given instructions and perform the task as per the code, called ‘execution of instructions’.

Thus a program is a passive entity residing at secondary memory and a process is an active entity residing in the main memory.

13. Explain the different states of a process?

A process can go through following states in its lifecycle:

  • New:

This is the first state when a process is created or just started. It resides in secondary memory.

  • Ready:

This state signifies that the process is ready to be assigned to the processor that is ready to execute.

  • Running:

This state signifies that process has been given to the processor and its instruction are getting executed.

  • Waiting:

This state signifies that a process is waiting for some kind of resource or an event be it a user input or waiting for any file to become available.

  • Terminated:

The process can be terminated normally or abnormally.

Normal termination means that process has done with its complete execution whereas abnormal means that process has been terminated without completing its task.

Note: Any process has to go minimum four states (new->ready->running->terminated).

14. Which is the first process to be created by OS?

Init process is the first process to be created by OS. It provides the environment for the other process to be created later.

15. How are process identified?

Any process can be identified by a term called its id that is process id (pid).

16. What is fork ()?

Fork is a system call which is responsible for creating a copy of a current process. The current process is termed as parent process and the created process is termed as child process.

On success it returns pid of the child process to parents process and Zero is returned to child process.

17. What is system call?

It’s like a way by which any user level program ask for the services offered by a kernel.

It acts as an interface between a process and the operating system.

18. What is program counter?

It a pointer which points to the next instruction to be executed by a compiler.

19. What are the different attributes of a process?

Some of the important attributes of a process are:

  • Process id (pid)
  • Parent process id (PPid)
  • Process state
  • Scheduling parameter
  • Program counter and different registers.

This is also referred as context of a process.

20. What is Process control Block (PCB)?

It is like a data structure which hold all information (attributes) of a process.

21. What are different section of a process?

There is four important section of a process as stated below:

  • Stack: contains local variables ,returns address
  • Heap: Dynamically allocated memory via malloc, calloc,realloc
  • Data: contains global and the static variables
  • Code or text: contains code, program counter and content of processor’s register.

Note:

  • Stack and the Heap section are extendible that is stack can grow down and heap can grow up.
  • It is in the same order as mentioned above.

22. What is context switching?

It is switching of a processor from one process/thread to another. It is also called Task switch or process switch.

23. Qhat is inode?

Inode is a data structure which holds all the attributes of a file. It is also called index number.

Some of the attributes of file are:

  • File type
  • Permission
  • File size
  • Time when last it is modified

Note: Please while  reading thread concept, try to relate all this with process, thread will have its own, all those attributes as that of a process like its id(tid), scheduling parameter/policy etc. and  concept like context switching, different section etc. Thus try to relate all thread’s concept with that of a process.

24. What is thread?

Thread is a concurrent unit of execution within a process. A process can have multiple threads where each thread can perform a different task independently, thus increasing the efficiency of a process. A process always has one thread by default called main thread which is executed first.

Example:

  • Word processor, a background thread may check spelling and grammar while a foreground thread processes user input (keystrokes).
  • Web server – Multiple threads allow for multiple requests to be served simultaneously, without having to service requests sequentially.

25. State the benefits of a thread?

Some of the common advantages associated with threads are:

  • Responsiveness:

A process with thread are said to be more responsiveness than a process without thread because even if one thread is blocked or waiting for some resources the other thread still continue to function.

  • Lighter:

A thread is considered to be lighter than a process in terms of resource sharing and run time overhead. Most of the resource of a process are shared by all its thread making it lighter.

  • Throughput:

It improves the throughput of a multithreaded application, multiprocessor environment.

  • Economy:

Creating and managing thread is much faster (context switching is faster) than performing same task for processes.

26. State the disadvantages associated with thread?

  • Robustness:

It’s not as robust as process since if any one thread is terminated abnormally, it leads to entire process termination.

Thus many RTOS (Real Time Operating System) application uses processed over threads.

  • Increased Complexity

It is more complex than a process in terms of synchronization overhead.

27. What is difference between a process and a threads?

Process Thread
Process is used for heavyweight task Threads are used for small task(lightweight)
Processes are less responsive than threads Threads are more responsive than process
Processes are more robust than threads Threads are less robust
Each process will have its own address space. Threads are within a process thus share same address space(memory)
Processes have less synchronization overhead since all have separate address space(memory) Since they share same address space, synchronization is more overhead than process

28. What are different types of threads?

There are two types of threads:

  • User level thread : java thread
  • Kernel level thread: POSIX thread.

29. What is scheduler?

It is one of the component of kernel responsible for scheduling that is deciding when to run which process.

30. What are different types of scheduler?

There are three types of scheduler:

  • Long Term scheduler:

It is also called job scheduler responsible for selecting processes from queue (job pool/secondary memory) and loading them to main memory for execution.

  • Short term scheduler:

It is also called CPU scheduler responsible for selecting a process among processes that are ready to execute and allocate CPU to one of them.

This is nothing but a change of state of process from ready to running state. It is also called dispatcher.

  • Medium term scheduler:

It is also called swapper responsible for swapping a process from main memory to secondary memory in case if some high priority process needs to be given chance for execution.

It reduces the degree of multiprogramming (many processes in main memory).

31. What is preemptive and non-preemptive scheduling algorithm?

A scheduling algorithm is preemptive if, once a process has been given the CPU can take away. The strategy of allowing processes that are logically runnable to be temporarily suspended is called Preemptive Scheduling and allowing the process to run till completion is called non-preemptive scheduling.

32. What are different types of scheduling algorithm?

There are four different types of scheduler:

  • First come First serve(FCFS): First came process is served first
  • Round Robin(RR):Each process is given a quantum amount of time
  • Shortest job first(SJF):Process with lowest execution time is given first preference
  • Priority scheduling (ps): Priority value called (nice value) is used for selecting process. Its value is from 0 to 99. 0 being max and 99 being least.

33. What are different performance metric for scheduler?

There are five performance metric for scheduler, those are as follows:

  • CPU Utilization:

Percentage of time that the CPU is doing useful work (I.e. not being idle). 100% is perfect.

  • Wait time:

Average time a process spends for its turn to get executed.

  • Throughput:

Number of processes completed / time unit.

  • Response Time:

Average time elapsed from when process is submitted until useful output is obtained.

  • Turnaround Time:

Average time elapsed from when process is submitted to when it has completed.

34. What is daemon process?

A daemon process is one which runs at the background unlike the other foreground processes without the intervention of the user. It ends with “d”.

Example: crond is a daemon process in Linux operating system which is responsible for scheduling of an event like sending packets statistics at every 1 hours to server can be done with the help of crond daemon process.

35. What are different types of process in Linux?

There are three different types of process in Linux, those are:

  • Interactive-Foreground
  • Batch
  • Daemon-Background

36. What is deadlock?

A deadlock is a situation where two or more process or threads sharing the same resource are effectively preventing each other from accessing the resource. In simple terms the resource needed by one process/threads are being used by others and so on, thus none of the process can continue executing leading to deadlock.

37. What are the conditions required for deadlock to happen?

There are four conditions required for deadlock which are stated below

Mutual Exclusion: At least one resource is held in a non-sharable mode that is only one process at a time can use the resource. If another process requests that resource, the requesting process has to wait till it is released.

Hold and Wait: There must exist a process that is holding at least one resource and is waiting to acquire additional resources that are currently being held by other processes.

No Preemption: Resources cannot be preempted; that is, a resource can only be released after the process has completed its task.

Circular Wait: There must exist a set {p0, p1,…..pn} of waiting processes such that p0 is waiting for a resource which is held by p1, p1 is waiting for a resource which is held by p2,…, pn-1 is waiting for a resource which is held by pn and pn is waiting for a resource which is held by p0.

Note: All the four conditions mentioned above has to be satisfied for deadlock to happen.

38. What is race condition?

Race condition is an undesirable situation where two or more threads/process are trying to access and change the value of data shared by them and the outcome of the operation depends upon the order in which the execution happens.

Thus it lead to data inconsistency and loss of its value as both threads are racing to change/access the shared data.

Example:

Assume x =5;

Thread 1

x =x+1;

write x;

Thread 2

x=x+10;

write x;

Assume just before first write the first thread is suspended and control comes to second thread thus it increments the value of x by 10 and writes the value that is now x becomes 15.

In this case we can see that value of x depends upon the order in which the thread executes and the first value of x is lost that x=x+1=5+1=6. Thus there is clear inconsistency among the value of x because of race condition. Here x is the shared variable among both the threads upon which both are racing to access/update its value. To avoid such inconsistencies we need a proper synchronization mechanism like semaphore, mutex (discussed later)

39. What is Zombie process?

A zombie process also called defunct process is one which has completed its execution and is in terminated state but still has entry in the process table. It is denoted by “Z”. It shows that still the resources held by process are not freed upon termination.

It is dangerous because at one point of time system may run out of memory.

40. What is synchronization?

As the name suggest it means a proper co-ordination among processes while running in terms of resources. It means sharing system resources by a process in such a way that concurrent access to shared data is handled thereby minimising the chance of inconsistent data as we saw in Race condition.

41. What are different synchronization mechanism?

Some of the common synchronization mechanism are:

  • Semaphore
  • Mutex

42. What is semaphore?

Semaphore is one of the simplest synchronization mechanism used to control access to a common resource by multiple processes in a concurrent system such as a multiprogramming operating system.

It’s a variable with a value range between 0 to N where N = maximum resources -1;

43. What are different types of semaphore?

There are two types of semaphore, those are:

  • Binary Semaphore:

Semaphore which can have only two values either 0 or 1. It is also called Boolean semaphore controlling/protecting just one resource.

  • Counting Semaphore:

Semaphore whose value can be in the range of 0 to n where n =max -1; where max is nothing but the maximum resource.

When number of resources a semaphore protects is greater than 1, it’s called counting semaphore.

44. How is synchronization achieved by semaphore or What are different operations performed on semaphore variables?

There are two operations which are performed on semaphore which helps in synchronization, those are:

  • Wait:

If the semaphore value is not negative, decrement the value by 1.

  • Signal:

Increments the value of semaphore by 1.

For example:

Say the value of semaphore variable is initialized by 1 and if one process tries to use the shared variable, it decrements the value by 1 and access it. In the meantime if other process attempts to access it, it finds the semaphore variable 0 thus has to wait till the first process completes its task and increments the value back to 1.

Thus form the above explanation we can see that there is a proper synchronization (controlling one process form another) avoiding any race condition.

45. What is mutex?

Mutex is a locking mechanism which allows only one process to access the resource at a time.

It stands for mutual exclusion and ensure that only one process can enter the critical section at a time.

46. What is critical section of code?

As the name suggest it is that section or part of code which has variables or other resources which is being shared by two process, and if allowed to access may lead to race condition. To avoid this we need a mutex which ensures only one process can enter the critical section of code at a time.

47. Differentiate between semaphore and mutex?

Below stated are some important difference held between mutex and semaphore

                         Semaphore                               Mutex
It is a synchronization mechanism It is a locking mechanism
A Semaphore controls access to a shared pool of resources. It provides operations to Wait () until one of the resources in the pool becomes available, and Signal () when it is given back to the pool. A Mutex controls access to a single shared resource.
The other process can also the release the lock held by others The process which has acquired the lock can only release the lock

48. What do you mean by virtual memory?

Virtual memory is a memory management scheme used by operating system which allows a system to compensate for the shortage of physical memory.

Virtual address space is increased using active memory in RAM and inactive memory in hard disk drives (HDDs) to form contiguous addresses that hold both the application and its data.

49. What do you mean by logical and physical address?

Logical Address:

It can be defined as an address generated by CPU, later these addresses are mapped to physical address with the help of mechanism called paging (discussed later).

Physical Address:

It is nothing but the actual address that belongs to main memory where our program resides for execution.

50. What is paging?

The mapping from virtual to physical address is done by the memory management unit (MMU) which is a hardware device and this mapping is known as paging technique.

It ensures that the physical address of space to be non-contiguous. In this the virtual memory is divided into fixed size pages and the physical memory is divided into equal size called page frames.

51. What is the size of each page?

The size of page is 4k.

52. What is demand paging?

It is quite similar to a paging system with swapping where pages are loaded into main memory only on demand ,till then the processes resides in secondary memory.

For any process to execute, its pages are loaded into main memory, thus the entire page is not brought into main memory rather the pages are loaded only on demand not in advance. This is referred as demand paging.

Example:

We have a process responsible for database function like insert, query, delete and thus it should be understood that this process is divided into pages say one page for each function and at certain point of time, it needs to perform query so there is no point in loading the entire process (pages) rather just the page related to query function.

53. What is page fault?

As the name suggest, we are looking for certain page in main memory and it is not found, its termed as page fault else page hit.

54. What is page replacement algorithm and name it?

As above we have seen that there might be situation of page fault, in that case we need to bring that page from secondary memory to main memory but if there is no room for new page in the main memory, some page from the main memory has to be replaced with new page form secondary memory. This is called page replacement and one of the common algorithms is Least Recently Used (LRU) that is replace the page that has been unused for longest time.

55. What is cache?

Cache memory is a high speed memory in the CPU that is used for faster access to data. It provides the processor with the most frequently requested data

56. What is TLB?

It is a hardware cache responsible for speeding up the translation of logical address to physical address that is mapping between logical and physical address.

It contains the page table entries which is most recently used, thus before looking into main memory for page, TLB is searched if not found main memory lookup is done for required page.

57. What is fragmentation and state its types?

As we saw above that there is frequent swapping of page in and out form memory, the free space in main memory is broken into small pieces. It happens after sometime the processes cannot be allocated to memory blocks considering their small size and memory blocks remains unused. This problem is called fragmentation.

There are two types of fragmentation:

  • Internal fragmentation:

Memory block assigned to process is bigger. Some portion of memory is left unused, as it cannot be used by another process.

  • External fragmentation:

Total memory space is enough to satisfy a request or to reside a process in it, but they are  not contiguous, so it cannot be used.

58. What is IPC and state some of them?

IPC means inter process communication- process to process notification, process to process synchronization which allows a programmer to coordinate activities among different program processes that can run concurrently in an operating system

Some of the common IPC mechanism are:

  • Message Queue:

A queue of messages that is maintained between processes used for exchange for messages and other important information among processes.

  • Shared Memory:

In this memory (page) is shared among the processes in user space and one process can write into it and other can read.

  • Pipe:

A pipe is a technique for passing information from one program process to another. Basically, a pipe passes a parameter such as the output of one process to another process which accepts it as input.

Example:

ps –ef | grep “skype”

What it does that the output of “ps –ef” is given as an input to “grep” command with the help of pipe and “ps” is used in Linux to get the running process on system and “grep” is used for search.

  • Signal:

Signals come under IPC mechanisms that are used for notification – notification can be process to process – notification can be system to process.

Kill is the command by which one process can send a signal to other.

Syntax: kill <signal_name> <process_id>

Example:

1)  Kill SIGINT 1234

2) Kill SIGQUIT 1234

Each signal has its own number.

 Signal Name Signal Number Description
SIGINT 2 Issued if the user sends an interrupt signal (Ctrl + C)
SIGQUIT 3 Issued if the user sends a quit signal (Ctrl + D

59. State the purpose of a signal?

Signals serves two important purposes:

  • To make a process aware that a specific event has occurred
  • To force a process to execute a signal handler (customized/user) function included in user’s code.

60. What is interrupt?

An interrupt is a signal to the processor which can be generated by hardware or a software indicating an event that needs immediate attention. An interrupt indicates the processor to a high-priority condition requiring the interruption of the current task

61. What is starvation and aging?

Starvation:

Starvation is a resource management problem where a process is denied of resource or service for a long time or has been repeatedly denied services.

Aging:

This is a solution to starvation which involves gradually increasing the priority of processes that wait in the system for a long time.

The aging factor must increase the requests priority as time passes and must ensure that a request will eventually be the highest priority request (after it has waited long enough) and gets the chance to execute.

Note: It’s not same as deadlock.

Comment below if you have any queries related to above operating system interview questions and answers.

The post Operating System Interview Questions and Answers appeared first on The Crazy Programmer.

Difference between DBMS and RDBMS

$
0
0

In this tutorial you will learn about difference between dbms and rdbms with example.

DBMS

DBMS stands for Data Base Management System. This system is a computer software component introduced during 1960’s. It is a software that is used to store any type of data and it should provide easy manipulation of the data such as insertion, deletion, updation of the data. The data can be anything such as raw information about a person, company or it can be objects, for that purpose we use an object oriented DBMS or a Multimedia Database. DBMS has several components. Some of the major components are external interface, database language engine, query optimizer, database engine, storage engine, DBMS management component, etc.

RDBMS

RDBMS stands for Relational Database Management System. During 1970’s RDBMS or Relational database management system came into existence. It is a software which is used to store only that data which can be stored in the form of tables (also called relations). Data is managed and stored in rows and colums also known as tuples and attributes respectively. RDBMS can be thought of as an extension of DBMS inspite of the differences between them.

Every RDBMS is a DBMS, but the opposite is not true. For a DBMS to be termed as RDBMS it must satisfy atleast 6-7 rules out of the 12 rules defined by E.F Codd. Till date no RDBMS satisfies all the 12 rules.

Also Read: Difference between SQL and PL/SQL

Difference between DBMS and RDBMS

Image Source

Difference between DBMS and RDBMS

DBMS

RDBMS

A DBMS stores data in form of objects or in the form of files.

A RDBMS stores data in tables also called as relations.

Normalization is not possible in DBMS.

Normalization is possible in RDBMS.

Data is stored in hierarchial form generally.

Data is stored independently but are related through some constraints.

No use of constraints on the data stored.

To ensure data integrity and security several constraints are used.

No relationship with the data stored.

Data are related to each other.

Follows no specific properties for data security while manipulating the data

Follows ACID (Atomicity,Consistency,Integrity,Durability) properties for data security.

No support for Distributed Databases.

Supports Distributed Databases.

DBMS deals with small data and generally supports single user.

RDBMS deals with large data and generally supports multiple user.

Examples:- file systems,xml,etc.

Examples:- mysql, sql server, oracle etc.

The post Difference between DBMS and RDBMS appeared first on The Crazy Programmer.


4 Free ASP.NET Hosting Websites

$
0
0

Here you will know about some best and free asp.net hosting websites.

Are you a student or developer? Do you have ASP.NET website? Want to test your ASP.NET project online? Want to host ASP.Net and SQL databases for free? Then this article might helpful for you. We will see some free Windows Server OS based web hosting services. Basically applications like ASP.NET, MSSQL, MS Access, etc requires windows server OS to run the websites. This is the main difference between Windows and Linux based hosting sites. So let’s start.

Also Read: 5 Best Java Web Hosting Companies in India

4 Free ASP.NET Hosting Websites

4 Free ASP.NET Hosting Websites

1. SOMEE.COM

Somme.com provides free windows ASP.Net hosting on Windows 2012 or Windows 2003. The registration is absolutely free and does not require credit card information to complete registration. Somee.com provides only 1 website to host free of cost. They also provides FTP to transfer your web files by using of free ftp clients.

FEATURES:

  • Storage capacity: 150MB
  • Transfer rate: 5GB/Month
  • Free Subsomain
  • IIS 8.0/7.5/6.0
  • ASP.Net 4.5/ 4.0/3.5/2.0/ 1.1
  • AJAX 3.5/1.0
  • MVC 1.0/2.0/3.0/4.0
  • Silverlight
  • Databases: MS Access 2003, 2007/MS SQL Express 2012, 2008R2
  • MS SQL databases size: 15MB
  • MS SQL log size: 20MB
  • Backup storage size: 40MB

DISADVANTAGES:

  • Some what low storage capability.
  • Forced advertising (You will see advertising on your hosted website.)
  • Low database storage size.

2. MYWINDOWSHOSTING.COM

Mywindowshosting.com web hosting service for 60 Days free trail for your ASP.Net website. After free 60 days trail period you have buy or upgrade to their paid hosting plans. Registration is free and no credit card information is needed for activation. They believes in try it before buy it. You will get free support for your trail period from mywindowshosting.com. You can use this web hosting site for your small web based project for testing.

FEATURES:

  • Storage Capacity: 1GB
  • Number of Site/IIS Entry: 1
  • Domain Names Hosted: 1
  • Bandwidth: 10GB
  • 1 FTP Account
  • Windows Sever OS: 2012/2008
  • MS Access Database
  • MS SQL Database: 2012/2008/2005
  • ASP.Net: 4.5/4.0/3.5/2.5
  • Firewall, Anti Virus and Daily Backup
  • 24X7 Technical Support
  • No Advertisements

DISADVANTAGES:

  • Only 60 Days free trail subscription

3. ASPSPIDER.COM

AspSpider.com offers web hosting for educational purpose at no cost. You can use their hosting services to create ASP.NET websites and give demonstrations to your manager or client without spending any money. The service is purely for learning and educational purpose and absolutely no commercial sites are allowed except for demo purpose.Registration is fairly simple and no credit card is required.

FEATURES:

  • ASP.NET 4.0/3.5/2.0
  • No Advertising
  • MS SQL Server 2008/ 2005 Express Edition
  • MS Access support
  • 100 MB Disk Space
  • 2 GB Monthly Data Transfer

Disadvantages:

  • Low storage space
  • No ASP.Net 4.5 Support
  • Low monthly transfer rate
  • No FTP support

4. ASPHOST4FREE.COM

AspHost4Free.com provides free web hosting service for your ASP.Net and MS Access database. Registration is free and no credit card information is needed. Let’s look at the features and disadvantages.

FEATURES:

  • 100MB Disk Space
  • No Advertising for limited time
  • FTP Support
  • Unlimited Bandwidth
  • Technical Support via E-mail
  • MS Access Database
  • Standard ASP Scripts

Disadvantages:

  • Low Disk Space
  • No MS SQL Database (You have to compromised with MS Access database)
  • Ads will displayed after limited time is over.

This article is submitted by Abhishek. He is a web geek & editor at geeksgyaan.

Comment below if you know about any other free asp.net hosting site. I would love to add it in this list.

The post 4 Free ASP.NET Hosting Websites appeared first on The Crazy Programmer.

How Social Media and Big Data will Unleash What We Know

$
0
0

Social media is getting bigger and bigger to the point that today, it will provide more information in days than what the entire world had mere decades ago. Understanding it and figuring out how to use it for your business is essential and, as the workload increases, it will require newer and newer technological advances and ideas.

As the data scientist consultants from ActiveWizards explain, following the growth of social media is of great value to those who are willing to learn and use social networks to get financial gain. However, this is no secret and the competition is ever improving, so the one with the best understanding and adaptability will most likely be the one to get ahead.

How Social Media and Big Data will Unleash What We Know

Image Source

Every year, the developers have to put in extra hours to advance their technology in order to get insight and context from interactions happening on social media websites. The reason is simple; there are millions upon millions of conversations happening daily out in the open. Every time someone comments, shares, replies to a comment, or even likes something online, they actually create the conditions needed for a conversation thread to start, and that means data that can be used to improve your services or; at least, to improve on your sales tactics. Of course, social media brings up a whole new slew of questions regarding the privacy and legality of using data acquired this way, but the fact is that most of these conversations take place in the open and not in private messages.

Now, a person is simply not capable of analyzing the information that is put in; the language that is used is natural, the sentences are not always (if ever) properly constructed, and the amount of information is insurmountable for any mortal. So, the actual use of this information requires technologies that are still being developed. That technology does not only need to be powerful enough to handle the size, complexity, and speed of the input, it also needs to do that in a way that is cost effective.

The intriguing part of the entire story about online comments is that they are permanent. Whatever someone writes down without even thinking about it is stored for what is possibly an eternity. This is valuable information because not only does it make it possible to investigate the market and get precise statistical information, but it will also allow for historical tracking of trends.

This is where big data steps in. It provides new ways of approaching this issue and it is showing promise in regards to being able to adapt to the incredible growth of social media. Another big issue today is trying to follow the trends and, when that does not work as well as intended, trying to get ahead of them. In order to be really successful, you need to know what will happen before it does and, in order to do that, you must first know what to ask for. Big data actually helps with that as well. Some tools are actually smart enough to recognize these patterns and offer knowledge you might need before you even realize it.

Nevertheless, big data still needs to grow and these are the things it is likely to develop:

1. Apps that plug directly into social networks for both the consumer and enterprises alike.

Big data is the only thing, well, big enough to actually approach this information as it is happening. More and more social networks include third-party software to be used as analytic programs. What big data offers is the possibility of getting a full report of queries, trends, and insights that would help you improve your business.

2. Interconnections

The Internet is probably the main method of communication in the twenty-first century. This means that now, almost every subject around actually has a public forum for it to be discussed. This will lead to more and more connections between consumers and enterprises. If a company is to succeed in the future, it should include the capabilities to follow both of these.

3. Spying concerns

Even now, a lot of consumers online are worried about big companies and governments spying on them and illegally acquiring information regarding their behavior. It is rather important to be able to put those worries at ease and grow your work without the brand of being the “Big Brother” for your clients.

The post How Social Media and Big Data will Unleash What We Know appeared first on The Crazy Programmer.

Python Program to Add Two Numbers

$
0
0

Here you will get python program to add two numbers.

The program will first ask user to enter two numbers, calculate their sum and finally print it.

input() is an inbuilt function which is used to take input from user.

Python Program to Add Two Numbers

a = input("enter first number: ")
b = input("enter second number: ")

sum = a + b

print "sum:", sum

Output

enter first number:5
enter second number:7
sum: 12

The post Python Program to Add Two Numbers appeared first on The Crazy Programmer.

Python Program to Swap Two Numbers

$
0
0

Here you will get python program to swap two numbers with and without using temporary variable.

Python Program to Swap Two Numbers Using Temporary Variable

a = 10
b = 20

print "before swapping\na=", a, " b=", b

temp = a
a = b
b = temp

print "\nafter swapping\na=", a, " b=", b

Output

before swapping
a= 10 b= 20

after swapping
a= 20 b= 10

Python Program to Swap Two Numbers Without Using Temporary Variable

Method 1:

Python provides a way to directly swap two number without temporary variable. It can be done in following way.

a, b = b, a

Method 2:

In this method we can use addition and subtraction operators.

a = a + b
b = a - b
a = a - b

Method 3:

We can also swap numbers using multiplication and division operator in following way.

a = a * b
b = a / b
a = a / b

This method will not work when one of the number is 0.

Method 4:

It is another method in which we use bitwise xor operator.

a = a ^ b
b = a ^ b
a = a ^ b

Comment below if you have queries or know any other way to swap numbers in python.

The post Python Program to Swap Two Numbers appeared first on The Crazy Programmer.

How to Run C and C++ Program in Sublime Text

$
0
0

In this tutorial you will learn how to run C and C++ program in sublime text on windows.

It is a very popular and widely used text editor by programmers and developers. Just follow below steps to configure sublime text to compile and run C and C++ programs. I have tested the steps in sublime text 3 but I am sure it will work for any other version also.

Also Read: Configure Notepad++ to Run C, C++ and Java Programs

How to Run C and C++ Programs in Sublime Text

How to Run C and C++ Program in Sublime Text

Here I consider that you have installed GCC compiler on your system.

Part 1: Adding Path in Environment Variables

1. Copy the path of bin folder of GCC compiler. In my case the path looks like as shown below, it may be different in your case.

C:\Program Files (x86)\CodeBlocks\MinGW\bin

2. Now right click on Computer and select Properties. Then click on Advance system settings and after that click on Environment Variables.

3. In the next window under System variables find a variable with name Path. Select it and click on Edit button.

4. In Variable value text field go to end and then type semicolon and then paste the path of bin folder that you copied. See below screenshot.

How to Run C and C++ Programs in Sublime Text

5. Finally click on all OK buttons to save the settings.

Part 2: Configuring Sublime Text

Open sublime text and go to Tools > Build System > New Build System and then paste the following lines in it.

For C:

{
"shell_cmd" : "gcc $file_name -o ${file_base_name}",
"working_dir" : "$file_path",

"variants":
[
	{
		"name": "Run",
		"shell_cmd": "gcc $file_name -o ${file_base_name} && ${file_path}/${file_base_name}"
	}
]
}

Press ctrl+s and then save it with file name C_RUN.

For C++:

{
"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",

"variants":
[
	{
		"name": "Run",
		"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
	}
]
}

Press ctrl+s and then save it with file name CPP_RUN.

For running a program go to Tools > Build With and then select C_RUN – Run or CPP_RUN – Run according to the language you are using.

Video Tutorial

If you have any query then ask in comment section, I will try to solve it.

The post How to Run C and C++ Program in Sublime Text appeared first on The Crazy Programmer.

Python Program to Find Largest Among Three Numbers

$
0
0

Here you will get python program to find largest number among three numbers.

The program will ask user to input three numbers and then print greatest among them.

print("enter three numbers:")

a = int(input())
b = int(input())
c = int(input())

if a>b and a>c:
	print(a, " is largest")
elif b>a and b>c:
	print(b, " is largest")
else:
	print(c, " is largest")

Output

enter three numbers:
12
7
9
12 is largest

The post Python Program to Find Largest Among Three Numbers appeared first on The Crazy Programmer.

How to Run Python Program in Sublime Text

$
0
0

In this tutorial you will learn how to run python program in sublime text in windows.

Just follow below steps to configure sublime text. The whole process is divided into two parts.

Part 1: Setting Path

First of all you have to set the path of python installation directory in environment variable. You can skip this step if it is already done.

1. Copy the path of python installation directory. In my case it looks like as shown below.

C:\Users\TCP\AppData\Local\Programs\Python\Python36-32

Note: Here TCP is the user name of my computer. It will be different in your case.

2. Now right click on Computer and click on Properties option. Then select Advance system settings in left sidebar.

3. Now click on Environment Variables and then under System variables select variable with name Path.

4. Click Edit button and then in Variable value field go to end and type semicolon and then paste the path of python directory that you copied. See below screenshot.

How to Run Python Program in Sublime Text 1

5. Finally click on all OK buttons to save the settings.

Part 2: Install SublimeREPL Plugin

For taking input from user in sublime text we need a plugin named as SublimeREPL. So follow below steps to install it.

1. Go to below link and copy the code according to your sublime text version.

https://packagecontrol.io/installation

How to Run Python Program in Sublime Text 2

2. Open sublime and go to View > Show Console. Then in console box at bottom paste the code that you have just copied and press enter. Wait for few seconds, it will install required packages.

How to Run Python Program in Sublime Text 3

3. Then go to Preferences > Package Control > Package Control: Install Package.

How to Run Python Program in Sublime Text 4

4. In textbox type SublimeREPL and select it to install the plugin. After installation restart sublime text.

How to Run Python Program in Sublime Text 5

5. Now got to Tools > Build System > New Build System. A new file will open, just paste the following code in it.

{
    "target": "run_existing_window_command", 
    "id": "repl_python_run",
    "file": "config/Python/Main.sublime-menu"
}

6. Press ctrl + s and save it with file name Python_RUN.

7. Go to Tools > Build System and select Python_RUN as build system or you can use ctrl + b as shortcut.

How to Run Python Program in Sublime Text 6

8. For running a python program go to Tools > Build.

Video Tutorial

Comment below if you are facing any problem to run python program in sublime text.

The post How to Run Python Program in Sublime Text appeared first on The Crazy Programmer.


iSkysoft iMedia Converter Deluxe

$
0
0

iSkysoft iMedia Converter Deluxe is basically a video converter that can change the state of a video. In simpler terms can convert a video/audio in any format, edit them, download online streaming videos, and burn DVDs.

Features offered by iSkysoft iMedia Converter Deluxe

Converting Audios/Videos in Any Format

  • The iSkysoft iMedia Converter Deluxe supports more than 150 formats and with each free upgradation of the application, more formats are added for absolutely no charge.
  • This Video Converter is compatible with each device and also doesn’t degrade the quality of the video, which means a HD video remains a HD video.

iSkysoft iMedia Converter Deluxe

Image Source

Various Formats Offered

1. Video Formats

  • Output Formats
    • Std. Video Formats: WMV, AVI, MOV, MP4, M4V, DV, MPEG-1, VOB, MPEG-2, DivX, MKV 3GP, 3G2, ASF, MXF,MPEG-1 SECAM, MPEG-2 NTSC, , MPEG-1 NTSC, MPEG-1 PAL, MPEG-2 PAL, DVD-Video PAL, MPEG-2 SECAM, DVD-Video NTSC, DVD-Video SECAM, etc.
    • 3D and HD Video Formats: HD MKV, HD M4V, HD TS, HD MOV, HD MP4, HD MPEG, HD TRP, 3D MP4, 3D MKV, 3D, 4K MKV, 4K MOV, YouTube, 3D MOV etc.
    • Online Videos From: Youtube Video, Facebook Video, Vimeo, VEVO, FLV, F4V, SWF.
    • DRM Video Formats: BBC iPlayer WMV/MP4, iTunes M4V/M4P
  • Input Formats
    • Std. Video Formats: ASF, MPG, MPEG-1, MPEG-2, MOV(QuickTime), MP4, AVI(XviD), 3GP, 3GPP, MKV , TP, TRP, WMV (Windows Media Video),FLV (Flash Video), RM, RMVB, MXF, OGV, VRO, TS (MPEG-2), VOB, DivX, WebM etc.
    • HD Video Formats: HD WMV (VC-1), HD MOV (MPEG-4, H.264), MTS (AVCHD, H.264), HD TOD (MPEG-2), HD MKV (H.264, MPEG-2), M2TS (AVCHD, H.264)etc.
    • Online Video: Youtube Video, Facebook Video, FLV, Vimeo, VEVO, SWF, F4V, WebM.
    • DRM Video Formats: BBC iPlayer WMV/MP4.iTunes M4V/M4P
    • Image: BMP, PNG, JPEG, GIF

2. Audio Formats

M4A, AC3, WAV, MP3, AAC, M4R, AAC, OGG, FLAC, CAF, SD2, APE, MKA, AU, AIFF, APE, etc.

3. DVD Formats

DVD disc, ISO, DVD Files (VIDEO_TS Folders, dvdmedia)

4. Device Formats

  • Apple: All the iPhones, iPad Pro, iPad Air, iPad mini, Apple Generic, Apple TV 2, Apple TV 3, Apple TV, iPod
  • Other Devices: Samsung, HTC, Motorola, Nokia, Blackberry, PSP, LG, Sony, VR, ARCHOS, other Android devices.

Recording and Downloading Videos

iSkysoft iMedia Converter Deluxe provides 2 ways of downloading online videos, also after downloading the video converting the video format option is also available.

The Video Recording option is only available in the Windows Version and not in the Mac Version.

iSkysoft iMedia Converter Deluxe

DVD Solution

iSkysoft iMedia Converter Deluxe is the Best Video Converter for Mac and Windows as it offers all the DVD solutions like Converting formats, Editing Videos with built-in tools, Burning DVDs, Creating DVDs and Backing up the data of DVD.

iSkysoft iMedia Converter Deluxe

Editing Videos

One can easily edit a video with the editing tools offered by iSkysoft Media Converter Deluxe! Crop, Rotate, Merge, Trim and Metadata can be done to the video and also Subtitles, Watermarks can be added to it and the level of Brightness, Saturation, Warmth, & Volume can also be adjusted.

iSkysoft iMedia Converter Deluxe

Screenshot Option

You can also take a screenshot of the video easily through this application.

iSkysoft iMedia Converter Deluxe

I suggest you to try iSkysoft iMedia Converter Deluxe as according to me this is one of the Best Video Converter for Mac and Android offering all the required features.

Download the Windows version of iSkysoft iMedia Converter Deluxe from:

https://videoconverter.iskysoft.com/video-converter-deluxe-windows.html

Download the Mac version of iSkysoft iMedia Converter Deluxe from:

https://videoconverter.iskysoft.com/video-converter-deluxe-windows.html

Use the tool and share your thoughts about it in comment section below.

The post iSkysoft iMedia Converter Deluxe appeared first on The Crazy Programmer.

Python Program to Check Leap Year

$
0
0

Here you will get python program to check leap year.

A normal year contains 366 days while a leap year contains 365 years.

If the year is divisible by 4 then it is leap year except the century years (year that have 00 in end). A century year is leap year only if it is not divisible by 100 but divisible by 400.

For example 2000, 2016 are leap year while 2002, 2017 are not leap year.

Below program ask user to input a year and then check it is leap year or not.

Python Program to Check Leap Year

year = int(input("enter a year: "))

if(year%4==0 and (year%100!=0 or year%400==0)):
	print("leap year")
else:
	print("not leap year")

Output

enter a year: 2016
leap year

Comment below if you have any queries related to above leap year program in python.

The post Python Program to Check Leap Year appeared first on The Crazy Programmer.

Python Program to Check Number is Odd or Even

$
0
0

Here you will get python program to check number is odd or even.

A number is even if it is completely divisible by 2 otherwise it is odd.

The modulus operator % is used to find remainder of any number. So here we will use it to divide a number by 2 and find the remainder. If remainder is 0 then number is even otherwise odd.

Python Program to Check Number is Odd or Even

num = int(input("enter a number: "))

if(num%2 == 0):
	print("number is even")
else:
	print("number is odd")

Output

enter a number: 11
number is odd

Comment below if you have any queries related to above python odd even program.

The post Python Program to Check Number is Odd or Even appeared first on The Crazy Programmer.

Bisection Method in C and C++

$
0
0

In this tutorial you will get program for bisection method in C and C++.

To find a root very accurately Bisection Method is used in Mathematics. Bisection method algorithm is very easy to program and it always converges which means it always finds root.

Bisection Method repeatedly bisects an interval and then selects a subinterval in which root lies. It is a very simple and robust method but slower than other methods.

It is also called Interval halving, binary search method and dichotomy method.

Bisection Method calculates the root by first calculating the mid point of the given interval end points.

Bisection Method in C and C++

Image Source

Bisection Method Procedure

The input for the method is a continuous function f, an interval [a, b], and the function values f(a) and f(b). The function values are of opposite sign (there is at least one zero crossing within the interval). Each iteration performs these steps:

1. Calculate the midpoint c = (a + b)/2

2. Calculate the function value at the midpoint, function(c).

3. If convergence is satisfactory (that is, a – c is sufficiently small, or f(c) is sufficiently small), return c and stop iterating.

4. Examine the sign of f(c) and replace either (a, f(a)) or (b, f(b)) with (c, f(c)) so that there is a zero crossing within the new interval.

Pros and Cons

Advantage of the bisection method is that it is guaranteed to be converged and very easy to implement.

Disadvantage of bisection method is that it cannot detect multiple roots and is slower compared to other methods of calculating the roots.

Program for Bisection Method in C

#include<stdio.h>

//function used is x^3-2x^2+3
double func(double x)
{
    return x*x*x - 2*x*x + 3;
}

double e=0.01;
double c;

void bisection(double a,double b)
{
    if(func(a) * func(b) >= 0)
    {
        printf("Incorrect a and b");
        return;
    }

    c = a;

    while ((b-a) >= e)
    {
        c = (a+b)/2;
        if (func(c) == 0.0){
            printf("Root = %lf\n",c);
            break;
        }
        else if (func(c)*func(a) < 0){
                printf("Root = %lf\n",c);
                b = c;
        }
        else{
                printf("Root = %lf\n",c);
                a = c;
        }
    }
}

int main()
{
    double a,b;
    a=-10;
    b=20;

    printf("The function used is x^3-2x^2+3\n");
    printf("a = %lf\n",a);
    printf("b = %lf\n",b);
    bisection(a,b);
    printf("\n");
    printf("Accurate Root calculated is = %lf\n",c);

    return 0;
}

Output

a = -10.000000
b = 20.000000
Root = 5.000000
Root = -2.500000
Root = 1.250000
Root = -0.625000
Root = -1.562500
Root = -1.093750
Root = -0.859375
Root = -0.976563
Root = -1.035156
Root = -1.005859
Root = -0.991211
Root = -0.998535

Accurate Root calculated is = -0.998535

Program for Bisection Method in C++

#include<iostream>

using namespace std;

//function used is x^3-2x^2+3
double func(double x)
{
    return x*x*x - 2*x*x + 3;
}

double e=0.01;
double c;

void bisection(double a,double b)
{
    if(func(a) * func(b) >= 0)
    {
        cout<<"Incorrect a and b";
        return;
    }

    c = a;

    while ((b-a) >= e)
    {
        c = (a+b)/2;
        if (func(c) == 0.0){
            cout << "Root = " << c<<endl;
            break;
        }
        else if (func(c)*func(a) < 0){
                cout << "Root = " << c<<endl;
                b = c;
        }
        else{
                cout << "Root = " << c<<endl;
                a = c;
        }
    }
}

int main()
{
    double a,b;
    a=-10;
    b=20;

    cout<<"The function used is x^3-2x^2+3\n";
    cout<<"a = "<<a<<endl;
    cout<<"b = "<<b<<endl;
    bisection(a,b);
    cout<<"\n";
    cout<<"Accurate Root calculated is = "<<c<<endl;

    return 0;
}

This article is submitted by Rahul Maheshwari. You can connect with him on facebook.

Comment below if you have any queries regarding above program for bisection method in C and C++.

The post Bisection Method in C and C++ appeared first on The Crazy Programmer.

Python Program to Find Factorial of Number Using Loop

$
0
0

Here you will get python program to find factorial of number using for and while loop.

Factorial of a number is calculated by multiplying it with all the numbers below it starting from 1.

For example factorial of 4 is 24 (1 x 2 x 3 x 4).

Below program takes a number from user as an input and find its factorial.

Python Program to Find Factorial of Number

Using For Loop

num = int(input("enter a number: "))

fac = 1

for i in range(1, num + 1):
	fac = fac * i

print("factorial of ", num, " is ", fac)

Output

enter a number: 5
factorial of 5 is 120

Using While Loop

num = int(input("enter a number: "))

fac = 1
i = 1

while i <= num:
	fac = fac * i
	i = i + 1

print("factorial of ", num, " is ", fac)

Output

enter a number: 4
factorial of 4 is 24

Comment below if you have any queries related to above python factorial program.

The post Python Program to Find Factorial of Number Using Loop appeared first on The Crazy Programmer.

Viewing all 761 articles
Browse latest View live