Skip to main content


Conditional Statements In C Programming

Conditional Statements: What are conditional Statements: Ans. Conditional statements are those statements which are used to check whether a particular condition is true or t is false and if it is true the task given to it gets executed. Types of conditional statements: There 3 types of conditional statements if statement else if statement else statement They all work together to give the desired output. Syntax: if(condition here) {code to be written here;} Note: The condition which needs to be checked should be written inside the round brackets. Code which needs to be executed if the condition is true is written inside curly braces. Semicolon will come only inside curly braces and not after condition. 1. if statement: It is the main statement and it is a standalone statement i.e it doesn't require any other conditional statement for its existence. Syntax: if(condition) {Code to be written here;} If the condition in the

Basic C Programming Questions

Basic Coding Questions: Exercise 1: Q1. Write a programme to calculate area and perimeter of rectangle by accepting its length and breadth. Ans: #include<stdio.h> #include<conio.h> void main() { float a,p,l,b; clrscr(); printf("\n enter the length and breadth of rectangle"); scanf("%f%f",&l,&b); a=l*b; p=2*(l+b); printf("\n the area of rectangle is %f and the perimeter is %f",a,p); getch(); } The above image code is written in code blocks Output: enter the length and breadth of rectangle 20(press enter) 10 (press enter) the area of rectangle is 200 and the perimeter is 60 Explanation of the above code: Declaring of variables in data type float since length and breadth cannot always be integers. Taking input of length and breadth together by using scanf function. Substituting the values of length and breadth stored in l and b

C Programming Basics

C PROGRAMMING BASICS: 1. Introduction to C language: C language was invented in Bell Labs by Dennis Ritchie between 1972-73. C language is a case sensitive language i.e the input given to it varies according to upper and lower case letters. It is executed using binary form data such as (0,1). By using binary data the speed of executing a code increases. 1.1 Header Files: Header files are those files which contain some predefined functions in it which we are going to use in our code. Every header file is accessed by appending an extension ".h". Example:               #include<stdio.h>                                 ↓                    ⇡          Tells computer to                  header file  with           include the header                 extension .h          file                                     T here are many header files for different functions such as the following:          <conio.h> <math.h> <string.h