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

Bhanu Priya
Updated on 20-Jun-2024 02:10:34

986 Views

C programming language provides two types of searching techniques. They are as follows − Linear search Binary search Linear Search Searching for the key element is done in a linear fashion. It is the simplest searching technique. It does not expect the list to be sorted. Limitation − It consumes more time and reduce the power of system. Input Unsorted list of elements, key. Output Success – If key is found. Unsuccessful – Otherwise. Example 1 Following ... Read More

What are the local static variables in C language?

Bhanu Priya
Updated on 20-Jun-2024 02:04:18

4K+ Views

A local static variable is a variable, whose lifetime doesn’t stop with a function call where it is declared. It extends until the lifetime of a complete program. All function calls share the same copy of local static variables.These variables are used to count the number of times a function is called. The default value of static variable is 0. Whereas, normal local scope specifies that the variables defined within the block are visible only in that block and are invisible outside the block.The global variables which are outside the block are visible up to the end of the program.ExampleFollowing ... 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

How to calculate sum of array elements using pointers in C language?

Bhanu Priya
Updated on 20-Jun-2024 01:36:52

17K+ Views

Pointer is a variable which stores the address of other variable.Consider the following statement −int qty = 179;Declaring a pointerThe syntax for declaring a pointer is as follows −int *p;Here, ‘p’ is a pointer variable which holds the address of other variable.Initialization of a pointerAddress operator (&) is used to initialize a pointer variable.For example, int qty = 175; int *p; p= &qty;Array of PointersIt is collection of addresses (or) collection of pointers.DeclarationFollowing is the declaration for array of pointers −datatype *pointername [size];For example, int *p[5];It represents an array of pointers that can hold five integer element addresses.Initialization‘&’ is used ... Read More

Find the largest number in a series by using pointers in C language

Bhanu Priya
Updated on 20-Jun-2024 01:31:22

3K+ Views

Pointer is a variable that stores the address of another variable. We can hold the null values by using pointer. It can be accessed by using pass by reference. Also, there is no need of initialization, while declaring the variable. The syntax for pointer is as follows − pointer variable= & another variable; For example, p =&a; Algorithm Refer an algorithm given below for finding the largest number in a series with the help of pointers. Step 1: Start Step 2: Declare integer variables Step 3: Declare pointer variables Step 4: Read 3 numbers from console Step 5: Assign ... Read More

Explain unformatted input and output functions in C language

Bhanu Priya
Updated on 20-Jun-2024 01:22:07

6K+ Views

Unformatted input and output functions read a single input sent by the user and permits to display the value as the output at the console. Unformatted input functions The unformatted input functions in C programming language are explained below − getchar() It reads a character from the keyboard. The syntax of getchar() function is as follows − Variablename=getchar(); For example, Char a; a = getchar(); Example Program Following is the C program for getchar() function −  Live Demo #include int main(){    char ch;    FILE *fp;    fp=fopen("file.txt", "w"); //open the file in write mode    printf("enter the text ... Read More

What is conditional compilation in C language?

Bhanu Priya
Updated on 20-Jun-2024 00:36:06

10K+ Views

What is conditional compilation in C language? In C programming language, several directives control the selective compilation of portions of the program code. They are as follows − #if #else #elif #endif The general form of #if is as follows − #if constant_expression    statement sequence #endif #else works much like the C keyword else. #elif means "else if" and establishes an if else-if compilation chain. Amongst other things, #if provides an alternative method of "commenting out" code. For example, #if 0    printf("#d", total); #endif Here, the compiler will ... Read More

What are memory operations in C language?

Bhanu Priya
Updated on 20-Jun-2024 00:33:01

754 Views

The library #include contains the basic memory operations. Although not strictly string functions, the functions are prototyped in #include . These memory operations are as follows − void *memchr (void *s, int c, size_t n); Search for a character in a buffer. int memcmp (void *s1, void *s2, size_t n); Compare two buffers. ... Read More

What are string searching functions in C language?

Bhanu Priya
Updated on 20-Jun-2024 00:27:24

910 Views

string searching functions in C language The library also provides several string searching functions, which are as follows − char *strchr (const char *string, intc); Find first occurrence of character c in string. char *strrchr (const char *string, intc); Find last occurrence of character c in string. ... Read More

How to convert binary to Hex by using C language?

Bhanu Priya
Updated on 19-Jun-2024 23:14:55

7K+ Views

Binary numbers are represented in 1’s and 0’s.Hexadecimal number system with 16 digits is {0, 1, 2, 3…..9, A(10), B(11), ……F(15)}To convert from binary to hex representation, the bit string id is grouped in blocks of 4-bits which are called as nibbles from the least significant side. Each block is replaced by the corresponding hex digit.Let’s see an example to get the clarity on hexadecimal and binary number representation.0011 1110 0101 1011 0001 1101   3    E    5    B   1    DWe write 0X3E5B1D for a hex constant in C language.Another example which What iss how ... Read More

Advertisements