Found 1339 Articles for C

Structure declaration in C language

Bhanu Priya
Updated on 08-Mar-2021 10:15:03

13K+ Views

The structure is a collection of different datatype variables, grouped together under a single name. It is a heterogeneous collection of data items that share a common name.Features of structureIt is possible to copy the contents of all structural elements of different data types to another structure variable of its type by using an assignment operator.To handle complex datatypes, it is possible to create a structure within another structure, which is called nested structures.It is possible to pass an entire structure, individual elements of structure, and address of structure to a function.It is possible to create structure pointers.The general form ... Read More

What is a malloc function in C language?

Mandalika
Updated on 20-Feb-2021 10:27:42

7K+ Views

The malloc() function stands for memory allocation, that allocate a block of memory dynamically.It reserves the memory space for a specified size and returns the null pointer, which points to the memory location.malloc() function carries garbage value. The pointer returned is of type void.The syntax for malloc() function is as follows −ptr = (castType*) malloc(size);ExampleThe following example shows the usage of malloc() function. Live Demo#include #include #include int main(){    char *MemoryAlloc;    /* memory allocated dynamically */    MemoryAlloc = malloc( 15 * sizeof(char) );    if(MemoryAlloc== NULL ){       printf("Couldn't able to allocate requested memory");    }else{ ... Read More

How to find a leap year using C language?

Bhanu Priya
Updated on 08-Mar-2021 10:09:07

365 Views

Leap year is a year that consists of 366 days. For every four years, we will experience a leap year.The logic we will implement to find whether the given year by the user through the console is a leap or not −if (( year%400 == 0)|| (( year%4 == 0 ) &&( year%100 != 0)))If this condition is satisfied, then the given year is a leap year. Otherwise, it is not.ExampleFollowing is the C program to check leap year with the help of If condition − Live Demo#include int main(){    int year;    printf("Enter any year you wish ... Read More

C program to print multiplication table by using for Loop

Bhanu Priya
Updated on 02-Sep-2023 13:18:25

81K+ 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.AlgorithmGiven below is an algorithm to print multiplication table by 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

How to write a simple calculator program using C language?

Bhanu Priya
Updated on 21-Jan-2025 10:58:52

21K+ 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. Begin by writing the C code to create a simple calculator. Then, follow the algorithm given below to write a C program. Algorithm Step 1: Declare variables Step 2: Enter any operator at runtime Step 3: Enter any two integer values at runtime Step 4: Apply switch case to select the operator: // case '+': result = num1 + num2; ... Read More

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

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

313 Views

The formula for finding profit is as follows if the selling price is greater than cost price −profit=sellingPrice-CosePrice;The formula for finding loss is as follows if cost price is greater than selling price −loss=CostPrice-SellingPriceNow, apply this logic in the program and try to find whether the person gets a profit or loss after buying any article −ExampleFollowing is the C program to find the profit or loss − Live Demo#include int main(){    float CostPrice, SellingPrice, Amount;    printf(" Enter the product Cost : ");    scanf("%f", &CostPrice);    printf(" Enter the Selling Price) : ");    scanf("%f", &SellingPrice);    if ... Read More

Convert Fahrenheit to Celsius using C Program

Bhanu Priya
Updated on 04-Nov-2023 01:56:40

57K+ Views

The logic that we implement to convert Fahrenheit to Celsius is as follows −celsius = (fahrenheit - 32)*5/9;AlgorithmRefer to the algorithm given below to convert Fahrenheit to Celsius.Step 1: Declare two variables farh, cels Step 2: Enter Fahrenheit value at run time Step 3: Apply formula to convert         Cels=(farh-32)*5/9; Step 4: Print celsExampleFollowing is the C program to convert Fahrenheit to Celsius − #include int main(){    float fahrenheit, celsius;    //get the limit of fibonacci series    printf("Enter Fahrenheit: ");    scanf("%f",&fahrenheit);    celsius = (fahrenheit - 32)*5/9;    printf("Celsius: %f ", celsius);    return 0; }OutputWhen the above program is executed, it produces the following result −Enter Fahrenheit: 100 Celsius: 37.777779

How to write the temperature conversion table by using function?

Bhanu Priya
Updated on 08-Mar-2021 09:53:40

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 the table by using a function.ExampleFollowing is the C program for temperature conversion − Live Demo#include float conversion(float); int main(){    float fh,cl;    int begin=0,stop=300;    printf("Fahrenheit \t Celsius");// display conversion table heading    printf("----------\t-----------");    fh=begin;    while(fh

Explain the variable declaration, initialization and assignment in C language

Bhanu Priya
Updated on 08-Mar-2021 07:16:24

11K+ Views

The main purpose of variables is to store data in memory. Unlike constants, it will not change during the program execution. However, its value may be changed during execution.The variable declaration indicates that the operating system is going to reserve a piece of memory with that variable name.Variable declarationThe syntax for variable declaration is as follows −type variable_name;ortype variable_name, variable_name, variable_name;For example, iInt a, b; float c; double d;Here, a, b, c, d are variables. The int, float, double are the data types.Variable initializationThe syntax for variable initialization is as follows −data type variablename=value;For example, int width, height=20; char letter='R'; ... Read More

Accessing variables of Int and Float without initializing in C

Bhanu Priya
Updated on 08-Mar-2021 06:48:26

2K+ Views

ProblemDeclare int and float variables without initializing and try to print their values in C language. Explain what will happen.SolutionIf a variable is declared but not initialized or uninitialized and if those variables are trying to print, then, it will return 0 or some garbage value.Whenever we declare a variable, a location is allocated to that variable. The only thing is with the help of initialization, we are trying to occupy the memory location which is already allotted while declaration.But in the below program, we are not initializing the values in the memory locations which are reserved. But, by default, ... Read More

Advertisements