My Items

I'm a title. ​Click here to edit me.

Operating System | Introduction

Basically the operating system is a software that manages the computer hardware. It acts as an intermediary between the user of a computer and computer hardware. The purpose of an operating system is to provide an environment in which a user can execute programs in a convenient and efficient manner. An operating system is concerned with the allocation of resources and services, such as memory, processors, devices, and information. The operating system correspondingly includes programs to manage these resources, such as a traffic controller, a scheduler, a memory management module, I/O programs, and a file system. Functions of Operating System: Convenience: An OS makes a computer more convenient to use. Efficiency: An OS allows the computer system resources to be used in an efficient manner. Ability to Evolve: An OS should be constructed in such a way as to permit the effective development, testing, and introduction of new system functions at the same time without interfering with service. The operating system is a set of special programs that run on a computer system that allows it to work properly. It performs basic tasks such as recognizing input from the keyboard, keeping track of files and directories on the disk, sending output to the display screen, and controlling peripheral devices.
OS is designed to serve two basic purposes: It controls the allocation and use of the computing System’s resources among the various user and tasks. It provides an interface between the computer hardware and the programmer that simplifies and makes feasible for coding, creation, debugging of application programs. The Operating system must support the following tasks. The tasks are: Provides the facilities to create, modification of programs, and data files using an editor. Access to the compiler for translating the user program from high-level language to machine language. Provide a loader program to move the compiled program code to the computer’s memory for execution. Provide routines that handle the details of I/O programming. I/O System Management The module that keeps track of the status of devices is called the I/O traffic controller. Each I/O device has a device handler that resides in a separate process associated with that device.
The I/O subsystem consists of A memory Management component that includes buffering caching and spooling. A general device driver interface. Drivers for specific hardware devices. Assembler The input to an assembler is an assembly language program. The output is an object program plus information that enables the loader to prepare the object program for execution. At one time, the computer programmer had at his disposal a basic machine that interpreted, through hardware, certain fundamental instructions. He would program this computer by writing a series of ones and Zeros (Machine language), place them into the memory of the machine. Compiler The High-level languages- examples are FORTRAN, COBOL, ALGOL, and PL/I are processed by compilers and interpreters. A compiler is a program that accepts a source program in a “high-level language “and produces a corresponding object program. An interpreter is a program that appears to execute a source program as if it was machine language. The same name (FORTRAN, COBOL, etc.) is often used to designate both a compiler and its associated language. Loader A Loader is a routine that loads an object program and prepares it for execution. There are various loading schemes: absolute, relocating, and direct-linking. In general, the loader must load, relocate, and link the object program. The loader is a program that places programs into memory and prepares them for execution. In a simple loading scheme, the assembler outputs the machine language translation of a program on a secondary device and a loader places it in the core. The loader places into memory the machine language version of the user’s program and transfers control to it. Since the loader program is much smaller than the assembler, those make more core available to the user’s program.

Data Types in C

In this blog you will learn about the data types in C. The previous blog was about the variables and keywords C language, which you can find here. As we have learned in the last blog, the data type of a variable determines the type of value the variable stores, the amount of memory that is allotted to the variable and the operations that can be performed on the variable. For instance, a variable that is declared as int can only contain integers, and mathematical, relational and logical operations can be easily performed on it; while a variable that is declared as char can store only characters and mathematical operations cannot be performed on it without error. The data types in C can be broadly classified into two categories - primitive data types and derived data types. Primitive Data Type - The primitive data types are the fundamental data types in C. They form the basis for the more complex data types. Primitive data types can not be broken down into simpler data types. Some examples of primitive data types are int, char and float. Derived Data Types - The derived data types as the name suggests, are derived from the primitive data types. They can be created by grouping together one or more primitive data types. Some of the derived data types are array, struct and union. The derived data types are used to achieve special requirements. You will learn more about the derived data types in later blogs. All variables in a program must be declared with a data type as 'datatype var_name;'. For example: int age; float x; char t; The most common data types are the integer type, the floating point type and the character type. So let's study these in detail. Integer Type The integer data types is used to store integers. Data type Size (bytes) Range short signed int 2 -32768 to +32767 short unsigned int 2 0 to 65535 int (signed int) 2 -32768 to +32767 unsigned int 2 0 to 65535 long signed int 4 -2147483648 to +2147483647 long unsigned int 4 0 to 4294967295 Floating Point Type The floating data types are used to store real numbers. Data type Size (bytes) Range float 4 3.4E-38 to 3.4E+38 double 8 1.7E-308 to 1.7E+308 long double 10 1.7E-4932 to 1.7E+4932 Character Type The character types are used to store character values. Data type Size (bytes) Range signed char 1 -128 to +127 unsigned char 1 0 to 255 The short, long, signed and unsigned keywords are that type modifiers that change the meaning of the base data type to give a new type. Note: These figures are for 16-bit compilers. Happy coding! Follow us on Instagram @programmersdoor Join us on Telegram @programmersdoor Please leave comments if you find any inconsistency in the blog. Follow Programmers Door for more. #blog #c #learn #coding #programming

Variables and Keywords in C

In this blog you will learn about the variables and keywords in C. The previous blog was about the standard of the C language, which you can find here. Just like the building blocks of any language are its words, the building blocks of a programming language are variables and keywords. Using variables and keywords, one can create an instruction, and using a set of instructions, one can create a program. So lets study these variables and keywords. A variable is the name given to a memory location, and it is used to store data. Alternatively, an entity whose value may change during execution of a program is called a variable. Variables can have various data types, which determine the amount of memory that is allotted to that variable, and the operations that can be performed on that variable. Some of the data types available in C language are char, int, float, double, etc. We will explore these data types in detail later on. There are certain rules that must be followed while naming a variable. If not, the compiler will generate an error. The length of the name of a variable must be between 1 to 31. The variable name must be a combination of alphabets, digits, or underscores. The first character of a variable name should be an alphabet or an underscore. Commas and blanks are not allowed in a variable name. No special symbol other than an underscore are allowed in a variable name. According to these rules, some valid variable names are: x, emp_id, _date, num3. Similarly, the following variable names would be considered invalid: 6, roll no, 2row, marks&. A variable can be declared as: data_type var_name. Examples of declaration statements: int a; float avg_marks; char s; There are many types of variables in the C language. The main types of variables are as follows: Local Variable - A variable that is declared inside a function is called a local variable. The scope of a local variable is the function or block of code inside which it is declared. Global Variable - A variable that is declared outside the function is called a global variable. The scope of a global variable is the entire program, that means that any function can access a global variable. Static Variable - A variable that exists for the lifetime of a program is called a static variable. It’s value does not change during the execution of the program. A variable can be made static by adding the keyword ‘static’ in the variable declaration. Keywords are predefined, reserved words in C which convey special meaning to the compiler. Every keyword is associated with a specific feature. There are 32 keywords in C language, and they are given in the table below. auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while You will learn the meaning and functions of these keywords as you continue studying the C programming language. Happy coding! Follow us on Instagram @programmersdoor Join us on Telegram @programmersdoor Please leave comments if you find any inconsistency in the blog. Follow Programmers Door for more. #blog #c #learn #coding #programming

C Language Standard

