Found 1401 Articles for C

C Program to find the given number is strong or not

Bhanu Priya
Updated on 06-Nov-2023 03:39:36

30K+ Views

A strong number is a number, where the sum of the factorial of the digits is equal to the number itself.Example123!= 1!+2!+3!                   =1+2+6 =9Here, 123 is not a strong number because, the sum of factorial of digits is not equal to the number itself.145!=1!+4!+5!            =1+24+120            =145Here, 145 is a strong number because, the sum of factorial of digits is equal to the number itself.The logic we use to find whether the given number is strong or not is as follows − while(n){    i = 1,fact = 1;    rem = n % 10;    while(i

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

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 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 is enumerated data type in C language?

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 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 − Live Demo#include main ( ){    enum week {mon, tue, wed, thu, fri, ... Read More

C Program to delete the duplicate elements in an array

Bhanu Priya
Updated on 12-Sep-2023 03:23:56

39K+ Views

Try to delete the same numbers present in an array. The resultant array consists of unique elements.The logic to delete the duplicate elements in an array is as follows −for(i=0;i

How to merge to arrays in C language?

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
Updated on 24-Mar-2021 14:20:46

30K+ 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 matrix or not.SolutionLet us assume ZERO in the matrix is greater than (row * column)/2.Then, the matrix is a sparse matrix otherwise not.ProgramFollowing is the program to check whether the given matrix is sparse matrix or not − Live Demo#include #include int main(){    int row, col, i, j, a[10][10], count ... Read More

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

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 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 − Live Demo#include #include int main(){    int number, i, trail = 0, size;    printf("Enter a ... Read More

C program to rotate the bits for a given number

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 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. Live Demo#include #include int main(){    int number, rotate, Msb, size;    printf("Enter ... Read More

C Program to check whether the triangle is equilateral, isosceles or scalene

Bhanu Priya
Updated on 07-Nov-2023 04:45:51

47K+ Views

Triangle consists of three sides and three angles. Based on the three sides, there are three types of triangle −Equilateral triangle: All three sides are equal.Isosceles triangle: All two sides are equal.Scalene triangle: No sides are equal.Follow the algorithm given below for writing the respective program.AlgorithmStep 1: Declare three sides of triangle. Step 2: Enter three sides at run time. Step 3: If side1 == side2 && side2 == side3 Go to step 6 Step 4: If side1 == side2 || side2 == side3 || side3 == side1 Go to Step 7 Step 5: Else Go to step 8 Step ... Read More

C Program to calculate the difference between two time periods

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

4K+ 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 - stop.sec; while (stop.min > start.min) {    --start.hrs;    start.min += 60; } diff->min = start.min - stop.min; diff->hrs = start.hrs - stop.hrs;ExampleFollowing is the program to find difference between start and stop time − Live Demo#include struct time {    int sec;    int min;    int hrs; ... Read More

Advertisements