Difference Between memcmp and memicmp Functions in C Language

Bhanu Priya
Updated on 15-Mar-2021 09:58:55

441 Views

Memcmp() and memicmp() compares first n bytes of two blocks of memory.memcmp() performs comparison as unsigned characters.memicmp() performs comparison as characters but, ignore upper case or lower case letters.Both functions return an integer value.Two memory buffers are equal (returns 0).First buffer is greater than second (returns >0).First buffer is less than second(returns0)       printf("buffer st1 is bigger than buffer st2");    if(x

Count Vowels, Digits, Spaces, and Consonants in C

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

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

Display Lower Triangle Elements in a 3x3 2D Array in C

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

416 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

Sort an Array of Ten Elements in Ascending Order using C

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

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

Check if a Number is Perfect in C

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

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

Characteristics and Operations of Arrays in C Language

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

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

Monolithic and Modular Programming in C Language

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

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

Delete Duplicate Numbers in an Array using C

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

1K+ Views

Let the user enter the numbers in an array, which contains duplicate elements.Now, let’s write a code to delete the repeated numbers or elements in an array and make an array with unique elements without duplicatesFor example, An example is explained below −User input is 12, 30, 12, 45, 67, 30.Output is 12, 30, 45, 67 (after deleting duplicates).ProgramFollowing is the C program to delete the duplicate numbers in an array − Live Demo#include #define MAX 100 // Maximum size of the array int main(){    int array[MAX]; // Declares an array of size 100    int size;    int ... Read More

Convert Upper Case to Lower and Vice Versa in C

Bhanu Priya
Updated on 15-Mar-2021 09:39:55

2K+ Views

Converting upper to lower and lower to upper is generally termed as toggle.Toggle each character means, in a given string, the lower letter is print in upper form and upper case is print in lower letter respectively.ProgramThe C program to convert upper case to lower and lower case to upper is given below − Live Demo#include #define MAX 100 void toggle(char * string); int main(){    char string[MAX];    printf("enter the string need to be toggle :");    gets(string);    toggle(string);    printf("final string after toggling is:");    printf("%s", string);    return 0; } void toggle(char * string){    int ... Read More

Swap Two Numbers Without Using a Temporary Variable in C

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

4K+ Views

With the help of addition and subtraction operations, we can swap two numbers from one memory location to another memory location.AlgorithmThe algorithm is explained below −STARTStep 1: Declare 2 variables x and y. Step 2: Read two numbers from keyboard. Step 3: Swap numbers. //Apply addition and subtraction operations to swap the numbers.    i. x=x+y    ii. y=x-y    iii. x=x-y Step 4: Print x and y values.ProgramFollowing is the C program which explains swapping of two numbers without using third variable or a temporary variable −#include int main(){    int x, y;    printf("enter x and y values:"); ... Read More

Advertisements