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
ProblemWrite a program to replace all zeros (0's) with 1 in a given integer.Given an integer as an input, all the 0's in the number has to be replaced with 1.SolutionConsider an example given below −Here, the input is 102410 and the output is 112411.AlgorithmRefer an algorithm given below to replace all the 0’s to 1 in an integer.Step 1 − Input the integer from the user.Step 2 − Traverse the integer digit by digit.Step 3 − If a '0' is encountered, replace it by '1'.Step 4 − Print the integer.ExampleGiven below is the C program to replace all 0's ... Read More
Queue overflow and Queue under flow can be avoided by using linked list.Operations carried out under queue with the help of linked lists in C programming language are as follows −InsertDeleteInsertionThe syntax is as follows −Syntax&item : Newnode = (node*) mallac (sizeof (node)); newnode ->data = item; newnode ->link = NULL; if ((front = = NULL) || (rear = = NULL)){ front= newnode; rear = newnode; }else{ Rear->link = newnode; rear = newnode; }DeletionThe syntax is as follows −Syntaxif ((front= = NULL)) printf("Deletion is not possible, Queue is empty"); else{ temp = front; front ... Read More
In C programming language, the most common use of structure is an array of structures.To declare an array of structures, first the structure must be defined and then, an array variable of that type has to be defined.For example,struct book b[10];//10 elements in an array of structures of type ‘book’ExampleFollowing is the C program for the array of structures − Live Demostruct marks{ int sub1; int sub2; int sub3; int total; }; main(){ int i; struct marks student[3] = {{20,17,11,10}, {175,23,169,10}, {27,56,27,01}}; struct marks total; for(i = 0; i
In C programming language, a structure is a collection of different datatype variables, which are grouped together under a single name.Declaration and initialization of structuresThe general form of a structure declaration is as follows −datatype member1; struct tagname{ datatype member2; datatype member n; };Here, struct is a keyword.tagname specifies the name of structure.member1, member2 specifies the data items that make up structure.For example, struct book{ int pages; char author [30]; float price; };Structure variablesThere are three methods of declaring structure variables, which are as follows −First methodstruct book{ int pages; char author[30]; ... Read More
Stack over flow and stack under flow can be avoided by allocating memory dynamically.Operations carried out under stack in C programming language are as follows −PushPopPushFollowing is the basic implementation of a linked list −&item = 10 newnode = (node*) malloc (sizeof (node)); newnode ->data = item; newnode ->link = NULL; newnode ->link = start; start = newnode;popThe syntax is as follows −Syntaxif (start = = NULL) printf("Deletion is not possible.List is empty") else{ temp = start; start = start link; free (temp); }ProgramFollowing is the C program for stack by using linked lists −#include #include ... Read More
ProblemSort the names given by the user at runtime in an alphabetical order by using the bubble sort technique.SolutionThe logic used to print the names in alphabetical order is as follows −for (i=1; i < ITEMS; i++){ for (j=1; j 0){ /* Exchange of contents */ strcpy (dummy, string[j-1]); strcpy (string[j-1], string[j]); strcpy (string[j], dummy ); } } }ExampleFollowing is the C program to sort the names in an alphabetical order by using the string functions − Live Demo#define ITEMS 5 #define MAXCHAR ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP