Write a C program to calculate the distance between two cities

C Programming Tutorial

Problem Statement: The distance between two cities (in km.) is input through the keyboard. Write a C program to convert and print this distance in meters, feet, inches and centimeters. Answer: /* Conversion of distance */ #include <stdio.h> #include <conio.h> main() { float km, m, cm, ft, inch; clrscr(); /* To clear the screen */ … Read more

if else statement in c

C Programming Tutorial

The if statement by itself will execute a single statement, or a group of statements, when the expression following if evaluates to true. It does nothing when the expression evaluates to false. Can we execute one group of statements if the expression evaluates to true and another group of statements if the expression evaluates to … Read more

Hierarchy of Operators Revisited in C

C Programming Tutorial

Since we have now added the logical operators to the list of operators we know, it is time to review these operators and their priorities. The higher the position of an operator is in the table, higher is its priority. The following figure summarizes the working of all the three logical operators.

C Program to calculate the salary

C Programming Tutorial

Problem Statement: Write a program to calculate the salary as per the following table: Solution: /* C program to calculate salary */ main( ) { char g ; int yos, qual, sal ; printf ( “Enter Gender, Years of Service and Qualifications ( 0 = G, 1 = PG ):” ) ; scanf ( “%c%d%d”, &g, … Read more

Multiple Statements within if in C

C Programming Tutorial

It may so happen that in a program we want more than one statement to be executed if the expression following if is satisfied. If such multiple statements are to be executed then they must be placed within a pair of braces as illustrated in the below example. Example: The current year and the year in which … Read more

If Statement in C

C Programming Tutorial

Like most languages, C uses the keyword if to implement the decision control instruction. The general form of if statement looks like this: if ( this condition is true )       execute this statement ; The keyword if tells the compiler that what follows is a decision control instruction. The condition following the … Read more

Introduction to Decision Control Structure in C

C Programming Tutorial

Decision !!! we all need to alter our actions in the face of changing circumstances. If the weather is fine, then I will go for a stroll. If the highway is busy I would take a diversion. If the pitch takes spin, we would win the match. If she says no, I would look elsewhere. … Read more

write a C program for Conversion of Temperature from Fahrenheit to Centigrade

C Programming Tutorial

Problem Statement: Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a c program to convert this temperature into Centigrade degrees. Answer: /* Conversion of Temperature from Fahrenheit to Centigrade */ #include <stdio.h> #include <conio.h> main() { float fr, cent; clrscr(); print(“\n Enter the temperature in Fahrenheit:”); scanf(“%f”, &fr); cent=5.0/9.0*(fr-32); printf(“\n … Read more

Summary of C learning – First program in C

C Programming Tutorial

The three primary constants and variable types in C are integer, float and character. A variable name can be of maximum 31 characters. Do not use a keyword as a variable name. An expression may contain any sequence of constants, variables and operators. Operators having equal precedence are evaluated using associativity. Left to right associativity … Read more

Control Instructions in C

C Programming Tutorial

As the name suggests the ‘Control Instructions’ enable us to specify the order in which the various instructions in a program are to be executed by the computer. In other words the control instructions determine the ‘flow of control’ in a program. There are four types of control instructions in C. They are: Sequence Control … Read more