Let us first understand the one dimensional array processing in C programming language.1D Array ProcessingStoring values in 1 D Array(reading) is done as follows −int num[5] int i; for(i=0;i
ProblemLet’s create a simplified expression by removing brackets from the expressions.SolutionExample 1Input: A string expression with bracket is as follows: (x+y)+(z+q) The output is as follows: x+y+z+qExample 2The input is as follows: (x-y+z)-p+q The output is as follows: x-y+z-p+qAlgorithmRefer an algorithm to remove the brackets from a given input.Step 1: Declare and read the input at runtime.Step 2: Traverse the string.Step 3: Copy each element of the input string into new string.Step 4: If anyone parenthesis is encountered as an element, replace it with empty space.ExampleFollowing is the C program to remove the brackets from a given input −#include int ... Read More
An array is a group of related data items which share’s a common name. A particular value in an array is identified with the help of its "index number".Declaring arrayThe syntax for declaring an array is as follows −datatype array_name [size];For example, float marks [50]It declares ‘marks’ to be an array containing 50 float elements.int number[10]It declares the ‘number’ as an array to contain a maximum of 10 integer constants.Each element is identified by using an "array index".Accessing array elements is easy by using the array index.The logic we use for merge sort is as follows −void MergeSort(int *array, int ... Read More
ProblemWrite a C program to search an element from an array at runtime by the user and the result to be displayed on the screen after search. If the searching element is not in an array then, we need to search element is not found.SolutionAn array is used to hold the group of common elements under one nameThe array operations are as follows −InsertDeleteSearchAlgorithmRefer an algorithm to search the elements into an array with the help of pointers −Step 1 − Declare and read the number of elements.Step 2 − Declare and read the array size at runtime.Step 3 − ... Read More
ProblemWrite a C program to delete an element from an array at runtime by the user and the result to be displayed on the screen after deletion. If the deleted element is not in an array, then we need to display Invalid Input.SolutionAn array is used to hold the group of common elements under one name.The array operations are as follows −InsertDeleteSearchAlgorithmRefer an algorithm to delete the elements into an array with the help of pointers.Step 1 − Declare and read the number of elements.Step 2 − Declare and read the array size at runtime.Step 3 − Input the array ... Read More
ProblemWrite a C program to insert the elements into an array at runtime by the user and the result to be displayed on the screen after insertion. If the inserted element is greater than the size of an array, then, we need to display Invalid Input.SolutionAn array is used to hold the group of common elements under one name.The array operations are as follows −InsertDeleteSearchAlgorithmRefer an algorithm to insert the elements into an array with the help of pointers.Step 1: Declare and read the number of elements.Step 2: Declare and read the array size at runtime.Step 3: Input the array ... Read More
ProblemSort the given array in descending or ascending order based on the code that has been written.SolutionAn array is a group of related data items which share’s a common name. A particular value in an array is identified with the help of its "index number".Declaring arrayThe syntax for declaring an array is as follows −datatype array_name [size];For example, float marks [50]It declares ‘marks’ to be an array containing 50 float elements.int number[10]It declares the ‘number’ as an array to contain a maximum of 10 integer constants.Each element is identified by using an "array index".Accessing array elements is easy by using ... Read More
We can apply the software development method to solve the linear equation of one variable in C programming language.RequirementThe equation should be in the form of ax+b=0a and b are inputs, we need to find the value of xAnalysisHere, An input is the a, b values.An output is the x value.AlgorithmRefer an algorithm given below to find solution of linear equation.Step 1. Start Step 2. Read a, b values Step 3. Call function Jump to step 5 Step 4. Print result Step 5: i. if(a == 0)Print value of c cannot be predictedElseCompute c=-b/aReturn cStep 6: StopProgramFollowing is the C ... Read More
Linked lists use dynamic memory allocation i.e. they grow and shrink accordingly. They are defined as a collection of nodes. Here, nodes have two parts, which are data and link. The representation of data, link and linked lists is given below −Types of Linked ListsLinked lists have four types, which are as follows −Single / Singly linked listsDouble / Doubly linked listsCircular single linked listCircular double linked listThe logic we used to find the length of linked list by using recursion method is −int length(node *temp){ if(temp==NULL) return l; else{ l=l+1; ... Read More
ProblemFind out if a given number can be expressed as sum of two prime numbers or not.Given a positive integer N, we need to check if the number N can be represented as a sum of two prime numbers.SolutionConsider an example given below −20 can be expressed as sum of two prime numbers 3 and 17, 13 and 7.20= 3+720= 13+7AlgorithmRefer an algorithm given below for expressing a given number as a sum of two prime numbers.Step 1 − Input the number to be checked at run time.Step 2 − Repeat from i = 2 to (num/2).Step 3 − Check ... Read More