In this blog you will learn about the standard of the C language. The previous blog was about the structure of a program in C, which you can find here. By definition, a standard is something established by authority as a model or point of reference. Just like the standard units of measurement, a standard for the programming language C was also required. This need arose because after C was developed, many professional programmers started making their own additions to it. This led to a number of variations of C being available for a programmer to choose from, but none of them was the real one. So, there was an urgent need for standardization. Previous Standards of C: The first standard was informal, and called K&R C after Brian Kernighan and Dennis Ritchie. It added some new features like the data types long int and unsigned int, and the compound assignment operator. It also proposed a standardized I/O library. There are only 28 keywords in K&R C. Even with K&R C, it was important for some standards organisation to come up with an official standard for C. The American National Standard Institute (ANSI) undertook the task, and as a result, ANSI C was developed. Keywords like const, enum, signed, void and volatile were introduced in ANSI C. It is also called C89, C90 or ISO C. It remains one of the very popular standards of C language. Almost all C compilers support features of ANSI C. In 1999, a new standard of C was developed, which was called ISO/IEC 9899:1999, or more simply, C99. It added a few more keywords to ANSI C like inline and restrict, along with new header files like <stdbool.h> <complex.h>, etc. Another standard, which is being developed in parallel to the other standards, is the Embedded C. The Embedded C was developed for the needs of embedded system programmers. It is mostly similar to the normal C, with some additional features. It has the advantage that it is simpler and easier to learn. Current Standard of C: The current and latest C programming language standard is called C11. It was adopted in 2011, hence the name. The document describing the C11 standard is called ISO/IEC 9899:2011. It added seven more keywords to C, making the total count of keywords 44. Happy coding! Follow us on Instagram @programmersdoor Join us on Telegram @programmersdoor Follow Programmers Door for more #blog #c #learn #coding #programming

LIFESTYLE | FIGHT THIS PANDEMIC WITH STRONG AND HEALTHY MIND

This pandemic has ruthlessly rattled the lives of people but its adversity can be reduced by healthy living. So hang on this blog will help you find your way towards healthy living. Amidst the lockdown time, people are facing huge number of problems may it be the outer problems of the daily life or the one which is growing into our mind and body . Seeing all the pace going down to zero , the economic world shaken up due to the pandemic, people struggling to earn their bread and butter and the very challenging mental breakdown . People seeing the picture of themselves on the verge of extinction, regular increase in the patient count, the unavailability of the beds in the hospitals making it even more worst to survive and with no early coming of the vaccine . People being stuck indoors, worried about an uncertain future , concerned for their near and dear ones . This pandemic is a stressful situation for anyone to contend with . BUT, Let's look up to a bigger picture , shiner and brighter can we heal our mind ???? Mind being the temple of the body generates immense positive energy which will help the people fight with greater strength . This is the time when you need to calm yourself and work on your mental wellbeing to keep your immune strong and healthy to fight this pandemic . There could be certain ways to protect your mental health- ** KEEP your mind active - read , write , play games sudokus , drawing , painting etc , find something you really enjoy . ** REGULARLY be in contact with your loved ones , try to express your thoughts , feeling and worries . It will help you feel lite and relaxed ** THINK about your daily routine with some different healthy exercise and activities . ** TRY to regularly meditate and calm your mind be stress free. ** LOOK after your sleep, try to maintain regular sleep pattern and keep good sleep hygiene practices . ** THE most important one move less out of your homes , only at times when it is really required and urgent , use proper masks and sanitizers . BE SAFE, BE CALM, BE HEALTHY ONLY KEYS TO FIGHT THIS PANDEMIC BRAVELY. HEALTHY LIVING! Follow us on Instagram @programmersdoor Join us on Telegram @programmersdoor Please write comments if have any recommendations or corrections. Follow Programmers Door for more LIFESTYLE blogs! #blog #learn #pandemic #healthyliving #stayhome #covidcrisis

Placement Practice | Dynamic Programming - I

