Posts

Data Representation in Computer

Image
How Computers Represent Data All symbols, pictures, or words must be reduced to a string of binary digits. A binary digit is called a bit and represents either a 0 or a 1. These are the only digits in the binary or base 2, number system used by computers. A string of eight bits used to store one number or character in a computer system is called a byte. One byte for character A 01000001 The computer representation in ASCII for the name Alice is 01000001 = A 01001100 = L 01001001 = I 01000011 = C 01000101 = E To represent the numbers 0 through 9 and the letters  a  through  z  and  A  through  Z , computer designers have created coding systems consisting of several hundred standard codes. In one code, for instance, the binary number 01000001 stands for the letter  A . Two common coding systems are Extended Binary Coded Decimal Interchange Code (EBCDIC) and American Standard Code for Information Interchange (ASCII). EBCDIC represents every number, alphabetic character, or spe

C++ Program to Represent the Graph Using Adjacency Matrix | C++ Programming

Image
 C++ Program to Represent the Graph Using Adjacency Matrix #include <iostream> #include <iomanip> using namespace std ; // A function to print the adjacency matrix. void PrintMat ( int mat [][ 20 ], int n ) {     int i , j ;     cout << " \n\n "          << setw ( 4 ) << "" ;     for ( i = 0 ; i < n ; i ++)         cout << setw ( 3 ) << "(" << i + 1 << ")" ;     cout << " \n\n " ;     // Print 1 if the corresponding vertexes are connected otherwise 0.     for ( i = 0 ; i < n ; i ++)     {         cout << setw ( 3 ) << "(" << i + 1 << ")" ;         for ( j = 0 ; j < n ; j ++)         {             cout << setw ( 4 ) << mat [ i ][ j ];         }         cout << " \n\n " ;     } } int main () {     int i , j , v ;     cout << "Enter the number of vertexes: " ;

Expression, Statements and Comments in C Programming | C Programming

Image
Expression, Statements, and Comments in C Programming  Arithmetic C Expressions in C Programming An expression is a combination of variables constants and operators written according to the syntax of the C language. In C every expression evaluates to a value i.e., every expression results in some value of a certain type that can be assigned to a variable. Some examples of C expressions are shown in the table given below. Algebraic C Expression in C programming Expression a x b - ca * b – c (m + n) (x + y) (m + n) * (x + y) (ab / c)a * b / c 3x2 +2x + 13*x*x+2*x+1 (x / y) + cx / y + c Evaluation of Expressions in C Programming Expressions are evaluated using an assignment statement of the form Variable = expression; Variable is any valid C variable name. When the statement is encountered, the expression is evaluated first and then replaces the previous value of the variable on the left-hand side. All variables used in the expression must be assigned values before evaluation

Fractional Knapsack Problem | DAA

Image
Fractional Knapsack Problem A thief has a bag or knapsack that can contain the maximum weight W of his loot. There are n items and the weight of an ith item is wi and it worth vi. Any amount of item can be put into the bag i.e. xi fraction of item can be collected, where 0<=xi<=1. Here the objective is to collect the items that maximize the total profit earned. Here we arrange the items by ratio vi/wi. Algorithm GreedyFracKnapsack (W, n) {     for (i = 1 ; i <= n; i++)     {         x [i] = 0.0 ;     }     tempW = W;     for (i = 1 ; i <= n; i++)     {         if ( w [i] > tempW)             then break ;         x [i] = 1.0 ;         tempW -= w [i];     }     if (i <= n)         x [i] = tempW / w [i]; } We can see that the above algorithm just contains a single loop i.e. no nested loops the running time for the above algorithm is O(n). However our requirement is that v[1 ... n] and w[1 ... n] are sorted, so we can use the sorting method to sort it in O(n log n

Software and Its Types

Image
Software Software is a collection of sets of programs, which are used to execute all kinds of specific instruction. It consists of a number of machine instructions, and arrays in a specific order to perform a particular task. Software is used to describe all the programs and their associated documents which run on a computer. So, a computer needs both software and hardware for its proper functioning. Software means computer instructions or data. Anything that can be stored electronically is software. Firmware is software (programs or data) that has been permanently written onto read-only memory (ROM) All software falls into two general types or categories: System Software and Application Software. System software consists of low-level programs that interact with the computer at a very basic level. This includes operating systems, compilers, and utilities for managing resources. On the other hand, application software includes database programs, word processors, and spreadsheets. Typ

C Program to Print Triangle Pattern | C Programming

Image
To draw the kite pattern, we use for a loop. The kite Pattern in c is easy to make using for loop. A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. Syntax The syntax of a for loop in C programming language is for ( init; condition; increment ) { statement(s); } Here is the flow of control in a 'for' loop − The init step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears. Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and the flow of control jumps to the next statement just after the 'for' loop. After the body of the 'for' loop executes, the flow of control jumps back up to the increment statement. This statement allows you to update any loop cont

Purpose of System Call

Image
The Purpose of The System Call The interface between a process and an operating system is provided by system calls. In general, system calls are available as assembly language instructions. They are also included in the manuals used by the assembly-level programmers. System calls are usually made when a process in user mode requires access to a resource. Then it requests the kernel to provide the resource via a system call. In general, system calls are required in the following situations: If a file system requires the creation or deletion of files. Reading and writing from files also require a system call. Creation and management of new processes. Network connections also require system calls. This includes sending and receiving packets. Access to a hardware device such as a printer, scanner, etc. requires a system call. Types of System Calls There are mainly five types of system calls. These are explained in detail as follows: Process Control These system calls deals with p