Programming Articles

Page 945 of 2547

How to count number of vowels and consonants in a string in C Language?

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

In C programming, counting vowels and consonants in a string is a common string manipulation task. We iterate through each character and check if it's a vowel (a, e, i, o, u) or consonant using conditional statements. Syntax // Check if character is vowel if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') vowels++; else if(isalpha(ch)) ...

Read More

C program to print multiplication table by using for Loop

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

A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. In this tutorial, we will learn how to print a multiplication table using a for loop in C. Syntax for (initialization; condition; increment/decrement) { // statements to be executed } Algorithm Given below is an algorithm to print multiplication table using for loop in C language − Step 1: Enter a number to print table at runtime. Step 2: Read that number from keyboard. Step 3: Using for loop print number*i 10 times. // for(i=1; i

Read More

How to write a simple calculator program using C language?

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

A calculator is a simple tool that helps us to calculate mathematical operations easily and quickly. A basic calculator can perform simple arithmetic operations like subtraction, addition, multiplication, and division. In C programming, we can create a calculator using switch-case statements to handle different operators and perform calculations based on user input. Syntax switch(operator) { case '+': result = num1 + num2; break; case '-': result = num1 - num2; break; case '*': result = num1 * num2; break; case ...

Read More

Write a C program to find out profit or loss in buying an article

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

In business transactions, calculating profit or loss is essential to determine the financial outcome. Profit occurs when the selling price exceeds the cost price, while loss occurs when the cost price is greater than the selling price. Syntax if (selling_price > cost_price) { profit = selling_price - cost_price; } else if (cost_price > selling_price) { loss = cost_price - selling_price; } else { // No profit, no loss } Formulas The formulas for calculating profit and loss are − Profit: ...

Read More

How to write the temperature conversion table by using function?

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

Temperature conversion is nothing but converting Fahrenheit temperature to Celsius or Celsius to Fahrenheit. In this programming, we are going to explain how to convert the Fahrenheit temperature to Celsius temperature and how to represent the same in the form of a table by using a function. Syntax // Function to convert Fahrenheit to Celsius float fahrenheitToCelsius(float fahrenheit); // Function to convert Celsius to Fahrenheit float celsiusToFahrenheit(float celsius); Example 1: Fahrenheit to Celsius Conversion Table Following is the C program for temperature conversion table from Fahrenheit to Celsius − ...

Read More

Explain the variable declaration, initialization and assignment in C language

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

In C programming, variables are named storage locations in memory that hold data values. Unlike constants, variables can have their values modified during program execution. Before using any variable, it must be declared to inform the compiler about its data type and name. Syntax data_type variable_name; data_type variable_name = initial_value; data_type var1, var2, var3; Variable Declaration Variable declaration tells the compiler to reserve memory space for a variable with a specific data type. The syntax is − type variable_name; or for multiple variables of the same type − ...

Read More

Accessing variables of Int and Float without initializing in C

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

When we declare variables in C without initializing them, their values are unpredictable. This article demonstrates what happens when we try to access uninitialized int and float variables and explains the underlying memory behavior. Syntax data_type variable_name; // Declaration without initialization Understanding Uninitialized Variables When a variable is declared but not initialized, the following occurs − Memory is allocated for the variable during declaration The memory location contains whatever data was previously stored there This results in garbage values − unpredictable leftover data from previous program executions The actual ...

Read More

Given an example of C pointer addition and subtraction

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

Pointer arithmetic is a fundamental concept in C programming that allows you to perform mathematical operations on pointer variables. Two important operations are pointer addition and subtraction, which help navigate through memory addresses. Syntax /* Pointer Addition */ new_address = current_address + n; /* Pointer Subtraction */ new_address = current_address - n; Where n is the number of elements to move, and the actual byte offset is calculated as: n * sizeof(data_type) C Pointer Addition Pointer addition involves adding an integer value to a pointer. The result is a new memory address ...

Read More

Compute sum of all elements in 2 D array in C

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

In C programming, computing the sum of all elements in a 2D array involves traversing through each element using nested loops and accumulating the values. This is a fundamental operation when working with matrices and tabular data. Syntax datatype array_name[rows][columns]; For example: int arr[3][4]; creates a 2D array with 3 rows and 4 columns, containing 12 elements total. Example 1: Sum of All Elements Following is the C program to calculate the sum of all elements in a 2D array − #include int main() { ...

Read More

Explain volatile and restrict type qualifiers in C with an example

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

Type qualifiers in C add special attributes to existing data types to control how variables are accessed and optimized by the compiler. The two important type qualifiers are volatile and restrict, which help with memory management and compiler optimization. volatile Prevents compiler optimizations restrict Enables compiler optimizations const Read-only qualifier Type Qualifiers in C Syntax volatile ...

Read More
Showing 9441–9450 of 25,466 articles
« Prev 1 943 944 945 946 947 2547 Next »
Advertisements