Skip to main content

Posts

Syllabus Theory

 SYLLABUS Programming in C (Common to all disciplines) Module 1  Basics of Computer Hardware and Software Basics of Computer Architecture: processor, Memory, Input& Output devices Application Software & System software: Compilers, interpreters, High level and low level languages Introduction to structured approach to programming, Flow chart Algorithms, Pseudo code (bubble sort, linear search - algorithms and pseudocode) Module 2  Program Basics Basic structure of C program: Character set, Tokens, Identifiers in C, Variables and Data Types , Constants, Console IO Operations, printf and scanf Operators and Expressions: Expressions and Arithmetic Operators, Relational and Logical Operators, Conditional operator, size of operator, Assignment operators and Bitwise Operators. Operators Precedence Control Flow Statements: If Statement, Switch Statement, Unconditional Branching using goto statement, While Loop, Do While Loop, For Loop, Break and Continue statements.(Simple programs cov

Nesting of Loops

We can write one loop inside another loop.A loop within another loop is called a nested loop. In C programming, nested loops are loops that are placed inside another loop. This allows you to repeat a set of instructions multiple times, and inside each iteration of the outer loop, the inner loop completes its full iteration. Nested loops are useful when you need to perform repetitive tasks within repetitive tasks. The following is the syntax of writing one for loop inside another for loop.There is no rule that a loop must be nested inside its own type. In fact, there can be any type of loop nested inside any type and to any level. Each inner (nested) loop must be completely embedded within an outer loop, the loops cannot overlap.Here for each iteration of the outer loop, the inner loop keep executing completely. Nesting of for loop for ( initialization; condition; increment )  {       for ( initialization; condition; increment )       { // statement of inside loop       }       // state

Infinite Loops in C

An infinite loop is a looping construct that does not terminate and executes the loop forever. It is also called an indefinite loop or an endless loop . It either produces a continuous output or no output. When to use an infinite loop An infinite loop is useful for those applications that accept the user input and generate the output continuously until the user exits from the application manually.  In the following situations, this type of loop can be used: All the operating systems run in an infinite loop as it does not exist after performing some task. It comes out of an infinite loop only when the user manually shuts down the system. All the servers run in an infinite loop as the server responds to all the client requests. It comes out of an indefinite loop only when the administrator shuts down the server manually. All the games also run in an infinite loop. The game will accept the user requests until the user exits from the game. We can create an infinite loop through various lo

Prgoram transfer control(Jump) statements, break, continue ,goto and exit function

break Statement The break statement is used with in switch statement to transfer program control out of switch statement after executing a set  of statements mentioned in a particular case. break statement can also be used in looping statements to transfer program control out of the loop. This will help to terminate a loop when a particular condition is met. Example: This program will check whether the given number contain digit 0.It is noted  that when the number contain first 0, we can stop doing the process and print that the number contains 0.There is no point in continuing the loop and hence computation time can be saved. #include <stdio.h> main()  {     int n,digit;     printf("Enter an integer: ");     scanf("%d", &n);     while (n != 0) {         digit= n % 10;           n = n/10;         if (digit==0) {                printf("number contains 0\n");                       break;                       }           }      } o/p Enter an in

Looping (iteration )Statements while,do while and for ,sample programs using loops and programs to try

Loops are used in programming to repeat a specific block of statements until some end condition is met.    Types of Loops in C Depending upon the position of a control statement in a program, looping in C is classified into two types:   1. Entry controlled loop 2. Exit controlled loop In an entry control loop in C, a condition is checked before executing the body of a loop. It is also called as a pre-checking loop. In an exit controlled loop , a condition is checked after executing the body of a loop. It is also called as a post-checking loop. The control conditions must be well defined and specified otherwise the loop will execute an infinite number of times. The loop that does not stop executing and processes the statements number of times is called as an infinite loop . An infinite loop is also called as an " Endless loop ."   There are three looping statements in C programming: while loop ( entry controlled) do...while loop ( exit controlled) for loop ( entry control

switch statement in C,sample programs and programs to try

There is one potential problem with the if-else statement which is the complexity of the program increases whenever the number of alternative path increases. If you use multiple if-else constructs in the program, a program might become difficult to read and comprehend. Sometimes it may even confuse the developer who himself wrote the program. The solution to this problem is the switch statement. A switch statement is used for multiple way selections that will branch into different code segments based on the value of a variable or expression. This expression or variable must be of integer data type. Syntax: switch (expression) { case value1:                   code segment1;                   break; case value2:                  code segment2;                  break; case valueN:                  code segmentN;                  break; default:                 default code segment; } The value of this expression is either generated duri

Structure of a C program

Lets understand the  basic structure of a C program. A C program is divided into different sections. There are six main sections to a basic c program. The six sections are, Documentation Include/Link/Preprocessor     section Definition Global Declarations ( Functions and variables) Main function Subprogram functions     Now let us learn about each of this layer in detail. Figure: Basic Structure Of C Program Sample Program The C program here will find the area of a circle using a user-defined function and a global variable PI holding the value of pi /* File Name: areaofcircle.c Author: Abhijith date: 06/05/2021   description: a program to calculate area of circle user enters the radius */ #include<stdio.h>   //link section #define PI   3.14;//definition section float area(float r);//global declaration /****************************/ int main()//main function { float r; printf(" Enter the radius:\n"); scanf("%

Beginning with C programming

Beginning with C programming: Finding a Compiler: Before we start C programming, we need to have a compiler to compile and run our programs. There are certain online compilers like http://ideone.com/ or https://www.onlinegdb.com/online_c_compiler that can be used to start C programming without installing a compiler. Windows: There are many compilers available freely for compilation of C programs like Code Blocks and Dev-CPP. Borland C( https://developerinsider.co/download-and-install-borland-c-compiler-on-windows-10/ ), Turbo C ( https://developerinsider.co/download-turbo-c-for-windows-7-8-8-1-and-windows-10-32-64-bit-full-screen/ ) etc Linux: For Linux, gcc comes bundled with the linux, Code Blocks can also be used with Linux. This Blog has been written based on Linux and all the given examples have been compiled on the Ubuntu flavor of the Linux system.If you are using Linux or UNIX, then check whether GCC is installed on your system by entering the following command from the comma