Found 33676 Articles for Programming

C program to print multiplication table by using for Loop

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

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

316 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

Given an example of C pointer addition and subtraction

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

3K+ 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 12-Dec-2024 17:13:22

36K+ Views

A pointer is a variable that stores the address of another variable. The deceleration of a pointer is similar to that of a variable the only difference is while declaring a pointer we need to use "*". Following is the syntax to declare a pointer − type *variable_name; Similar to variables, pointers can be declared in different types. Following is an example − #Integer type pointer int *integer_pointer; #Character type pointer char *character_pointer; The following are the points to be noted − Pointers enable direct memory access and manipulation, which is crucial for ... Read More

Compute sum of all elements in 2 D array in C

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

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