Bhanu Priya

Bhanu Priya

1,060 Articles Published

Articles by Bhanu Priya

Page 11 of 106

Finding even and odd numbers in a set of elements dynamically using C language

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 1K+ Views

ProblemTo compute sum of even numbers and odd numbers in a set of elements using dynamic memory allocation functions.SolutionIn this program, we are trying to find even and odd numbers in a set of numbers.The logic used to find even numbers in a set elements is given below −for(i=0;i

Read More

C program to rotate the bits for a given number

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 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 and try to rotate either left or right based on user program.User has to enter the number rotation at run time along with a number.Program 1Following is the C program to apply left rotation for a given number.#include #include int main(){    int number, rotate, Msb, size;    printf("Enter any ...

Read More

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

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 3K+ 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 refers to Least Significant Bit.From LSB after the first bit set, there are three zero.The number of trailing zeros is three.ExampleFollowing is the program to count number of trailing zeros for a given number −#include #include int main(){    int number, i, trail = 0, size;    printf("Enter a number"); ...

Read More

Working with two-dimensional array at runtime in C programming

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 2K+ Views

ProblemWrite a C program to calculate sum and product of all elements in two-dimensional array using run time compilation.SolutionRuntime compilation or initialization is also called as dynamic allocation. Allocation of memory at the time of execution (run time) is known as dynamic memory allocation.The functions calloc() and malloc() support allocating of dynamic memory.In this program, we will calculate the sum of all elements and product of all elements of two-dimensional array at run time.Logic for computing sum of all elements in 2D array −printf("Sum array is : "); for(i=0;i

Read More

What is enumerated data type in C language?

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 3K+ 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 type −enum week{    mon, tue, wed, thu, fri, sat, sun };Here, Identifier values are unsigned integers and start from 0.Mon refers 0, tue refers 1 and so on.ExampleFollowing is the C program for enumerated data type −#include main ( ){    enum week {mon, tue, wed, thu, fri, sat, ...

Read More

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

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 18K+ 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 one that remains unchanged and remaining all should be complementing.The logic to find two’s complement for a given binary number is as follows −for(i = SIZE - 1; i >= 0; i--){    if(one[i] == '1' && carry == 1){       two[i] = '0';    }    else ...

Read More

What are character analysis function, explain with C program?

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 321 Views

Character analysis and conversion functionsThe predefined functions in “ctype.h” library is for analyzing the character input and converting them.Analysis functionsS.NoFunctionDescription1isalpha()An alphabet or not2isdigit()A digit or not3isspace()A space, a new line or tab4ispunct()A special symbol or not5slower()A lower case letter of alphabet6isupper()An upper case letter of alphabet7isalphanumeric()An alphabet/digit or notConverting functionsFunctionDescriptiontolower()Converts an upper case alphabet to lower casetoupper()Converts a lower case alphabet to upper caseExampleLet us see a program to demonstrate character analysis and conversion functions −#include #include void main(){    //Initializing compile time character variable// char variable = 'A';    //Reading User I/P//    //printf("Enter the character : ");   ...

Read More

Finding number of alphabets, digits and special characters in strings using C language

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 866 Views

Following is the logic we implement to find alphabets, digits and special characters −for(number=0;string[number]!='\0';number++) {// for loop until endof string    if(string[number]>='a'&&string[number]='A'&&string[number]='0'&&string[number]='a'&&string[number]='A'&&string[number]='0'&&string[number]

Read More

Declaring a structure with no members in C language

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 1K+ Views

ProblemCan we declare a structure with no members in C, if yes what will be the size of that structure?SolutionYes, it is allowed in C programming language that we can declare a structure without any member and in that case the size of the structure with no members will be 0 (Zero). It will be a Zero size structure.Example#include //structure with no members struct temp{ }; int main(){    //declaring structure variable    struct temp T;    printf("Size of T: %d", sizeof(T));    return 0; }OutputIn this C program, we are declaring a structure named "temp" without declare any ...

Read More

What is out of bounds index in an array - C language?

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 3K+ Views

Suppose you have an array with four elements. Then, an array indexing will be from 0 to 3, i.e., we can access elements from index 0 to 3.But, if we use index which is greater than 3, it will be called as an index out of bounds.If, we use an array index which is out of bounds, then the compiler will compile and even run. But, there is no guarantee for the correct result.Result can be not sure and it will start causing many problems. Hence, it is advised to be careful while using an array indexing.Example ProgramFollowing is the ...

Read More
Showing 101–110 of 1,060 articles
« Prev 1 9 10 11 12 13 106 Next »
Advertisements