Skip to main content

Posts

Showing posts from May, 2021

Enhancing Indoor Air Quality: A Guide to Better Health and Comfort

In today's world, where we spend a significant amount of our time indoors, the quality of the air we breathe inside our homes and workplaces is crucial for our health and well-being. Poor indoor air quality (IAQ) can lead to various health issues, including allergies, respiratory problems, and even long-term conditions. This blog post explores effective strategies for managing and improving indoor air quality. Understanding Indoor Air Pollutants Indoor air pollutants can originate from various sources: Biological Pollutants: Mold, dust mites, and pet dander. Chemical Pollutants: Volatile organic compounds (VOCs) from paints, cleaners, and furnishings. Particulate Matter: Dust, pollen, and smoke particles. Strategies for Improving Indoor Air Quality Ventilation: Natural Ventilation: Open windows and doors regularly to allow fresh air circulation. Mechanical Ventilation: Use exhaust fans in kitchens and bathrooms to remove pollutants directly at the source. Air Purifiers: HEPA Filt

Introduction to Data structure and algorithms

BASIC TERMINOLOGY Our aim has been to design good programs, where a good program is defined as a program that * runs correctly * is easy to read and understand * is easy to debug and * is easy to modify. A program should undoubtedly give correct results, but along with that it should also run efficiently. A program is said to be efficient when it executes in minimum time and with minimum memory space. In order to write efficient programs we need to apply certain data management concepts. The concept of data management is a complex task that includes activities like data collection, organization of data into appropriate structures, and developing and maintaining routines for quality assurance. Data structure is a crucial part of data management and in this book it will be our prime concern. A data structure is basically a group of data elements that are put together under one name, and which defines a particular way of storing and organizing data in a computer so that it can be used eff

C Program Important points

Points to Remember • C was developed in the early 1970s by Dennis Ritchie at Bell Laboratories. • Every word in a C program is either an identifier or a keyword. Identifiers are the names given to program elements such as variables and functions. Keywords are reserved words which cannot be used  as identifiers. • C provides four basic data types: char, int, float, and double. • A variable is defined as a meaningful name given to a data storage location in computer memory.  • Standard library function scanf() is used to input data in a specified format.printf()function is used to output data of different types in a specified format. • C supports different types of operators which can be classified into following categories: arithmetic, relational, equality, logical, unary, conditional, bitwise, assignment, comma, and sizeof operators. • Modulus operator (%) can only be applied on integer operands, and not on float or double operands.  • Equality operators have lower precedence t

Pointers to Pointers

Pointer to Pointers In C, you can also use pointers that point to pointers. The pointers in turn point to data or even to other pointers. To declare pointers to pointers, just add an asterisk * for each level of reference.           Fig: Pointer to Pointer For example, consider the following code: int x=10; int *px, **ppx; px = &x; ppx = &px; Let us assume, the memory locations of these variables are as shown in Fig.above Now if we write, printf("\n %d", **ppx); Then, it would print 10, the value of x. Drawbacks of Pointers Although pointers are very useful in C, they are not free from limitations. If used incorrectly, pointers can lead to bugs that are difficult to unearth. For example, if you use a pointer to read a memory location but that pointer is pointing to an incorrect location, then you may end up reading  a wrong value. An erroneous input always leads to an erroneous output. Thus however efficient your program code may be, the output will always

Pointer Expression and Pointer Arithmetic

Pointer Expressions and Pointer Arithmetic Like other variables, pointer variables can also be used in expressions. For example, if ptr1 and ptr2 are pointers, then the following statements are valid: int num1 = 2, num2 = 3, sum = 0, mul = 0, div = 1; int *ptr1, *ptr2; ptr1 = &num1; ptr2 = &num2; sum = *ptr1 + *ptr2; mul = sum * (*ptr1); *ptr2 += 1; div = 9 + (*ptr1)/(*ptr2) – 30; In C, the programmer may add integers to or subtract integers from pointers as well as subtract one pointer from the other. We can also use shorthand operators with the pointer variables as we use them with other variables. C also allows comparing pointers by using relational operators in the expressions. For example, p1>p2, p1==p2 and p1!=p2 are all valid in C. Postfix unary increment (++) and decrement (––) operators have greater precedence than the dereference operator (*). Therefore, the expression *ptr++ is equivalent to *(ptr++), as ++ has greater operator precedence than *. Thus, the express

Declaring Pointer Variables

Declaring Pointer Variables The general syntax of declaring pointer variables can be given as below. data_type *ptr_name; Here, data_type is the data type of the value that the pointer will point to. For example, int *pnum; char *pch; float *pfnum; In each of the above statements, a pointer variable is declared to point to a variable of the specified data type. Although all these pointers (pnum, pch, and pfnum) point to different data types, they will occupy the same amount of space in the memory. But how much space they will occupy will depend on the platform where the code is going to run. Now let us declare an integer pointer variable and start using it in our program code. int x= 10; int *ptr; ptr = &x; In the above statement, ptr is the name of the pointer variable. The * informs the compiler that ptr is a pointer variable and the int specifies that it will store the address of an integer variable.  An integer pointer variable, therefore, ‘points to’ an integer variable. In th

Pointers

