Found 1401 Articles for C

Explain write mode operation of files in C language

Bhanu Priya
Updated on 24-Mar-2021 13:22:38

703 Views

File is collection of records or is a place on hard disk, where data is stored permanently.Need of filesEntire data is lost when a program terminates.Storing in a file preserves the data even if, the program terminates.If you want to enter a large amount of data, normally it takes a lot of time to enter them all.We can easily access the content of files by using few commands.You can easily move your data from one computer to another without changes.By using C commands, we can access the files in different ways.Operations on filesThe operations on files in C programming language ... Read More

How to separate even and odd numbers in an array by using for loop in C language?

Bhanu Priya
Updated on 24-Mar-2021 13:18:59

2K+ Views

An array is a group of related data items that are stored with single name.For example, int student[30]; //student is an array name that holds 30 collection of data items with a single variable nameOperations of arraySearching − It is used to find whether particular element is present or notSorting − It helps in arranging the elements in an array either in ascending or descending order.Traversing − It processes every element in an array sequentially.Inserting − It helps in inserting the elements in an array.Deleting − It helps in deleting an element in an array.The logic to find even numbers ... Read More

How to perform arithmetic operations on two-dimensional array in C?

Bhanu Priya
Updated on 24-Mar-2021 13:17:01

3K+ Views

An array is a group of related data items that are stored with single name.For example, int student[30]; //student is an array name that holds 30 collection of data items with a single variable nameOperations of arraySearching − It is used to find whether particular element is present or notSorting − It helps in arranging the elements in an array either in ascending or descending order.Traversing − It processes every element in an array sequentially.Inserting − It helps in inserting the elements in an array.Deleting − It helps in deleting an element in an array.The logic applied to perform arithmetic ... Read More

How to perform the arithmetic operations on arrays in C language?

Bhanu Priya
Updated on 24-Mar-2021 13:12:55

3K+ Views

An array is a group of related data items that are stored with single name.For example, int student[30]; //student is an array name that holds 30 collection of data items with a single variable nameOperations of arraySearching − It is used to find whether particular element is present or notSorting − It helps in arranging the elements in an array either in ascending or descending order.Traversing − It processes every element in an array sequentially.Inserting − It helps in inserting the elements in an array.Deleting − It helps in deleting an element in an array.The logic to perform all arithmetic ... Read More

C program to replace all occurrence of a character in a string

Bhanu Priya
Updated on 24-Mar-2021 13:12:15

5K+ Views

Enter a string at run time and read a character to replace at console. Then, finally read a new character that has to be placed in place of an old character where ever it occurs inside the string.Program1Following is the C program to replace all occurrence of a character − Live Demo#include #include int main(){    char string[100], ch1, ch2;    int i;    printf("enter a string : ");    gets(string);    printf("enter a character to search : ");    scanf("%c", &ch1);    getchar();    printf("enter a char to replace in place of old : ");    scanf("%c", &ch2);    for(i = 0; i

How to find the product of given digits by using for loop in C language?

Bhanu Priya
Updated on 24-Mar-2021 13:11:50

3K+ Views

The user has to enter a number, then divide the given number into individual digits, and finally, find the product of those individual digits using for loop.The logic to find the product of given digits is as follows −for(product = 1; num > 0; num = num / 10){    rem = num % 10;    product = product * rem; }Example1Following is the C program to find the product of digits of a given number by using for loop − Live Demo#include int main(){    int num, rem, product;    printf("enter the number : ");    scanf("%d", & num); ... Read More

How to swap two arrays without using temporary variable in C language?

Bhanu Priya
Updated on 24-Mar-2021 13:09:15

4K+ Views

Swap two arrays without using Temp variable. Here, we are going to use Arithmetic Operators and Bitwise Operators instead of third variable.The logic to read the first array is as follows −printf("enter first array ele:"); for(i = 0; i < size; i++){    scanf("%d", &first[i]); }The logic to read the second array is as follows −printf("enter first array ele:"); for(i = 0; i < size; i++){    scanf("%d", &first[i]); }The logic to swap the two arrays without using a third variable is as follows −for(i = 0; i < size; i++){    first[i] = first[i] + sec[i];    sec[i] = ... Read More

C program to find palindrome number by using while loop

Bhanu Priya
Updated on 24-Mar-2021 13:05:23

11K+ Views

Palindrome number is a number which remains same when it reverses. In C language, the user is allowed to enter any positive integer and to check, whether the given number is palindrome number or not by using the while loop.Example1Following is the C Program to find Palindrome number by using the while loop − Live Demo#include int main(){    int num, temp, rem, rev = 0;    printf("enter a number:");    scanf("%d", &num);    temp = num;    while ( temp > 0){       rem = temp %10;       rev = rev *10+ rem;     ... Read More

C program to convert centimeter to meter and kilometer

Bhanu Priya
Updated on 24-Mar-2021 13:03:38

4K+ Views

Here, the user has to enter the length in centimeters (cm), and then, convert the length into meters (m), and kilometer (km).1 Meter = 100 Centimeters 1 Kilometer = 100000 CentimetersAlgorithmRefer an algorithm given below to convert centimeter into meter and kilometer respectively.Step 1: Declare variables. Step 2: Enter length in cm at runtime. Step 3: Compute meter by using the formula given below.    meter = centim / 100.0; Step 4: Compute kilometer by using the formula given below.    kilometer = centim / 100000.0 Step 5: Print meter. Step 6: Print kilometeExample1Following is the C program to convert ... Read More

C program to find the sum of arithmetic progression series

Bhanu Priya
Updated on 24-Mar-2021 12:55:26

1K+ Views

ProblemFind the sum of an arithmetic progression series, where the user has to enter first number, total number of elements and the common difference.SolutionArithmetic Progression (A.P.) is a series of numbers in which the difference of any two consecutive numbers is always the same. Here, total number of elements is mentioned as Tn.Sum of A.P. Series: Sn = n/2(2a + (n – 1) d) Tn term of A.P. Series: Tn = a + (n – 1) dAlgorithmRefer an algorithm given below to find the arithmetic progression.Step 1: Declare variables. Step 2: Initialize sum=0 Step 3: Enter first number of series ... Read More

Advertisements