Found 1401 Articles for C

Differentiate between array and structures in C

Bhanu Priya
Updated on 02-Sep-2021 13:17:30

232 Views

The major differences between an array and a structure in C programming language are as follows −ArraysStructuresAn array is a single entity representing a collection of data items of same data types.A structure is a single entity representing a collection of data items of different data types.Individual entries in an array are called elements.Individual entries in a structure are called members.An array declaration reserves enough memory space for its elements.The structure definition reserves enough memory space for its members.There is no keyword to represent arrays but the square braces [] preceding the variable name tells us that we are dealing ... Read More

C program to store inventory system using structures

Bhanu Priya
Updated on 01-Sep-2021 13:18:41

7K+ Views

Structure is a collection of different datatype variables, grouped together under a single name.Features of structureThe features of structure in the C programming language are as follows −It is possible to copy the contents of all the structure elements of different datatypes to another structure variable of its type by using an assignment operator.For handling the complex datatypes, it is better to create structure within another structure, which is called nested structures.It is possible to pass an entire structure, individual elements of structure and an address of structure to a function.It is possible to create structure pointers.ProgramFollowing is the C ... Read More

C program to sort names in alphabetical order using structures

Bhanu Priya
Updated on 02-Sep-2023 13:54:56

4K+ Views

Structure is a collection of different datatype variables, grouped together under a single name.Features of structureThe features of structure in the C programming language are as follows −It is possible to copy the contents of all the structure elements of different datatypes to another structure variable of its type by using an assignment operator.For handling the complex datatypes, it is better to create structure within another structure, which is called nested structures.It is possible to pass an entire structure, individual elements of structure and an address of structure to a function.It is possible to create structure pointers.Declaration and initialization of ... Read More

C program to compare if the two matrices are equal or not

Bhanu Priya
Updated on 01-Sep-2021 13:13:28

2K+ Views

The user has to enter the order of two matrices and elements of two matrices. Then, these two matrix are compared.If both matrix elements and size are equal, then it displays that the two matrices are equal.If size of matrix is equal but the elements are not equal, then it displays that the matrix can be compared but is not equal.If the size and elements are not matched, then it displays that the matrices cannot be compared.ProgramFollowing is the C program to compare if the two matrices are equal or not −#include #include main(){    int A[10][10], B[10][10]; ... Read More

C program to sort all columns and rows of matrix

Bhanu Priya
Updated on 01-Sep-2021 13:10:15

4K+ Views

ProblemWrite a code to sort all the rows of matrix in an ascending order and all columns in the descending order. The size of matrix and elements of matrix are given by user at runtime.SolutionThe solution to sort all the rows of matrix in an ascending order and all columns in the descending order in the C programming language is explained below −The logic used to sort the rows in an ascending order is as follows −for (i=0;i

C program to interchange the diagonal elements in given matrix

Bhanu Priya
Updated on 01-Sep-2021 13:07:55

854 Views

ProblemWe need to write a code to interchange the main diagonal elements with the secondary diagonal elements. The size of the matrix is given at runtime.If the size of matrix m and n values are not equal, then it prints that the given matrix is not a square.Only a square matrix can interchange the main diagonal elements and can interchange with the secondary diagonal elements.SolutionThe solution to write a C program to interchange the diagonal elements in given matrix is as follows −The logic to interchange the diagonal elements is explained below −for (i=0;i

C program to perform operations on two halves’ in a single array

Bhanu Priya
Updated on 01-Sep-2021 13:05:11

552 Views

ProblemWrite a program to accept a one-dimensional array of N elements and split into two halves. Later on, sort the first half in an ascending order and the second half into descending order.SolutionThe solution to perform the two operations on two halves’ in a single array in C programming language is explained below −The logic used to sort the first half in an ascending order is as follows −for (i=0; i

C program to find the areas of geometrical figures using switch case

Bhanu Priya
Updated on 01-Sep-2021 13:02:24

5K+ Views

ProblemFind the areas of rectangle, square, triangle, circle by using the switch case statement, User need to enter base, height, side, radius, breadth and length at runtime to calculate the areas of all geometrical figures.SolutionThe solution to find the areas of rectangle, square, triangle, circle by using the switch case statement is explained below −FormulaeThe formulae for finding the areas of the respective geometrical figures are as follows −Area of rectangle = breadth *length;Area of square = side * side;Area of circle = 3.142*radius*radius;Area of triangle = 0.5 *base*height;ExampleFollowing is the C program to find the areas of rectangle, square, ... Read More

C program to find the second largest and smallest numbers in an array

Bhanu Priya
Updated on 13-Sep-2023 14:56:13

28K+ Views

Enter the array elements and then, arrange the numbers in descending order by using the swapping technique. Later on, with the help of an index location, try to print the second largest and the second smallest element in an array.An array is used to hold the group of common elements under one name.The array operations in C programming language are as follows −InsertDeleteSearchAlgorithmGiven below is an algorithm to find the second largest and the second smallest numbers in an array −Step 1 − Declare and read the number of elements.Step 2 − Declare and read the array size at runtime.Step ... Read More

C program to generate the value of x power n using recursive function

Bhanu Priya
Updated on 01-Sep-2021 12:56:48

3K+ Views

ProblemCompute the value of xn , where x and n both are the inputs given by the user at runtimeSolutionThe solution to generate the value of x power n by using the recursive function in C programming language is as follows −The logic to find xn is mentioned below −//Calling function: Xpow=power(x, n); //Called function: if (n==1)    return(x); else if ( n%2 == 0)    return (pow(power(x, n/2), 2)); /*if n is even*/ else    return (x*power(x, n-1));AlgorithmRefer an algorithm given below to generate the value of x power n by using the recursive function.Step 1 − Read long ... Read More

Previous 1 ... 5 6 7 8 9 ... 141 Next
Advertisements