Found 26504 Articles for Server Side Programming

How to find minimum element in an array using binary search in C language?

Bhanu Priya
Updated on 20-Jun-2024 01:51:23

2K+ Views

C programming language provides two types of searching techniques. They are as follows − Linear search Binary search Binary Search This method can be applied only to sorted list. The given list is divided into two equal parts. The given key is compared with the middle element of the list. Here, three situations may occur, which are as follows − If the middle element matches the key, then the search will end successfully here ... Read More

C program to replace all zeros with one in a given integer.

Bhanu Priya
Updated on 26-Mar-2021 06:56:47

3K+ Views

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

What are the local static variables in C language?

Sindhura Repala
Updated on 20-Jan-2025 17:20:08

5K+ Views

A local static variable is a variable, whose lifetime doesn’t end with the function call in which it is declared. It extends until the entire programs lifetime. All function calls share the same copy of local static variables. Static Variables A static variable preserves its value across multiple function calls, maintaining its previous value within the scope where it was initialized. These variables are used to count the number of times a function is called. The default value of a static variable is 0. In contrast, normal local scope means that the variables defined within the block are only visible ... Read More

C programs to differentiate array of structures and arrays within a structure

Bhanu Priya
Updated on 26-Mar-2021 06:50:51

782 Views

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

C program to compare the structure variables

Bhanu Priya
Updated on 26-Mar-2021 06:47:28

9K+ Views

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

How to find minimum element in an array using linear search in C language?

Sindhura Repala
Updated on 20-Jan-2025 16:39:20

1K+ Views

Searching for an algorithm is considered as a step-by-step procedure for specifying a data among a large set of data. The C programming language provides two types of searching techniques. They are as follows − Linear search Binary search Linear Search A Linear Search is also known as sequential search, which is a process for finding an item in a list of items. This kind of algorithm checks each element of the list one by one until a match is found in the total list . ... Read More

Explain queue by using linked list in C language

Bhanu Priya
Updated on 26-Mar-2021 06:52:11

1K+ Views

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

Explain the stack by using linked list in C language

Bhanu Priya
Updated on 26-Mar-2021 06:47:11

3K+ Views

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

Explain the deletion of element in linked list

Bhanu Priya
Updated on 26-Mar-2021 06:40:12

717 Views

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 −Operations on linked listsThere are three types of operations on linked lists in C language, which are as follows −InsertionDeletionTraversingDeletionConsider an example given below −Delete node 2Delete node 1Delete node 3ProgramFollowing is the C program for deletion of the elements in linked lists − Live Demo#include #include struct Node{    int data;    struct Node *next; }; void ... Read More

Explain deleting an element in a queue by using C language

Bhanu Priya
Updated on 20-Jun-2024 21:39:11

7K+ Views

Data structure is collection of data organized in a structured way. It is divided into two types as explained below −Linear data structure − Data is organized in a linear fashion. For example, arrays, structures, stacks, queues, linked lists.Nonlinear data structure − Data is organized in a hierarchical way. For example, Trees, graphs, sets, tables. Also Read: Data Structures and Types Queue Queue is a linear data structure, where the insertion is done at rear end and the deletion is done at the front end.The order of queue is FIFO – First In First OutOperationsInsert – Inserting an element into ... Read More

Advertisements