In this blog, you will learn what dynamic programming is Introduction to Dynamic Programming Dynamic programming technique is similar to the divide and conquer approach. Both solve a problem by breaking it down into several subproblems that can be solved recursively. The difference between the two is that in a dynamic programming approach, the results obtained from solving smaller subproblems are reused (by maintaining a table of results) in the calculation of larger subproblems. Thus, dynamic programming is a Bottom-up approach that begins by solving the smaller sub-problems, saving these partial results, and then reusing them to solve larger sub-problems until the solution to the original problem is obtained. Reusing the results of sub-problems (by maintaining a table of results) is the major advantage of dynamic programming because it avoids the re-computations (computing results twice or more) of the same problem. Thus, the Dynamic programming approach takes much less time than naïve or straightforward methods, such as a divide-and-conquer approach that solves problems in the top-down method and having lots of re-computations. The dynamic programming approach always gives a guarantee to get an optimal solution. Take the case of generating the Fibonacci sequence. We know that n-th Fibonacci number fib(n) can be defined as: fib(n) = fib(n-1) + fib(n-2), where n >= 2.
and,
fib(0) = 0
fib(1) = 1 The first few Fibonacci numbers are: 1, 1, 2, 3, 5, 8, 13, 21, 34,... Recursive program: int fib(int n)
{
if (n <= 1)
return n;

return fib(n-1) + fib(n-2);
} The time complexity of the recursive solution is exponential. However, we can improve the time complexity by using Dynamic Programming approach and storing the results of the subproblems as shown below: int fib(int n)
{
int f[n+2];
int i;

// 0th and 1st number of the series are 0 and 1
f[0] = 0;
f[1] = 1;

for (i = 2; i <= n; i++)
{
f[i] = f[i-1] + f[i-2];
}

return f[n];
} The time complexity of the above solution is linear. Properties of a Dynamic Programming Problem There are two main properties of any problem which can be solved using the dynamic programming approach: Overlapping Subproblem Property Optimal Substructure Property Overlapping Subproblems: Dynamic programming is mainly used when solutions of the same subproblems are needed again and again. So Dynamic Programming is not useful when there are no common (overlapping) subproblems because there is no point in storing the solutions if they are not needed again. For example, Binary Search doesn’t have common subproblems. If we take an example of following the recursive program for Fibonacci Numbers, there are many subproblems that are solved again and again. Recursion tree for the execution of fib(5): fib(5)
/ \
fib(4) fib(3)
/ \ / \
fib(3) fib(2) fib(2) fib(1)
/ \ / \ / \
fib(2) fib(1) fib(1) fib(0) fib(1) fib(0)
/ \
fib(1) fib(0) We can see that the function fib(3) is being called 2 times. If we would have stored the value of fib(3), then instead of computing it again, we could have reused the old stored value. Optimal Substructure: A given problem has Optimal Substructure Property if an optimal solution of the given problem can be obtained by using optimal solutions of its subproblems. For example, the Shortest Path problem has the following optimal substructure property: If a node x lies in the shortest path from a source node u to destination node v then the shortest path from u to v is a combination of the shortest path from u to x and shortest path from x to v. The standard All Pair Shortest Path algorithms like Floyd–Warshall and Bellman-Ford are typical examples of Dynamic Programming. On the other hand, the Longest Path problem doesn’t have the Optimal Substructure property. Happy Coding! Follow us on Instagram @programmersdoor Join us on Telegram @programmersdoor Please write comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem. Follow Programmers Door for more. #blog #interview #placement #learn #computer #science

JAVA | Program to find duplicate words in a String

In this program, we need to find out the duplicate words present in the string and display those words. IMPLEMENTATION: 1. Lets start with creating class and main class under it. public class DuplicateCharacters
{
public static void main(String[] args)
{ 2. Now define String using auto generated method and also define integer count and
initialize it with zero. String str = new String("Programmers door");
int count=0; 3. After this lets create a character array to convert our string variable to the character. char[] chars=str.toCharArray(); 4.Now lets create for loops for comparing characters and if two characters of consecutive
index match, then we will print that character and the counter will be incremented by 1
after each iteration. System.out.println("Duplicate characters are:");
for (int i=0; i<str.length();i++)
{
for(int j=i+1; j<str.length();j++)
{
if (chars[i] == chars[j])
{
System.out.println(chars[j]);
count++;
break;
}
}
}
} OUTPUT: Duplicate characters are:
r
o
r
m
r
o Happy Coding! Follow us on Instagram @programmersdoor Join us on Telegram @programmersdoor Please write comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem. Follow Programmers Door for more. #blog #JAVA #HCF #learn #coding #programming

Structure of a C Program

In this blog you will learn about the structure of a program in C. The previous blog was about an introduction to the C language, which you can find here. As we have learned, C is a middle-level, procedure oriented programming language. This means that unlike object oriented languages like Java, in which programs are organised around a set of classes and objects, the programs in C are organised around a set of functions. The structure of a program in C is, thus, much simpler than that in Java. All C programs follow a structure, which is as follows: Any program in the C language is divided into six sections - the documentation section, the link section, the definition section, the global declaration section, the main() function section and the subprogram section. Let's discuss all of them one by one: Documentation Section - The first section of a C program is the documentation section. It is a set comment lines where information like the name of the program, name of the author, etc. are mentioned, which can be used by other programmers to identify the code. Link Section - The link section of a C program consists of instructions to the compiler to link the header files or functions from the system. Definition Section - The third section is the definition section which contains symbolic constants. Generally, the preprocessor directive '#define' is used to create constants. Global Declaration Section - Global declaration section is where global variables or user defined functions are declared. Global variables are the variables that can be used in more than one function; whereas local variables can only be used in the function they are declared in. Main Function Section - This section contains the main function of the program. Every program must have one main() function. Subprogram Section - The subprogram section is where the user-defined functions are defined, in case the program is a multi-function program. These user-defined functions can be called in the main() function or in each other. Let’s try to understand the structure with help of an example. In the following program, we are trying to find the area of a circle. /* areaofcircle.c
author: shuchi
date: 04-08-2020
*/

#include<stdio.h>

#define PI 3.14

float area(int r);

int main()
{ int r;
printf("Enter the value of radius \n");
scanf("%d",r);
float a;
a=area(r);
printf("The area of the circle is %f",a);
return 0;
}

float area(int r)
{ float a;
a = PI*r*r;
return a;
} Now let’s study the sections of the above program. /* areaofcircle.c
author: shuchi
date: 04-08-2020
*/ This is the documentation section of the program. In C, we can create comments using ‘//’ for single line comments, or using ‘/* */’. Comments are ignored by the compiler. #include<stdio.h> This is the link section of the program, which contains commands to link header files into the program. Some common header files which are used are stdio.h, conio.h, math.h, etc. #define PI 3.14 This is the definition section of the program. Here we have defined a constant ‘pi’ and assigned the value of 3.14 to it. Remember, the '#define' is not a statement and must not end with a semicolon (;). float area(int r); This is the global declaration section of the program. Here we have declared the function ‘area’. It is a user-defined function which takes the value of the radius, of the datatype int, as argument and calculates the area of the circle. int main()
{ int r;
printf("Enter the value of radius \n");
scanf("%d",r);
float a;
a=area(r);
printf("The area of the circle is %f",a);
return 0;
} This is the main() function of the program. In the main function we have asked the user to enter the value of the radius. Then the user-defined function ‘area’ is called and the value of the radius is passed as argument to it. The function returns the calculated area of the circle. We can print out the result using the ‘printf’ function. float area(int r)
{ float a;
a = PI*r*r;
return a;
} This is the subprogram section of the program. Here we are defining the function ‘area’ that we previously declared in the global declaration section. This function simply calculates the area of the circle using the formula ‘pi * r * r’ and returns it. Keep in mind that this function has been mentioned three times in the program. The first time was in the global declaration section, where the function is merely declared, i.e., the compiler is made aware of the existence of the function, its name, return type and parameters. The second time was inside the main() function, which calls the ‘area’ function. You can study calling a function in later blogs. The third time was in the subprogram section where the function was defined, i.e., the body of the function was provided. A function can be declared and defined together, but it should be at least declared before it is called. Happy coding! Follow us on Instagram @programmersdoor Join us on Telegram @programmersdoor Please leave comments if you find any bug in the above code, or find other ways to solve the same problem. Follow Programmers Door for more. #blog #c #learn #coding #programming

Placement Practice - Binary Search Tree

We have already covered the definition of BST, insertion, and deletion of nodes from the tree click here. Let's look at the process of finding LCA in a Binary Search Tree. Finding LCA in Binary Search Tree The LCA or Lowest Common Ancestor of any two nodes N1 and N2 is defined as the common ancestor of both the nodes which is closest to them. That is the distance of the common ancestor from the nodes N1 and N2 should be least possible. Given values of two values n1 and n2 in a Binary Search Tree, find the Lowest Common Ancestor (LCA). For Simplicity, you may assume that both the values exist in the tree. Consider the below BST: In the of above BST: LCA of 4 and 7 is 6
LCA of 7 and 3 is 3
LCA of 4 and 10 is 8 The main idea would be While traversing from top to bottom, the first node n we encounter with a value between n1 and n2, i.e., n1 <= n <= n2, is LCA of n1 and n2 (assuming that n1 < n2). So just recursively traverse the BST, if node's value is greater than both n1 and n2 then our LCA lies in the left subtree of the node, if it's is smaller than both n1 and n2, then LCA lies on the right subtree. Otherwise, the root is LCA (assuming that both n1 and n2 are present in BST). Implementation using C++: #include <bits/stdc++.h>
using namespace std;

class node
{
public:
int data;
node* left, *right;
};

node *lca(node* root, int n1, int n2)
{
if (root == NULL) return NULL;

if (root->data > n1 && root->data > n2)
return lca(root->left, n1, n2);

if (root->data < n1 && root->data < n2)
return lca(root->right, n1, n2);

return root;
}

node* newNode(int data)
{
node* Node = new node();
Node->data = data;
Node->left = Node->right = NULL;
return(Node);
}

int main()
{
node *root = newNode(200);
root->left = newNode(80);
root->right = newNode(220);
root->left->left = newNode(40);
root->left->right = newNode(120);
root->left->right->left = newNode(100);
root->left->right->right = newNode(140);

int n1 = 100, n2 = 140;
node *t = lca(root, n1, n2);
cout << "LCA of " << n1 << " and " << n2
<< " is " << t->data<<endl;

n1 = 140, n2 = 80;
t = lca(root, n1, n2);
cout<<"LCA of " << n1 << " and " << n2
<< " is " << t->data << endl;

n1 = 100, n2 = 220;
t = lca(root, n1, n2);
cout << "LCA of " << n1 << " and " << n2
<< " is " << t->data << endl;

return 0;
} Output: LCA of 100 and 140 is 120
LCA of 140 and 80 is 80
LCA of 100 and 220 is 200 AVL Tree AVL tree is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than one for all nodes. Insertion To make sure that the given tree remains AVL after every insertion, we must augment the standard BST insert operation to perform some re-balancing. Following are two basic operations that can be performed to re-balance a BST without violating the BST property (keys(left) < key(root) < keys(right)). Left Rotation Right Rotation Below image shows how insertion is performed: Time Complexity: The rotation operations (left and right rotate) take constant time as only a few pointers are being changed there. Updating the height and getting the balance factor also takes constant time. So the time complexity of the AVL insert remains the same as BST insert which is O(h) where h is the height of the tree. Since the AVL tree is balanced, the height is O(Logn). So time complexity of AVL insert is O(Logn). Happy Coding! Follow us on Instagram @programmersdoor Join us on Telegram @programmersdoor Please write comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem. Follow Programmers Door for more. #blog #interview #placement #learn #computer #science

Root Finding Techniques | Secant Method

In this article, we will be going to study the Secant method in numerical analysis and design using Python. Algorithm Read a,b,E Compute f(a) and f(b) for i=1 to n in steps of 1 do m=af(b)-bf(a)/f(b)-f(a) if(|f(m)|<E) then a=b and b=m endif else Write does not converge a,b,f(a),f(b) endfor Write convergent solution m,f(m) stop Flowchart Program import math
def f(x):
return x*x*x - x -1


def secant(a,b):

if (f(a) * f(b) <0.0):
while True:
m=(a*f(b)-b*f(a))/(f(b)-f(a))
a=b
b=m

if (abs(f(m)) < 0.0001):
break
print("Root",round(m,4))
else:
print("Cannot find roots")

a =1.0
b = 2.0
secant(a, b) Example Q]Find the real root of the equation x^3-x-1=0 by secant method up to 4 decimal places? Solution- F(x)=x^3-x-1
To find x0 and x1
F(0)=-1 , F(1)=-1 , F(2)= 5

