Bhanu Priya has Published 1581 Articles

C Program to find two’s complement for a given number

Bhanu Priya

Bhanu Priya

Updated on 24-Mar-2021 14:25:47

12K+ Views

The two’s complement for a given binary number can be calculated in two methods, which are as follows −Method 1 − Convert the given binary number into one’s complement and then, add 1.Method 2 − The trailing zero’s after the first bit set from the Least Significant Bit (LSB) including ... Read More

What is enumerated data type in C language?

Bhanu Priya

Bhanu Priya

Updated on 24-Mar-2021 14:24:31

2K+ Views

These are used by the programmers to create their own data types and define what values the variables of these datatypes can hold.The keyword is enum.SyntaxThe syntax for enumerated data type is as follows −enum tagname{    identifier1, identifier2, ……., identifier n };ExampleGiven below is an example for enumerated data ... Read More

How to merge to arrays in C language?

Bhanu Priya

Bhanu Priya

Updated on 24-Mar-2021 14:22:04

5K+ Views

Take two arrays as input and try to merge or concatenate two arrays and store the result in third array.The logic to merge two arrays is given below −J=0,k=0 for(i=0;i

C Program for sparse matrix

Bhanu Priya

Bhanu Priya

Updated on 24-Mar-2021 14:20:46

29K+ Views

In a given matrix, when most of the elements are zero then, we call it as sparse matrix. Example − 3 x3 matrix1 1 0 0 0 2 0 0 0In this matrix, most of the elements are zero, so it is sparse matrix.ProblemCheck whether a matrix is a sparse ... Read More

C Program to count trailing and leading zeros in a binary number

Bhanu Priya

Bhanu Priya

Updated on 24-Mar-2021 14:19:25

2K+ Views

To begin with, let us understand what are trailing zeros in a binary number.Trailing zerosThe position of zeros after first one from the least significant bit (LSB) is called as trailing zeros in binary number.Example104 is decimal numberBinary number of 104 is: (MSB) 1101000(LSB)Here, MSB refers to Most Significant Bit.LSB ... Read More

C program to rotate the bits for a given number

Bhanu Priya

Bhanu Priya

Updated on 24-Mar-2021 14:18:20

3K+ Views

Consider the factors given below to write a C program to rotate the bits for a given number.Rotating the bit from left to right or right to left.In left rotation, the bits are shifted from left to right.In right rotation, the bits are shifted from right to left.Take a number ... Read More

C Program to calculate the difference between two time periods

Bhanu Priya

Bhanu Priya

Updated on 24-Mar-2021 14:16:13

3K+ Views

Enter the start and stop time with hours, minutes and seconds. Finally, we need to find the difference between start and stop time.The logic to find the difference between start and stop time is given below −while (stop.sec > start.sec){    --start.min;    start.sec += 60; } diff->sec = start.sec ... Read More

C program to calculate power of a given number

Bhanu Priya

Bhanu Priya

Updated on 24-Mar-2021 14:14:46

16K+ Views

Take two integers from the user for base and exponent and calculate the power as explained below.ExampleConsider the following for writing a C program.Suppose base =3Exponent = 4Power=3*3*3*3AlgorithmFollow the algorithm given below −Step 1: Declare int and long variables. Step 2: Enter base value through console. Step 3: Enter exponent ... Read More

C Program to find minimum occurrence of character in a string

Bhanu Priya

Bhanu Priya

Updated on 24-Mar-2021 14:12:33

1K+ Views

An array of characters is called a string.DeclarationFollowing is the declaration for declaring an array is as follows −char stringname [size];For example − char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − ... Read More

C Program to find maximum occurrence of character in a string

Bhanu Priya

Bhanu Priya

Updated on 24-Mar-2021 14:08:11

3K+ Views

An array of characters is called a string.DeclarationFollowing is the declaration declaring an array is as follows −char stringname [size];For example: char string[50]; string of length 50 charactersInitializationUsing single character constant −char string[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char string[10] = "Hello":;Accessing − There is ... Read More

Advertisements