- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1401 Articles for C
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
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
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
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
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
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
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
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