Found 1401 Articles for C

Convert Fahrenheit to Celsius using C Program

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

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

What are string literals in C language?

Bhanu Priya
Updated on 08-Mar-2021 07:21:38

4K+ Views

A string literal is a sequence of chars, terminated by zero. For example, Char * str = "hi, hello"; /* string literal */String literals are used to initialize arrays.char a1[] = "xyz"; /* a1 is char[4] holding {'x', 'y', 'z', '\0'} */ char a2[4] = "xyz"; /* same as a1 */ char a3[3] = "xyz"; /* a1 is char[3] holding {'x, 'y', 'z'}, missing the '\0' */String literals are not modifiable if you try to alter their values, which leads to undefined behavior.char* s = "welcome"; s[0] = 'W'; /* undefined behaviour */Always try to denote string literals as such, ... Read More

Explain the variable declaration, initialization and assignment in C language

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

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

What are different format specifiers used in C language?

Bhanu Priya
Updated on 08-Mar-2021 07:07:43

543 Views

Format specifiers are used for input-output (I/O) operations. With the help of a format specifier, the compiler can understand what type of data is in I/O operation.There are some elements that affect the format specifier. They are as follows −A minus symbol (-): Left alignment.The number after % specifies the minimum field width. If the string is less than the width, it will be filled with spaces.Period (.) − Separate field width and precision.Format specifiersHere is the list of some format specifiers −SpecifierUsed for%ca single character%sa string%hishort (signed)%hushort (unsigned)%Lflong double%nprints nothing%da decimal integer (assumes base 10)%ia decimal integer (detects the ... Read More

Accessing variables of Int and Float without initializing in C

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

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

Given an example of C pointer addition and subtraction

Bhanu Priya
Updated on 08-Mar-2021 06:45:44

2K+ Views

Pointers have many but easy concepts and they are very important to C programming.Two of the arithmetic pointer concepts are explained below, which are C pointer addition and subtraction respectively.C pointer additionC pointer addition refers to adding a value to the pointer variable.The formula is as follows −new_address= current_address + (number * size_of(data type))ExampleFollowing is the C program for C pointer addition − Live Demo#include int main(){    int num=500;    int *ptr;//pointer to int    ptr=#//stores the address of number variable    printf("add of ptr is %u ", ptr);    ptr=ptr+7; //adding 7 to pointer variable    printf("after adding add ... Read More

What are the different types of pointers in C language?

Bhanu Priya
Updated on 13-Sep-2023 16:12:06

30K+ Views

The pointer is a variable that stores the address of another variable.The syntax for the pointer is as follows −pointer = &variable;Types of PointersThere are eight different types of pointers which are as follows −Null pointerVoid pointerWild pointerDangling pointerComplex pointerNear pointerFar pointerHuge pointerNull PointerYou create a null pointer by assigning the null value at the time of pointer declaration.This method is useful when you do not assign any address to the pointer. A null pointer always contains value 0.ExampleFollowing is the C program for the null pointer − Live Demo#include int main(){    int *ptr = NULL; //null pointer   ... Read More

Explain the concept of pointers in C language

Bhanu Priya
Updated on 08-Mar-2021 06:33:17

5K+ Views

The pointer is a variable that stores the address of another variable.Features of PointersPointer saves the memory space.The execution time of a pointer is faster because it directly accesses to memory location.The memory is accessed efficiently with the help of a pointer.Memory is allocated and deallocated dynamically.Pointers are used with data structures.The syntax for the pointer is as follows −pointer = &variable;ExampleFollowing is the C program for the pointer − Live Demo#include int main(){    int x=40; //variable declaration    int *p; //pointer variable declaration    p=&x; //store address of variable x in pointer p    printf("address in variable p ... Read More

Compute sum of all elements in 2 D array in C

Bhanu Priya
Updated on 08-Mar-2021 06:19:59

3K+ Views

ProblemCalculate the sum of all elements of a two-dimensional array by using run-time initialization.SolutionTwo-dimensional Array is used in situations where a table of values have to be stored (or) in matrices applicationsThe syntax is as follows −datatype array_ name [rowsize] [column size];For example, int a[4] [4];Number of elements in an array = rowsize *columnsize = 4*4 = 16ExampleFollowing is the C program to calculate the sum of all elements of a two-dimensional array by using run-time initialization − Live Demo#include void main(){    //Declaring array and variables//    int A[4][3], i, j, even=0, odd=0;    //Reading elements into the array//   ... Read More

Advertisements