In real life we come across situations when we need to perform a set of task repeatedly till some condition is met. Such as – sending email to all employees, deleting all files, printing 1000 pages of a document. All of these tasks are performed in loop. To do such task C supports looping control statements.
For loop is an entry controlled looping statement. It is used to repeat set of statements until some condition is met.
Continue reading For loop in C programming
switch...case both programming constructs has ability to take decision based on conditions. Both are almost similar in nature. However, there is always a debate among beginners which to use and when to use what?
In this post, I will compare both on various grounds. So let us begin.
Continue reading If…else…if vs switch…case, difference and usage?
if...else statement provides support to control program flow. if statement make decisions based on conditions. It selects an action, if some condition is met. However, there exits situations where you want to make a decision from available choices. For example - select a laptop from available models, select a menu from available menu list etc.
switch...case statement gives ability to make decisions from fixed available choices. Rather making decision based on conditions. Using
switch we can write a more clean and optimal code, that take decisions from available choices.
Continue reading switch…case statement in C
if...else...if statements provide a great support to control programs flow. Simple
if is single condition based task i.e. "if some condition is true, then do the task". In contrast
if...else...if statement provides multiple condition checks i.e. "if some condition is true, then do some task. If the condition is false, then check some other condition and do some task. If all conditions fails, then do some default task."
Continue reading Nested if…else statement in C
In previous post, I explained to control programs flow of execution using simple
if works as "if some condition is true then do some tasks". It doesn't specifies what to do if condition is
false. A good program must think both ways. For example - if user inputs correct account number and pin, then allow money withdrawal otherwise show error message to user.
Continue reading If…else and if…else…if statement in C
So far in our journey of learning C programming, we learned to write simple C programs, that executes in the sequence we write. A program that always executes in same sequence is worthless. The ability to control program flow and statements execution is worth.
if statement allows us to select an action based on some condition. It gives programmer to take control over a piece of code. Programmer can control the execution of code based on some condition or user input. For example - if user inputs valid account number and pin, then allow money withdrawal.
Continue reading If statement in C
Control statements are heart of any programming language. In your programming life you will find 60-70% of your program consist control statements. To master the art of programming, you must have a good control over your program. You must have a solid grip over control statements.
Every program by default execute sequentially. Each and every statement is executed one after other. However, there happen situations when you need to execute statement/s based on conditions. Such as display confidential files only if user has authentic credentials.
Continue reading Flow Control statements in C
Write a C program to demonstrate input and output of all basic and derived types. How to use
printf() function perform input and output on primitive types in C programming.
Continue reading C program to perform input output of all basic data types
Input, process and output processed data is the main goal of every computer program. A program without data is a useless program.
In this post we will learn some basic C functions to input and output value of a variable.
Continue reading Basic input and output in C
Typecasting is a way to convert variables, constants or expression from one type to another type. Conversion from one type to another is often required in programming.
Consider a case where you want to find average of three numbers. Let us write a program to find average of three numbers.
int num1, num2, num3;
num1 = 91;
num2 = 85;
num3 = 83;
average = (num1 + num2 + num3) / 3;
printf("Average = %f", average);
Continue reading Typecasting in C programming