Pointers Every variable in C has a name and a value associated with it. When a variable is declared, a specific block of memory within the computer is allocated to hold the value of that variable. The size of the  allocated block depends on the data type.  Consider the following statement. int x = 10; When this statement executes, the compiler sets aside 2 bytes of memory to hold the value 10.  It also sets up a symbol table in which it adds the symbol x and the relative address in the memory where those 2 bytes were set aside. (Note the size of integer may vary from one system to another. On 32 bit systems, integer variable is allocated 4 bytes while on 16 bit systems it is allocated 2 bytes.)  Thus, every variable in C has a value and also a memory location (commonly known as address) associated with it. We will use terms rvalue and lvalue for the value and the address of the variable, respectively. The rvalue appears on the right side of the assignment statement (10 in the above sta

Passing Parameters to Functions

Passing Parameters to Functions There are two ways in which arguments or parameters can be passed to the called function. Call by value The values of the variables are passed by the calling function to the called function.  Call by reference The addresses of the variables are passed by the calling function to the called function. Call by Value In this method, the called function creates new variables to store the value of the arguments passed to it. Therefore, the called function uses a copy of the actual arguments to perform its intended task. If the called function is supposed to modify the value of the parameters passed to it, then the change will be reflected only in the called function. In the calling function, no change will be made to the value of the variables. This is because all the changes are made to the copy of the variables and not to the actual variables. To understand this concept, consider the code given below. The function add() accepts an integer variable num and ad

Phython MCQ - 1

1.What is the output after the following statement? m= 28 n= 5p printm//n) a) 5.0 b) 6 c) 5 d) 4.0 2.  What will be the output after the following statement?     m=90     n=7     print(m%n) a) 6 b) 4 c) 6.0 d) 5.0 3. What will be the output of the following statement?     m = 79     n = 64     print(m<n) a) m<n  b) False c) True d) No 4. What is the output of the following statement? m= 92 n= 35 print(m>n) a) True b) False c) yes d) No 5. What is the output of the following statement? m= false n = true print ( m and n)  a) m and n b) False c) True d) mn 6. What Will be the output of the following statement? m= true n= false print( m or n) a) m or n b) false c) true d) mn 7. What will be the output of the following statement? m = true n = false print(not m) a) not m b) false c) true d) not defined 8. What will be the output of the following statement? m= true n= false print('not n') a) not n b) false c) true d) not defined 9. What is the output of the following st

Functions needed

Why are Functions Needed? Let us analyse the reasons why segmenting a program into manageable chunks is an important aspect of programming. * Dividing the program into separate well-defined functions facilitates each function to be written and tested separately. This simplifies the process of getting the total program to work. * Understanding, coding, and testing multiple separate functions is easier than doing the same for one big function. * If a big program has to be developed without using any function other than main(), then there will be countless lines in the main() function and maintaining that program will be a difficult task. * All the libraries in C contain a set of functions that the programmers are free to use in their programs. These functions have been pre-written and pre-tested, so the programmers can use them without worrying about their code details. This speeds up program development, by allowing the programmer to concentrate only on the code that he has to write. *

Functions

FUNCTIONS C enables its programmers to break up a program into segments commonly known as functions, each of which can be written more or less independently of the others. Every function in the program is supposed to perform a well-defined task. Therefore, the program code of one function  is completely insulated from the other functions. Every function interfaces to the outside world in terms of how information is transferred to it and how results generated by the function are transmitted back from it. This interface is basically specified by the function name. For example, look  at below figure which explains how the main() function calls another function to perform a well-defined task. Fig: main() calls func1() In the figure, we can see that main() calls a function named func1(). Therefore, main() is known as the calling function and func1() is known as the called function. The moment the compiler  encounters a function call, the control jumps to the statements that are

Break and Continue Statements

Break and Continue Statements break Statement In C, the break statement is used to complete the implementation of the closes enclosing loop in which it appears. We have already seen its use in the switch statement. The break statement is mostly used with for, while, and do–while loops. When the compiler encounters a break statement, the control passes to the statement that follows the loop in which the break statement appears. Its syntax is  quite simple, just type keyword break followed by a semi-colon. break; The example given below shows the manner in which break statement is used to terminate the loop in which it is embedded. #include <stdio.h> int main() { int i = 0; while(i<=10) { if (i==5)  break;  printf("\t %d", i);  i = i + 1; } return 0; } Output 0 1 2 3 4 As soon as i becomes equal to 5, the break statement is executed and the control jumps to the statement following the while loop. Hence, the break statement is used to exit a loop from any point within i

Iterative statement

Iterative Statements Iterative statements are used to repeat the implementation of a series of statements until the specified expression becomes false. C supports three types of repetitive statements also known as looping  statements. They are * while loop * do–while loop * for loop In this part, we will discuss all these statements. while loop The while loop supports a mechanism to repeat one or more statements while a specific condition is true. Figure below shows the syntax and general form of a while loop. Note that in the while loop, the condition is verified before any of the statements in the statement block is implemented. If the condition is true, only then the statements will be implemented, otherwise if the condition is false, the control will jump to statement y, that is the next statement outside the while loop block. In the flow diagram it is clear that we require to constantly update the condition of the while loop. It is this condition which defines when the