Found 1401 Articles for C

C Program on two-dimensional array initialized at run time

Bhanu Priya
Updated on 08-Mar-2021 06:18:38

295 Views

ProblemCalculate the sum and product of all elements in an array by using the run-time compilation.SolutionA two-dimensional array is used in situations where a table of values have to be stored (or) in matrices applicationsThe syntax is as follows −datatype array_ name [rowsize] [column size];For example, int a[5] [5];Number of elements in array = rowsize *columnsize = 5*5 = 25ExampleFollowing is the C program to calculate the sum and product of all elements in an array by using the run-time compilation − Live Demo#include void main(){    //Declaring the array - run time//    int A[2][3], B[2][3], i, j, sum[i][j], product[i][j]; ... Read More

How to print the elements in a reverse order from an array in C?

Bhanu Priya
Updated on 08-Mar-2021 06:16:34

8K+ Views

Try to print the elements in reverse order by following an algorithm given below −Step1 − Declare an array of size 5Step 2 − Enter the 5 elements in memory using for loopStep 3 − Display elements in reverse orderBy decrementing for loopThe only logic is to reverse the elements is For loop −for(i=4;i>=0;i--){    //Displaying O/p//    printf("array[%d] :", i);    printf("%d", array[i]); }ExampleFollowing is the C program to reverse the elements − Live Demo#include void main(){    //Declaring the array - run time//    int array[5], i;    //Reading elements into the array//    printf("Enter elements into the array: ... Read More

Explain volatile and restrict type qualifiers in C with an example

Bhanu Priya
Updated on 08-Mar-2021 06:13:02

780 Views

Type qualifiers add special attributes to existing data types in C programming language.There are three type qualifiers in C language and volatile and restrict type qualifiers are explained below −VolatileA volatile type qualifier is used to tell the compiler that a variable is shared. That is, a variable may be referenced and changed by other programs (or) entities if it is declared as volatile.For example, volatile int x;RestrictThis is used only with pointers. It indicates that the pointer is only an initial way to access the deference data. It provides more help to the compiler for optimization.Example ProgramFollowing is the ... Read More

What are the C library functions?

Bhanu Priya
Updated on 25-Oct-2023 14:49:59

23K+ Views

Library functions are built-in functions that are grouped together and placed in a common location called library. Each function here performs a specific operation. We can use this library functions to get the pre-defined output. All C standard library functions are declared by using many header files. These library functions are created at the time of designing the compilers. We include the header files in our C program by using #include. Whenever the program is run and executed, the related files are included in the C program. Header File Functions Some of the header file functions are as follows − ... Read More

What are the limitations of array in C language?

Bhanu Priya
Updated on 13-Mar-2021 11:49:17

9K+ Views

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

What is a multidimensional array? Explain with program

Bhanu Priya
Updated on 13-Mar-2021 11:48:04

174 Views

C language allows arrays of three (or) more dimensions. This is a multidimensional array. The exact limit is determined by compiler.SyntaxThe syntax is as follows −datatype arrayname [size1] [size2] ----- [sizen];For example, for three – dimensional array −int a[3] [3] [3];Number of elements = 3*3*3 = 27 elementsExampleFollowing is the C program for multidimensional array − Live Demo#include main ( ){    int a[2][2] [2] = {1,2,3,4,5,6,7,8};    int i,j,k;    printf ("elements of the array are :");    for ( i=0; i

Explain recursive function in C language with program

Bhanu Priya
Updated on 13-Mar-2021 11:46:38

459 Views

Recursive Functions is the process of defining something in terms of itself. It is a function that calls itself again in the body of the function.A function fact ( ), that computes the factorial of an integer ‘N’ ,which is the product of all whole numbers from 1 to N.When fact ( ) is called with an argument of 1 (or) 0, the function returns 1. Otherwise, it returns the product of n*fact (n-1), this happens until ‘n’ equals 1.Fact (5) =5* fact (4)    =5*4*3* fact (3)    =5*4*3*2* fact (2)    =5*4*3*2*1 fact (1)    =5*4*3*2*1    = ... Read More

Explain top-down design and structure chart of function in C language

Bhanu Priya
Updated on 13-Mar-2021 11:43:10

1K+ Views

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

How floats are stored in C compiler?

Bhanu Priya
Updated on 13-Mar-2021 11:41:56

669 Views

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

What are the loop control statements in C language? Explain with flow chart and program

Bhanu Priya
Updated on 13-Mar-2021 11:35:21

6K+ Views

Loop control statements are used to repeat set of statements. They are as follows −for loopwhile loopdo-while loopfor loopThe syntax is as follows −for (initialization ; condition ; increment / decrement){    body of the loop }Flow chartThe flow chart for loop is as follows −Initialization is usually an assignment statement that is used to set the loop control variable.The condition is a relational expression that determines when the loop will exit.The increment/decrement part defines how the loop control variable will change each time loop is repeated.Loop continues to execute as long as the condition is true.Once the condition is ... Read More

Advertisements