
























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to procedural programming, explaining the concepts of functions, conditional statements, and variables in this programming paradigm. It covers the key features of procedural programming, including predefined functions, parameter passing, and the use of printf() and scanf() in C. The document also delves into the syntax and usage of simple if statements, nested if statements, and else if ladders. Additionally, it discusses switch statements and looping structures such as while loops and for loops.
Typology: Summaries
1 / 32
This page cannot be seen from the preview
Don't miss anything!

























A procedural language is a type of computer programming language that specifies a series of well-structured steps and procedures within its programming context to compose a program. Examples of procedural languages are BASIC, C, Java FORTRAN and Pascal. Procedural languages are some of the common types of programming languages used by script and software programmers. They make use of functions, conditional statements and variables to create programs that allow a computer to calculate and display a desired output. Procedures or functions are implemented on the data and variables to perform a task. These procedures can be called/invoked anywhere between the program hierarchy, and by other procedures as well. It is also known as imperative language. Advantage of Procedural Language are: ✓ It is relative simplicity and ease of implementation of compilers and interpreters ✓ The ability to re-use the same code at different places in the program without copying it. ✓ An easier way to keep track of program flow. ✓ The ability to be strongly modular or structured. ✓ Needs only less memory.
Characteristics of Procedural oriented programming is:
Program to divide two number :
If statement Simple if if else nested if else else if ladder (if else if else)
if (test-expression) { Statement 1; }
Entry True T.E Statement- 1
Flowchart of if else: Entry True False
#include<stdio.h> int main () { int n; printf("Enter a number: "); scanf("%d",&n); if(n>0) { printf("It is positive number"); } else { printf("It is negative number"); } return 0; } T.E Statement- (^1) Statement- 2 End
Output: Enter a number: 9 Enter a number: - 20 It is positive number It is negative number
if (test-expression 1) { if (test-expression 2) { Statement block-1; } else { Statement block-2; } else { if (test-expression 3) { Statement block-3; } else { Statement block-4; } }
printf("The greater number is %d",n1); } else { printf("The greater number is %d",n3); } } else { if(n2>n3) { printf("The greater number is %d",n2); } else { printf("The greater number is %d",n3); } } return 0; } Output: Enter a b and c: 67 82 25 The greatest value is 82.
if (condition-1) statement-1; else if (condition-2) statement-2; else if (condition-3) statement-3; else if (condition-4)
statement-4; : : : else if (condition-n) statement-n; else default statement;
Entry True False True False True False True False cond
Entry default exp const 3 exp const 2 exp const 1 exit
#include<stdio.h> int main () { char a; printf("Enter any number: "); scanf("%c", &a); switch(a) { case '1': printf("Sunday"); break; Switch exp block- 1 block- 1 block- 1 default block
case '2': printf("Monday"); break; case '3': printf("Tuesday"); break; case '4': printf("Wednesday"); break; case '5': printf("Thursday"); break; case'6': printf("Friday"); break; case '7': printf("Saturday"); break; default: printf("Please enter number 1 to 7"); break; } return 0; } Output: Enter any number: 6 Enter any number: Ans. Friday Ans. Please enter number 1 to 7
Hello Hello Hello
Entry False True Exit body of loop T.E
#include<stdio.h> int main () { int a=5; do { printf(“Hello”); a++; } while (a<8); return 0; } Output: Hello Hello Hello
for (initialization expression; test expression; update expression) { body of loop; }
Output: 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
Array is the group of relative data item that share a common name. Arrays are derived data types. The use of array allows for the development of smaller and most clear readable program. Types of Array:
Elements of the array can be represented either as a single column or as a single row. Initialization of an array: Datatype name [size] = {List of arguments} Program for One Dimensional array: #include<stdio.h> int main () { int mark [10],i; for (i=0; i<5; i++) { printf("Enter mark"); scanf("%d", &mark[i]); }
for (i=0; i<5; i++) { printf("%d\n", mark[i]); } return 0; } Output: Enter a mark: 5 Enter a mark: 9 Enter a mark: 7 Enter a mark: 3 Enter a mark: 12 Ans. 5 9 7 3 12
It is the collection of the data item all of the same types structured in two-dimension (refer as rows and columns) Declaration of Two-Dimension array: float marks [20][30] int marks [3][4] = [{1,2,3,4}, {2,4,6,8}, {1,3,5,7}] Program for Two-dimensional array: #include<stdio.h> int main () { int i, j, marks[10][10]; for (i=0; i<3; i++) { for (j=0; j<2; j++) {