In this program, we are trying to check whether the two given numbers by the user through console, are friendly pair or not?ExampleIf sum of all divisors of number1 is equal to number1 and sum of all divisors of number2 is equal to number2, then we can say, those two numbers are abundant numbers.The logic that we used to find friendly pairs is as follows −For the sum of all divisors of number 1.for(i=1;i
Squeeze(s1, s2) or squeeze(char[], char[]) is a user defined function which is used to delete the common characters or equal characters in two strings.ProblemHow to delete the common characters in two strings using squeeze function in C programming language?SolutionIn this program, the user enters two strings in the console and write a code to display first string excluding the common characters present in second string.ExampleThe C program which demonstrates the functioning of squeeze function is as follows − Live Demo#include void squeeze(char string1[], char string2[]);//prototype declaration int main(){ char string1[50]; char string2[30]; printf("enter the string1:"); scanf("%s", string1);// ... Read More
The different data types that we use in C programming are integer, short int, Signed and un signed char etc.Data TypesData type specifies the set of values and the type of data that can be stored in a variable. They allow the programmer to select the type appropriate to the needs of application.The data types are as follows −Primary data typesDerived data typesLet us understand primary data types.Primary data types‘C’ compilers support four fundamental data types. They are mentioned below −integercharacterFloating – pointDouble precision floating pointIntegral data typeIntegral data types are used to store whole numbers and characters. It is ... Read More
Arrays are a kind of data structure that can store a fixed-size sequential collection of elements of the same type.An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.LimitationsThe limitations of an array are explained below −An array which is formed will be homogeneous. That is, in an integer array only integer values can be stored, while in a float array only floating value and character array can have only characters. Thus, no array can have values of two data ... Read More
Functions communicate among themselves with the help of arguments and return value.Farm of ‘C’ function is as follows −return-datatype function name (argument list){ local variable declarations; executable statements(s); return (expression); }For example, void mul (int x, int y){ int p; p=x*y; printf("product = %d”, p); }Return values and their typesA function may or may not send back a value to the calling function.It will be done by using the return statementThe return types are void, int, float, char and double.If a function is not returning any value, then its return type is ‘void’.Function nameA ... Read More
A function is a self-contained block that carries out a specific well defined task.Advantages of functions in C language include −Reusability.The length of the program can be reduced.It is easy to locate and find any faulty function.It facilitates top-down modular programming.Top down design and structure chartsIt is a problem solving method in which a complex problem is solved by splitting into sub problems.Structure chart is a documentation tool that shows the relationships among the sub problems of a problem.The splitting of a problem into its related sub problems is the process of refining an algorithm. For example, performing arithmetic operations ... Read More
In C programming language, float is a short term for floating point.Floating point numbers are generally represented in the form of Institute of Electrical and Electronics Engineers (IEEE) format.The IEEE format uses a sign bit, a mantissa and an exponent for representing the power of 2.The sign bit denotes the sign of the number: a 0 represents a positive value and a 1 denotes a negative value.The mantissa represented in binary after converting into its normalized form. After normalization mantissa, the most significant digit is always 1.The exponent is an integer stored in unsigned binary format after adding a positive ... Read More
ProblemFor given number try to find the range in which that number exists.SolutionHere, we are learning how to find the ranges of a number.The logic that we apply to find range is −lower= (n/10) * 10; /*the arithmetic operators work from left to right*/ upper = lower+10;ExplanationLet number n=45Lower=(42/10)*10 // division returns quotient =4*10 =40Upper=40+10=50Range − lower-upper − 40-50ExampleFollowing is the C program for printing the range of numbers −#include main(){ int n, lower, upper; printf("Enter a number:"); scanf("%d", &n); lower= (n/10) * 10; /*the arithmetic operators work from left to right*/ upper ... Read More
ProblemWhat is the C program to obtain the sum of the first and last digit of the number, if a four-digit number is input through the keyboard?SolutionIn this program, we are taking a four-digit number at run time and trying to find the sum of first and last digit of that four-digit number by using the logic −a=n%10; b=n/1000; result = a + b;Let’s apply this logic to find sum of first and last digit of four-digit number −ExampleFollowing is the C program for finding sum of first and last digit by using divide and modulo operator −#include main(){ ... Read More
ProblemHow the C compiler detect that the file was reached the end for while reading? Explain with a program.Solutionfeof() is a file handling function in C language, which is used to find end of a file.The logic we used for finding end of file is as follows −fp = fopen ("number.txt", "r"); //open a file printf ("file content is"); for (i=0;i
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP