C Articles

Page 16 of 96

C program to generate an electricity bill

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 10K+ Views

In C, generating an electricity bill involves calculating charges based on different rate slabs depending on units consumed. Higher consumption leads to higher per-unit rates, implementing a progressive billing system commonly used by utility companies. Syntax if (units < slab1_limit) { amount = units * rate1; fixed_charge = charge1; } else if (units

Read More

How to add two complex numbers by passing structure to a function in C language?

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 7K+ Views

In C programming, complex numbers can be represented using structures with real and imaginary parts as members. To add two complex numbers, we pass the structure variables to a user-defined function that performs the addition and returns the result. Syntax typedef struct complex { float real; float imag; } complex; complex addition(complex num1, complex num2); Algorithm The following steps outline the process for adding two complex numbers using structures − Step 1: Define a structure with real and imaginary parts Step 2: Declare ...

Read More

What do you mean by static memory allocation in C programming?

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 3K+ Views

Static memory allocation in C refers to memory allocation that happens at compile time. The memory size and location are determined before the program runs, and once allocated, the memory cannot be resized during program execution. Static Memory Compile Time Fixed Size Dynamic Memory Runtime Variable Size Memory Allocation Types Examples: Arrays, Local variables, Global variables Examples: malloc(), calloc(), realloc() Syntax ...

Read More

Write a C program to demonstrate post increment and pre increment operators

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 3K+ Views

In C programming, the increment (++) and decrement (--) operators are used to increase or decrease a variable's value by 1. These operators can be applied in two forms: pre-increment/decrement and post-increment/decrement, which behave differently in expressions. Syntax /* Pre-increment/decrement */ ++variable; --variable; /* Post-increment/decrement */ variable++; variable--; Pre-Increment Operator (++variable) In pre-increment, the operator is placed before the operand. The value is first incremented and then the operation is performed on it. For example − z = ++a; // First: a = a + 1, Then: ...

Read More

Write C program using isupper() function

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 271 Views

In C, the isupper() function is used to check if a character is an uppercase letter (A-Z). It is defined in the ctype.h header file and returns a non-zero value if the character is uppercase, otherwise returns 0. Syntax int isupper(int ch); Parameters: ch − The character to be checked (passed as int). Return Value: Non-zero if the character is uppercase, 0 otherwise. Example 1: Counting Uppercase Letters Using isupper() This program counts the total number of uppercase letters in a string using the isupper() function − #include #include ...

Read More

Write a C program using time.h library function

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 433 Views

The time.h library in C provides various functions to work with date and time. This library allows you to get the current system time, format it, and perform time-related calculations. Syntax #include time_t time(time_t *timer); char *strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr); struct tm *localtime(const time_t *timer); Key Functions time() − Returns the current time as seconds since January 1, 1970 (Unix timestamp) strftime() − Formats time into a string according to specified format specifiers localtime() − Converts time_t to local time structure (struct tm) ...

Read More

Write a C program to check the atexit() function

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 610 Views

The atexit() is a function that allows the user to register a function that has to be called when the program terminates normally. These registered functions are called in the reverse order of their registration. It is a predefined function that is included in the stdlib.h header file. Syntax int atexit(void (*function)(void)); Parameters: function − Pointer to a function that takes no parameters and returns no value. Return Value: Returns 0 on success, non-zero on failure. Example 1: Basic Usage This example demonstrates how atexit() calls registered functions in ...

Read More

Calculate interest amount by using formula in C language

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 984 Views

In C programming, calculating interest on deposited amounts is a common financial calculation. This program demonstrates how to compute the final amount after applying continuous compound interest over a specified period. Syntax A = P * exp((r/100) * t) Where: P = Principal amount (initial deposit) r = Annual interest rate (percentage) t = Time period in years A = Final amount after interest Algorithm START Step 1: Declare double variables P, r, t, A, M Step 2: Read principal amount to be deposited Step 3: Read annual interest rate ...

Read More

Explain the functions fread() and fwrite() used in files in C

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 24K+ Views

In C programming, fread() and fwrite() functions are used for binary file operations to read and write entire structures or data blocks at once. These functions are particularly useful when working with structured data like records. Syntax size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); Parameters ptr − Pointer to the memory location to read/write data size − Size of each element in bytes nmemb − Number of elements to read/write stream − File pointer Return Value Both functions ...

Read More

Concatenating n characters from source string to destination string in C

Bhanu Priya
Bhanu Priya
Updated on 15-Mar-2026 911 Views

In C programming, the strncat() function is used to concatenate a specified number of characters from a source string to the end of a destination string. This function provides more control than strcat() by allowing you to limit the number of characters to be concatenated. Syntax char *strncat(char *dest, const char *src, size_t n); Parameters dest − Pointer to the destination string src − Pointer to the source string n − Maximum number of characters to concatenate Example 1: Basic strncat() Usage This example demonstrates concatenating only 4 characters from ...

Read More
Showing 151–160 of 953 articles
« Prev 1 14 15 16 17 18 96 Next »
Advertisements