Root[1,2]
F(1.5)=0.875 , F(1.4)=0.343 , F(1.3)= -0.103

Changing x0= 1.3 and x1= 1.4
F(x0)= -0.103 and F(x1)= 1.323042

(First case) x2=x0*F(x1)-x1*F(x0) =1.323042
F(x1)-F(x0)
F(x2)= -0.007136

(Second case) x3=x1*F(x2)-x2*F(x1) =1.323605
F(x2)-F(x1)
F(x2)= -0.000481

(Third case) x4=x2*F(x3)-x3*F(x2) =1.324717
F(x3)-F(x2)
F(x2)= -0.000004
Hence the correct answer(root) up to 4 decimal places is x=1.3247 Happy Coding! Follow us on Instagram @programmersdoor Join us on Telegram @programmersdoor Please write comments if you find any bug in the above code, or want some updates. Follow Programmers Door for more. #secantmethod #rootfindingtechinques #NAD #numerical #analysis #design #maths #computer #science #question #python #programming

Root Finding Techniques | Fixed Point Iteration Method

In this article, we will be going to study the fixed point iteration method in numerical analysis and design using Python. Algorithm start Read x,,epsilon(absolute error),x_before=0,i Calculate f(x) and g(x) //f(x)=putting x in the fxn,g(x)=differentiation of f(x) while (|x-x_before|>epsilon) x_before=x x=g(x) print (i, "{0:.6f}".format(x), "{0:.6f}".format(abs(x - x_before))) i=i+1 end loop Flowchart Program def f(x):
return (x**3 - 9*x + 1 )


