Found 1339 Articles for C

What are the different categories of functions in C Programming?

Sindhura Repala
Updated on 21-Jan-2025 16:13:15

31K+ Views

Functions are categorized bases on the presence or absences of arguments and whether they return a value. A user-defined function is one that is defined by the user when writing any program, as opposed to library functions that have predefined definitions. To meet specific requirements, the user must develop their own functions. Such functions must be properly defined by the user. A function is a block of code designed to perform a specific task. It is written once and can be reused multiple times as needed by the programmer. ... Read More

What are the different types of functions in C Programming?

Bhanu Priya
Updated on 09-Mar-2021 07:06:23

14K+ Views

Functions are broadly classified into two types which are as follows −predefined functionsuser defined functionsPredefined (or) library functionsThese functions are already defined in the system libraries.Programmer can reuse the existing code in the system libraries which is helpful to write error free code.User must be aware of syntax of the function.For instance, sqrt() function is available in math.h library and its usage is y= sqrt (x), where x= number must be positive.If x value is 25, i.e., y = sqrt (25) then ‘y’ = 5.In the same way, printf() is available in stdio.h library and clrscr() is available in conio.h ... Read More

How to write a C program to find the roots of a quadratic equation?

Bhanu Priya
Updated on 10-Dec-2024 13:10:44

152K+ Views

Problem Applying the software development method to solve any problem in C Language. Solution Find roots of a quadratic equation, ax2+bx+c. There will be 2 roots for given quadratic equation. Analysis Input − a, b, c values Output − r1, r2 values Procedure $r_{1}=\frac{-b+\sqrt{b^2-4ac}}{2a}$ $r_{2}=\frac{-b-\sqrt{b^2-4ac}}{2a}$ Design (Algorithm) Start Read a, b, c values Compute d = b2 4ac if d > 0 then ... Read More

Convert vowels from upper to lower or lower to upper using C program

Bhanu Priya
Updated on 24-Mar-2021 14:29:19

2K+ Views

An array of characters is called a string.DeclarationFollowing is the declaration for an array −char stringname [size];For example − char a[50]; string of length 50 charactersInitializationUsing single character constant −char a[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char a[10] = "Hello":;AccessingThere is a control string "%s" used for accessing the string till it encounters ‘\0’.The logic used to convert vowels from upper to lower or lower to upper is −for(i=0;string[i]!='\0';i++){    if(string[i]=='a'||string[i]=='e'||string[i]=='i'||string[i]=='o'||string[i]=='u'){       string[i]=toupper(string[i]);    } } printf("The result string with converted vowels is : "); puts(string);ProgramFollowing is the C program using conversion functions ... Read More

C Program to find the given number is strong or not

Sindhura Repala
Updated on 23-Jan-2025 10:53:45

42K+ Views

Recursive Factorial Calculation A strong number is a number, where the sum of the factorial of its digits equals the number itself. In C programming, a factorial is the product of all positive integers less than or equal to a given number. To calculate the factorial of a number, we use a recursive function with the argument N. This function will repeatedly call itself with a decremented value of N, multiplying the results until it reaches 1. 123!= 1!+2!+3!  =1+2+6 =9 In this case, 123 is not a strong number because the sum of the factorial of its digits ... Read More

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

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

17K+ 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

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 − 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

53K+ 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

6K+ 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

44K+ 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

Advertisements