Found 1339 Articles for C

C program to find the unique elements in an array.

Bhanu Priya
Updated on 14-Sep-2023 02:28:29

34K+ Views

ProblemFind the non-repeating element in an array by using the two loops. One is for the current element and the other is to check, if an element is already present in an array or not.SolutionConsider an example given below −15, 15, 16, 15, 13, 15Here, the non-repeated elements in an array are 16 and 13.AlgorithmRefer an algorithm given below for finding the unique or the non-repeated elements in an array.Step 1 − Declare an array and input the array elements at run time.Step 2 − Start traversing the array and check, if the current element is already present in an ... Read More

C program for a number to be expressed as a sum of two prime numbers.

Bhanu Priya
Updated on 26-Mar-2021 07:00:07

4K+ Views

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

C program to find the solution of linear equation

Bhanu Priya
Updated on 26-Mar-2021 07:04:38

5K+ Views

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

C program to find the length of linked list

Bhanu Priya
Updated on 26-Mar-2021 07:04:06

2K+ 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 −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

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

780 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

Advertisements