def g(x):
return (9*x-1)**(1/3)

epsilon = 0.0001


x = 2.7

x_before = 0

i = 0

while (abs(x - x_before) > epsilon):
x_before = x
x = g(x)

print(i, "{0:.6f}".format(x), "{0:.6f}".format(abs(x - x_before)))
i = i + 1 Example Q]Q] Find the real root of equation x^3-9x+1=0 by fixed-point iteration method? Solution- f(0)=1 , f(1)=-7 , f(2)=-9 , f(3)=1
Since root of f(x)=0 lies between 2 and 3 so taking x0=2.7

Assumption-
x= (9x-1)^1/3
F(x)= (9x-1)^1/3
F’(x)=3/(9x-1)^2/3
Since F’(2.7) coming less than 1,satisfy the condition . So taking
x(n+1)=(9x(n)-1)^1/3
n=0
x1=(9x0-1)^1/3=2.8562
x2=(9x1-1)^1/3=2.9125 -------------------------------------------
----------------------------------------
x7=2.9427
X8=2.9428
We get two approximate values having same decimal digits up to three places ,so the answer is 2.942 Happy Coding! Follow us on Instagram @programmersdoor Join us on Telegram @programmersdoor Please write comments if you find any bug in the above code, or want some updates. Follow Programmers Door for more. #fixedpointiterationmethod #rootfindingtechinques #NAD #numerical #analysis #design #maths #computer #science #question #python #programming

Introduction to C Language

In this blog, you will be introduced to the C programming language. One of the oldest languages, C is a general-purpose procedure-oriented programming language. It was developed by Dennis M. Ritchie in 1972, at the Bell Telephone Laboratories. It is the successor to B language and was developed to build the Unix operating system. Along with Unix, it became highly popular in the market during the 1980s. Some key characteristics of C are machine-independence, flexibility, an easy set of keywords, and user-friendliness. It has also become the basis for various other languages, and was standardized by ANSI (American National Standards Institute) in 1989 and the ISO (International Organization of Standardization). When it was created, C was a better language than its preceding languages by a long shot. Listed below are the qualities of the language that can be counted as its advantages, and that helped it become so well-liked. One of its most important features is portability. It can be used on any machine with little to no changes in the code. It is a structured programming language, that is, the complex programs can be divided into simpler ones, called functions. It boasts a rich library with a vast collection of in-built functions. It has the ability to extend itself, which means that the users are allowed to add their own functions in their programs. C uses only 32 keywords, and they are simple and easy to learn and work with. It is a middle level language, which means it bridges the gap between the high level languages and the low level languages, and combines the features of both. It provides dynamic memory allocation. Dynamic memory allocation allows you to assign memory during the run time of a program. C is faster than a lot of other languages. Programs written in this language are executed very quickly. It is a very powerful and efficient language, which can be proven by the fact that it still maintains its spot on the list of the most popular programming languages of the world. But even a language as robust as C has its disadvantages, some of which are — It does not support the concepts of object oriented programming, or OOPs, like inheritance, polymorphism, encapsulation, data abstraction etc. It is purely a procedure oriented language. There is no run time type checking, that is, if the data entered during the run time of the program is of the wrong data type, it does not generate an error message. It does not support constructors and destructors like C++ does. C does not provide the namespace feature. Without namespace, the declaration of two variables of the same name is not possible. An important feature that C lacks is the exception handling. Exception handling allows the user to catch errors and bugs in the program during compile time. But C does not support this. Even with these drawbacks, the common opinion that C is obsolete or out of date is completely wrong. Modern software developers make extensive use of it in several places. It remains in demand in the IT industry. Some applications of C are as follows — The primary use of C is the development of operating systems. Unix operating system was completely created with C is considered the best language for embedded systems, as it works closely with the machine hardware. C is used to create GUIs, which stands for Graphical User Interface. Adobe Photoshop has been created using C. A number of other programming languages have been derived from C, including, but not limited to, C++, which is almost a superset of C. C is a middle level language, and because of that, it is used to create compilers for other programming languages. C even finds multiple uses in the gaming and animation sector. Database and spreadsheet softwares can be developed using C. Internet browsers can be built using C language. Google Chrome and Mozilla Firefox are a couple of examples. A lot of people start their programming career by learning C. In fact, it is a mandatory course in most of the universities. The following features of C make it a great language for beginners — It is easy to understand and learn. It provides an excellent understanding of the basics of programming. The concepts of data types, loops, functions, structures, pointers, etc. are introduced in C. Programming in C helps develop reasoning and logical thinking abilities. C is a widely used language, so having this skill will surely be beneficial in future. After learning C, learning other languages like C++, Java, Python, etc. becomes incredibly easy. Coding is quickly becoming a necessary skill in so many different professions, and C might be just the language to begin your own programming journey. So, if you’re ready to start, you can easily download IDEs (integrated development environments) such as Turbo C/C++, Dev C++, Eclipse or any other IDE of your choice that supports C. Kick off with the classic program to print the message ‘Hello world’ given below. Happy coding! Follow us on Instagram @programmersdoor Join us on Telegram @programmersdoor Please leave comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem. Follow Programmers Door for more. #blog #c #learn #coding #programming

        Contact Us

programmersdoor@gmail.com

  • LinkedIn
  • Facebook
  • Instagram

©2023 by Programmers Door