Found 1401 Articles for C

Explain the different sections in C language

Bhanu Priya
Updated on 15-Mar-2021 10:01:41

8K+ Views

C program is defined by set of protocols that are to be followed by a programmer, while writing the code.SectionsThe complete program is divided into different sections, which are as follows −Documentation Section − Here, we can give commands about program like author name, creation or modified date. The information written in between/* */ or // is called as comment line. These lines are not considered by the compiler while executing.Link section − In this section, header files that are required to execute the program are included.Definition section − Here, variables are defined and initialised.Global declaration section − In this ... Read More

What is the use of randomize and srand functions in C language?

Bhanu Priya
Updated on 15-Mar-2021 10:00:14

246 Views

If we are generating random numbers in a program, it is necessary to control the series of numbers.The randomize() and srand() functions are used to seed the random number generator.The process of assigning the random number generators starting number is called seeding the generators.The randomize() uses PC’s clock to produce a random seed.srand() allows us to specify the random number generator’s starting value.ProgramGiven below is the C program on rand − Live Demo#include int main(){    // create same sequence of    // random numbers on every time the program runs    for(int i = 0; i

What are macros in C programming language?

Bhanu Priya
Updated on 10-Aug-2021 19:21:24

4K+ Views

Macro substitution is a mechanism that provides a string substitution. It can be achieved through "#deifne".It is used to replace the first part with the second part of the macro definition, before the execution of the program.The first object may be a function type or an object.SyntaxThe syntax for macros is as follows −#define first_part second_partProgramIn the program for every occurrence of first_part is replaced with the second_part throughout the code. Live Demo#include #define square(a) a*a int main(){ int b, c; printf("enter b element:"); scanf("%d", &b); c=square(b);//replaces c=b*b before execution of program printf("%d", c); return 0; }OutputYou will see the following ... Read More

C Program to count vowels, digits, spaces, consonants using the string concepts

Bhanu Priya
Updated on 15-Mar-2021 09:56:06

8K+ Views

An array of characters (or) collection of characters is called a string.DeclarationRefer the declaration given below −char stringname [size];For example − char a[50]; string of length 50 characters.InitializationThe initialization is as follows −Using 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 count number of vowels is as follows −if(string[i]=='a'||string[i]=='e'||string[i]=='i'||    string[i]=='o'||string[i]=='u')//checking the char is vowel vowel=vowel+1;The logic used to count number of digits is as follows −if(string[i]=='0'||string[i]=='1'||string[i]=='2'|| string[i]=='3'||string[i]=='4'||string[i]=='5'|| string[i]=='6'||string[i]=='7'||string[i]=='8'||string[i]=='9') digit=digit+1;The logic used to ... Read More

C program to display only the lower triangle elements in a 3x3 2D array

Bhanu Priya
Updated on 15-Mar-2021 09:54:15

289 Views

Let’s take the input of 3x3 matrix, means total 9 elements, in 2D array using keyboard at runtime.With the help of it and for loops, we can display only lower triangle in 3X3 matrix.The logic to print lower triangle elements is as follows −for(i=0;i=2nd index          printf("%d",array[i][j]);       else          printf(" "); //display blank in non lower triangle places    }    printf(""); }ProgramFollowing is the C program to display only the lower triangle elements in a 3x3 2D array − Live Demo#include int main(){    int array[3][3],i,j;    printf("enter 9 numbers:");    for(i=0;i

C program to sort an array of ten elements in an ascending order

Bhanu Priya
Updated on 15-Mar-2021 09:53:00

13K+ Views

An array is a group of related data items that are stored with single name.For example, int student[30];Here, student is an array name which holds 30 collection of data items, with a single variable name.OperationsThe operations of an array are explained below −Searching − It is used to find whether a particular element is present or not.Sorting − Helps in arranging the elements in an array either in ascending or descending order.Traversing − Processing every element in an array, sequentially.Inserting − Helps in inserting the elements in an array.Deleting − Helps in deleting an element in an array.In this program, ... Read More

C program to find if the given number is perfect number or not

Bhanu Priya
Updated on 15-Mar-2021 09:50:23

4K+ Views

Perfect number is the number; whose sum of factors is equal to 2*number.AlgorithmAn algorithm is explained below −START Step 1: declare int variables and initialized result=0. Step 2: read number at runtime. Step 3: for loop i=1;i

Explain the characteristics and operations of arrays in C language

Bhanu Priya
Updated on 15-Mar-2021 09:45:42

8K+ Views

An array is a homogeneous sequential collection of data items over a single variable name.For example, int student[30];Here, student is an array name holds 30 collection of data item, with a single variable name.CharacteristicsThe characteristics of arrays are as follows −An array is always stored in consecutive memory location.It can store multiple value of similar type, which can be referred with single name.The pointer points to the first location of memory block, which is allocated to the array name.An array can either be an integer, character, or float data type that can be initialised only during the declaration.The particular element ... Read More

Explain bit field in C language by using structure concept

Bhanu Priya
Updated on 15-Mar-2021 09:43:46

383 Views

Bit field is used for specifying the size of variable in terms of bits. Generally, it is defined inside a structure.Bit field: 1 byte=8 bitsFor example, An example is explained below −Struct info{    int x:2; };Here, x is occupying 2bits.It is invalid to assign any value to a bit field out of its range.We cannot use scanf statements to input the value of bit field because, size of and address operator cannot apply to bit field.The data types that we can assign to a bit field can be int, signed int, unsigned int.ProgramFollowing is the C program for unsigned ... Read More

Explain monolithic and modular programming in C language

Bhanu Priya
Updated on 15-Mar-2021 09:41:44

3K+ Views

The difference between monolithic programming and modular programming along with the advantages and disadvantage are explained below in detail.Monolithic programmingIf, we write an entire program in a single function that is in main function then, you call it as a monolithic type of programming. But, it is not a good style of writing entire logic in a single function.DisadvantagesThe disadvantages of monolithic programming include −Program seems to be very large and complex.Debugging, testing and maintenance of a program is very difficult.Modular ProgrammingIf the program is divided into number of functional parts, then we use to call it as modular programming.If ... Read More

Advertisements