How to use switch statement in C Programming

  Switch statement is also called as multiple selection structure in C Programming. Switch selection structure is similar to if-else selection structure. The difference is instead of using multiple if-else statement we use 'cases' to check for multiple conditions. The 'default' case will run when no condition is true. The following simple c program explains how to use switch statement in c programming. [js] #include <stdio.h> int main(void){ int number1; //defined variable named as number1 printf("Please Enter Integer Number:n"); scanf("%d", &number1); // getting variable value from user and assiging value to variable named as number1 printf("n"); switch(number1){ // expression to...
forward

How to use if-else statement in C Programming

In previous post we discussed about if statement in C Programming. If-else statement called as double selection structure in C Programming. In simple words it says "Do something when a condition is true, else (when condition is false) do some other thing". Following simple c program explains how to use if-else statement in C Programming. [js] #include <stdio.h> int main(void){ int number1; //defined variable named as number1 int number2; // defined variable named as number2 printf("Please Enter First Integer Number:n"); scanf("%d", &number1); // getting variable value from user and assiging value to variable named as number1 printf("n"); printf("Please Enter Second...
forward

How to use if statement in C Programming

  If statement is called as selection structure in C Programming. If statement checks a condition and proceed further depending upon the fact that whether the condition being checked is true or false. In simple words it says "Do something when this condition is true". Following simple program explains how to use if statement to compare 2 numbers entered by the user. [js] #include <stdio.h> int main(void){ // defining variables, computing their sum and printing sum on the screen int number1; //defined variable named as number1 int number2; // defined variable named as number2 printf("Please Enter First Integer Number:n"); scanf("%d",...
forward

How to define variables in c programming

In our previous post we discussed about how to get values from user. Sometimes we need to define variables and assign values to those variables. This simple program explains how to define variables and how to assign values to the variables in c programming. [js] #include <stdio.h> int main(void){ // defining variables, computing their sum and printing sum on the screen int number1; //defined variable named as number1 with data type integer int number2; // defined variable named as number2 with data type integer int sum; // defined variable named as sum with data type integer number1 = 5; // assigned...
forward

How to get value from user in C Programming

Sometimes in a program we need to get values from user, process the values entered by user and print / output the results of that processing on the screen. In order to get values from user we use 'scanf' function which is part of the stdio.h library. Following simple program explains how to use scanf function to get 2 numbers from user, sum the 2 entered by the user and print the sum of 2 numbers on the output screen. [js] #include <stdio.h> int main(void){ // defining variables, computing their sum and printing sum on the screen int number1; //defined...
forward