0% found this document useful (0 votes)
2 views22 pages

Module I Answers

The document outlines various computing environments, including personal, time-sharing, client-server, distributed, grid, and cluster computing. It also explains flowcharts as a method for representing algorithms and processes, detailing their symbols and uses. Additionally, the document covers program development steps in C, the characteristics of algorithms, and various operators used in C programming.

Uploaded by

runtst2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views22 pages

Module I Answers

The document outlines various computing environments, including personal, time-sharing, client-server, distributed, grid, and cluster computing. It also explains flowcharts as a method for representing algorithms and processes, detailing their symbols and uses. Additionally, the document covers program development steps in C, the characteristics of algorithms, and various operators used in C programming.

Uploaded by

runtst2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 22

Module-I

Computing Environments:

A computer system uses many devices, arranged in different ways to solve many problems. This
constitutes a computing environment where many computers are used to process and exchange
information to handle multiple issues

Types of Computing Environments:


The are the various types of computing environments. They are:

Personal Computing Environment


Personal computing is a stand-alone machine. In a personal computing environment, the
complete program resides on the stand-alone machine and executed from the same machine.
Laptops, mobile devices, printers, scanners and the computer systems we use at home, office are
the examples for the personal computing environment

Time-Sharing Computing Environment


The time-sharing computing environment is a stand-alone computer in which a single user can
perform multiple operations at a time by using a multitasking operating system. Here the
processor time is divided among different tasks and this is called “Time-sharing”. For example, a
user can listen to music while writing something in a text editor. Windows 95 and later versions
of Windows OS, iOS and Linux operating systems are the examples for this computing
environment.
Client-Server Computing Environment
The client-server environment contains two machines (Client machine and Server machine).
These both machines will exchange the information through an application. Here Client is a
normal computer like PC, Tablet, Mobile, etc., and Server is a powerful computer which stores
huge data and manages the huge amount of file and emails, etc., In this environment, client
requests for data and server provides data to the client. In the client-server environment, the
communication between client and server is performed using HTTP (Hyper Text Transfer
Protocol).

Distributed Computing Environment


In the distributed computing environment, the complete functionality of the software is not on a
single computer but is distributed among multiple computers. Here we use a method of computer
processing in which different programs of an application run simultaneously on two or more
computers. These computers communicate with each other over a network to perform the
complete task. In a distributed computing environment, the data is distributed among different
systems and that data is logically related to each other.
Grid Computing Environment
Grid computing is a collection of computers from different locations. All these computers work
for a common problem. A grid can be described as a distributed collection of a large number of
computers working for a single application.
Cluster Computing Environment
Cluster computing is a collection of interconnected computers. These computers work together
to solve a single problem. In a cluster computing environment, a collection of systems work
together as a single system

FLOWCHART:
What is flowchart?

A flowchart is a type of diagram that represents an algorithm, workflow or process, showing the
steps as boxes of various kinds, and their order by connecting them with arrows. This
diagrammatic representation illustrates a solution model to a given problem. Flowcharts are used
in analyzing, designing, documenting or managing a process or program in various fields
Symbols of flowchart:

Shape Name Description

An arrow coming from one symbol and ending at another


symbol represents that control passes to the symbol the
arrow points to. The line for the arrow can be solid or
Flow Line
dashed. The meaning of the arrow with dashed line may
differ from one flowchart to another and can be defined in
the legend.

Represented as circles, ovals, stadiums or rounded (fillet)


rectangles. They usually contain the word “Start” or
Terminal
“End”, or another phrase signaling the start or end of a
process, such as “submit inquiry” or “receive product”.

Represented as rectangles. This shape is used to show that


Process something is performed. Examples: “Add 1 to X”,
“replace identified part”, “save changes”, etc….
Represented as a diamond (rhombus) showing where a
decision is necessary, commonly a Yes/No question or
True/False test. The conditional symbol is peculiar in that
it has two arrows coming out of it, usually from the
bottom point and right point, one corresponding to Yes or
True, and one corresponding to No or False. (The arrows
Decision
should always be labeled.) More than two arrows can be
used, but this is normally a clear indicator that a complex
decision is being taken, in which case it may need to be
broken-down further or replaced with the “predefined
process” symbol. Decision can also help in the filtering of
data.

Represented as a parallelogram. Involves receiving data


Input/ and displaying processed data. Can only move from input
Output to output and not vice versa. Examples: Get X from the
user; display X.

Annotations represent comments or remarks about the


flowchart. Like comments found in high-level
Annotation programming languages, they have no effect on the
interpretation or behavior of the flowchart. Sometimes,
the shape consists of a box with dashed (or dotted) lines.

Represented as rectangles with double-struck vertical


edges; these are used to show complex processing steps
which may be detailed in a separate flowchart.
Predefined
Example: PROCESS-FILES. One subroutine may have
Process
multiple distinct entry points or exit flows (see coroutine).
If so, these are shown as labeled ‘wells’ in the rectangle,
and control arrows connect to these ‘wells’.

Represented as a hexagon. May also be called


initialization. Shows operations which have no effect
other than preparing a value for a subsequent conditional
Preparation
or decision step. Alternatively, this shape is used to
replace the Decision Shape in the case of conditional
looping.
Generally represented with a circle, showing where
multiple control flows converge in a single exit flow. It
will have more than one arrow coming into it, but only
one going out. In simple cases, one may simply have an
arrow point to another arrow instead. These are useful to
represent an iterative process (what in Computer Science
On-Page
is called a loop). A loop may, for example, consist of a
Connector
connector where control first enters, processing steps, a
conditional with one arrow exiting the loop, and one going
back to the connector. For additional clarity, wherever two
lines accidentally cross in the drawing, one of them may
be drawn with a small semicircle over the other, showing
that no connection is intended.

Represented as a home plate-shaped pentagon. Similar to


Off-Page
the on-page connector except allows for placing a
Connector
connector that connects to another page.

Flowchart for biggest of three numbers


Program Development steps of C

Program development or executing a program written in C involves a series of steps.


The program development steps:
1. Creating the program
2. Compiling the program.
3. Linking the program with functions that are needed from C library.
4. Executing the program.

The Following Figure shows the process of creating, compiling and executing a C Program

Creating a Program in Turbo C Editor:


Once we load the Operating system into the memory, the computer is ready to receive the
program. The program must be entered into a file. The file name can consist of letters, digits and
special characters, followed by a dot and a letter c.
Ex: hello.c
program.c
ex1.c
The file is created with the help of a text editor, we use tc.exe. double click the icon TC on the
desktop. TURBOC editor will be opened. If the file is existed before, it can be loaded. If it does
not exist, the file has to be created. After typing the instructions save it with fileextension .c.
When editing is over, the file is saved on disk which can be referred later by its name. the
program that is entered into the file is known as the source program.

Compiling the program: to compile the program press ALT + F9


Now the source program instructions are transformed into a form suitable for execution by the
computer. If mistakes in syntax or semantics of the language are discovered, they are listed out
and the compilation process ends right there. The errors should be corrected in the source
program with the help of the editor and the compilation is done again.

Linking the program:


Linking is the process of putting together other program files and functions that are required by
the program. The compiled and linked program is called the executable object code

Executing the program: to execute the program press CTRL+F9


would load the executable object code into the computer memory and execute the instructions.
Sometimes the program may request for some data to be entered through the keyboard. When
there is wrong with the program logic or data, then it is necessary to correct the source program
or data. In case the source program is modified the entire process of compiling, linking and
executing the program should be repeated.
Algorithm and its characteristics:

An algorithm is an effective step-by-step procedure for solving a problem in a finite number of


steps. In other words, it is a finite set of well-defined instructions or step-by-step description of
the procedure written in human readable language for solving a given problem. An algorithm
itself is division of a problem into small steps which are ordered in sequence and easily
understandable. Algorithms are very important to the way computers process information,
because a computer program is basically an algorithm that tells computer what specific tasks to
perform in what specific order to accomplish a specific task.

1. Finiteness: An algorithm should have finite number of steps and it should end after a
finite time
2. Definiteness: Each step must be clear, well-defined and precise. There should be no any
ambiguity
3. Input − An algorithm should have 0 or more well-defined inputs.
4. Output − An algorithm should have 1 or more well-defined outputs, and should match
the desired output
5. Effectiveness: Each step must be simple and should take a finite amount of time
6. Feasibility − Should be feasible with the available resources
7. Independent − An algorithm should have step-by-step directions, which should be
independent of any programming code.

Algorithm for root of quadratic equation


 Start

 Read a, b, c values

 Compute d = b2 4ac

 if d > 0 then

o r1 = b+ sqrt (d)/(2*a)

o r2 = b sqrt(d)/(2*a)

o print roots are real and unequal

o print r1,r2 values

 Otherwise if d = 0 then

o compute r1 = -b/2a, r2=-b/2a

o print roots are real and equal

o print r1,r2 values

 Otherwise if d < 0 then print roots are imaginary

 Stop

Flowchart for roots of quadratic equation


Operators in C language
An operator is a symbol that tells the computer to perform certain mathematical or logical
manipulations. Operators are used in programs to manipulate data and variables.
Various operators in C are:
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment and Decrement operators
6. Conditional operators(ternary operators)
7. Bitwise operators
8. Special operators

1. Arithmetic operators:

Arithmetic operators are used to perform mathematical calculations like addition, subtraction,
multiplication, division and modulus in C programs.

Operator Description Example

+ Adds two operands. A + B = 30

(A=10,B=20)

− Subtracts second operand from the first. A − B = -10

* Multiplies both operands. A * B = 200

/ Divides numerator by de-numerator. B/A=2

% Modulus Operator and remainder of after an integer B%A=0


division.

Example

C program to perform arithmetic operations such as addition, subtraction, multiplication,


division, modulus.

#include<stdio.h>
int main()
{
int a=40,b=20, add,sub,mul,div,mod;
add = a+b;
sub = a-b;
mul = a*b;
div = a/b;
mod = a%b;
printf("Addition of a, b is : %d\n", add);
printf("Subtraction of a, b is : %d\n", sub);
printf("Multiplication of a, b is : %d\n", mul);
printf("Division of a, b is : %d\n", div);
printf("Modulus of a, b is : %d\n", mod);
}

Output:
Addition of a, b is : 60
Subtraction of a, b is : 20
Multiplication of a, b is : 800
Division of a, b is : 2
Modulus of a, b is : 0

2. Relational operators:
Relational operators are used to find the relation between two variables i.e. to compare the
values of two variables in a C program.
Operato Description Example
r

== Checks if the values of two operands are equal or not. If yes, then (A = = B)
the condition becomes true. is not true.

!= Checks if the values of two operands are equal or not. If the values (A != B) is
are not equal, then the condition becomes true. true.

> Checks if the value of left operand is greater than the value of right (A > B) is
operand. If yes, then the condition becomes true. not true.

< Checks if the value of left operand is less than the value of right (A < B) is
operand. If yes, then the condition becomes true. true.

>= Checks if the value of left operand is greater than or equal to the (A >= B)
value of right operand. If yes, then the condition becomes true. is not true.

<= Checks if the value of left operand is less than or equal to the value (A <= B)
of right operand. If yes, then the condition becomes true. is true.

Example:

// C Program to demonstrate the working of arithmetic operators


#include<stdio.h>
main()
{
int a = 5, b = 5, c = 10;
printf("%d == %d = %d \n", a, b, a == b); // true
printf("%d == %d = %d \n", a, c, a == c); // false
printf("%d > %d = %d \n", a, b, a > b); //false
printf("%d > %d = %d \n", a, c, a > c); //false
printf("%d < %d = %d \n", a, b, a < b); //false
printf("%d < %d = %d \n", a, c, a < c); //true
printf("%d != %d = %d \n", a, b, a != b); //false
printf("%d != %d = %d \n", a, c, a != c); //true
printf("%d >= %d = %d \n", a, b, a >= b); //true
printf("%d >= %d = %d \n", a, c, a >= c); //false
printf("%d <= %d = %d \n", a, b, a <= b); //true
printf("%d <= %d = %d \n", a, c, a <= c); //true
}

Output:
5 == 5 = 1
5 == 10 = 0
5>5=0
5 > 10 = 0
5<5=0
5 < 10 = 1
5 != 5 = 0
5 != 10 = 1
5 >= 5 = 1
5 >= 10 = 0
5 <= 5 = 1
5 <= 10 = 1

3. Logical operators
 These operators are used to perform logical operations on the given
expressions.
 There are 3 logical operators in C language. They are, logical AND
(&&), logical OR (||) and logical NOT (!).

Operato Description Example


r

&& Called Logical AND operator. If both the operands are non-zero, (A && B)
then the condition becomes true. is false.

|| Called Logical OR Operator. If any of the two operands is non-zero, (A || B) is


then the condition becomes true. true.

! Called Logical NOT Operator. It is used to reverse the logical state !(A && B)
of its operand. If a condition is true, then Logical NOT operator will is true.
make it false.

Example :

// C Program to demonstrate the working of logical operators


#include<stdio.h>
main()
{
int a = 5, b = 5, c = 10, result;
result = (a = b) && (c > b);
printf("(a = b) && (c > b) equals to %d \n", result);
result = (a = b) && (c < b);
printf("(a = b) && (c < b) equals to %d \n", result);
result = (a = b) || (c < b);
printf("(a = b) || (c < b) equals to %d \n", result);
result = (a != b) || (c < b);
printf("(a != b) || (c < b) equals to %d \n", result);
result = !(a != b);
printf("!(a == b) equals to %d \n", result);
result = !(a == b);
printf("!(a == b) equals to %d \n", result);
}
Output
(a = b) && (c > b) equals to 1
(a = b) && (c < b) equals to 0
(a = b) || (c < b) equals to 1
(a != b) || (c < b) equals to 0
!(a != b) equals to 1
!(a == b) equals to 0

4. Assignment operators
In C programs, values for the variables are assigned using assignment
operators

Example:
if the value “10” is to be assigned for the variable “sum”, it can be assigned as
“sum = 10”

Example:

// C Program to demonstrate the working of assignment operators

#include <stdio.h>
main()
{
int a = 5, c;
c = a;
printf("c = %d \n", c);
c += a; // c = c+a
printf("c = %d \n", c);
c -= a; // c = c-a
printf("c = %d \n", c);
c *= a; // c = c*a
printf("c = %d \n", c);
c /= a; // c = c/a
printf("c = %d \n", c);
c %= a; // c = c%a
printf("c = %d \n", c);
}

Output
c=5
c = 10
c=5
c = 25
c=5
c=0

5. Increment/ Decrement operators


In C, ++ and -- are called increment and decrement operators respectively. Both of these
operators are unary operators, i.e, used on single operand. ++ adds 1 to operand and --
subtracts 1 to operand respectively.

Example:
Let a=5 and b=10
a++; //a becomes 6
a--; //a becomes 5
++a; //a becomes 6
--a; //a becomes 5

Difference between ++ and -- operator as postfix and prefix

When i++ is used as prefix(like: ++var), ++var will increment the value
of var and then return it but, if ++ is used as postfix(like: var++),
operator will return the value of operand first and then only increment it.

This can be demonstrated by an example:


#include <stdio.h>
int main()
{
int c=2,d=2;
printf("%d\n",c++); //this statement displays 2 then, only c
incremented by 1 to 3. printf("%d",++c); //this statement increments 1 to
c then, only c is displayed. return 0;
}
Output
2
4

6. Conditional operators(ternary operators):


Conditional operators return one value if condition is true and returns another value is condition
is false. This operator is also called as ternary operator.

Syntax :

(Condition? true_value: false_value);

Example :
(A > 100 ? 0 : 1);

In above example, if A is greater than 100, 0 is returned else 1 is returned. This is equal to if else
conditional statements.

Example program for conditional/ternary operators in C:

#include <stdio.h>
int main()
{
int x=1, y ;
y = ( x ==1 ? 2 : 0 ) ;
printf("x value is %d\n", x);
printf("y value is %d", y);
}

Output:
y value is 2

7. Bitwise operators

These operators are used to perform bit operations. Decimal values are
converted into binary values which are the sequence of bits and bit wise
operators work on these bits.

Bit wise operators in C language are & (bitwise AND), | (bitwise OR), ~
(bitwise OR), ^ (XOR), << (left shift) and >> (right shift).
Example:
#include>stdio.h>
main()
{
int m = 40,n = 80,AND_opr,OR_opr,XOR_opr ;
AND_opr = (m&n);
OR_opr = (m|n);
XOR_opr = (m^n);
printf("AND_opr value = %d\n",AND_opr );
printf("OR_opr value = %d\n",OR_opr );
printf("XOR_opr value = %d\n",XOR_opr );
printf("left_shift value = %d\n", m << 1);
printf("right_shift value = %d\n", m >> 1);
}

Output:
AND_opr value = 0
OR_opr value = 120
NOT_opr value = -41
XOR_opr value = 120
left_shift value = 80
right_shift value = 20

8. Special operators
C supports some special operators to perform some specific tasks.

Example:
#include<stdio.h>
main()
{
int a; float b;
double c; char d;
printf("Size of int=%d bytes\n",sizeof(a));
printf("Size of float=%d bytes\n",sizeof(b));
printf("Size of double=%d bytes\n",sizeof(c));
printf("Size of char=%d byte\n",sizeof(d));
}
Output:
Size of int = 4 bytes
Size of float = 4 bytes
Size of double = 8 bytes
Size of char = 1 byte

Type Conversion and Type casting


When variables and constants of different types are combined in an expression
then they are converted to same data type. The process of converting one
predefined type into another is called type conversion. Type conversion in c can
be classified into the following two types:

Implicit Type Conversion/Type conversion

When the type conversion is performed automatically by the compiler without


programmers intervention, such type of conversion is known as implicit type
conversion or type promotion.

The compiler converts all operands into the data type of the largest operand.

The sequence of rules that are applied while evaluating expressions are given
below:

1. All short and char are automatically converted to int, then,


2. If either of the operand is of type long double, then others will be converted
to long double and result will be long double.
3. Else, if either of the operand is double, then others are converted to double.
4. Else, if either of the operand is float, then others are converted to float.
5. Else, if either of the operand is unsigned long int, then others will be
converted to unsigned long int.
6. Else, if one of the operand is long int, and the other is unsigned int, then
1. if a long int can represent all values of an unsigned int, the unsigned int is
converted to long int.
2. otherwise, both operands are converted to unsigned long int.
7. Else, if either operand is long int then other will be converted to long int.
8. Else, if either operand is unsigned int then others will be converted to
unsigned int.

It should be noted that the final result of expression is converted to type of


variable on left side of assignment operator before assigning value to it.Also,
conversion of float to int causes truncation of fractional part, conversion of
double to float causes rounding of digits and the conversion of long int to int
causes dropping of excess higher order bits.

Explicit Type Conversion/Type casting

The type conversion performed by the programmer by posing the data type of
the expression of specific type is known as explicit type conversion. The explicit
type conversion is also known as type casting.

Type casting is done in the following form:


(datatype)expression;

Where, data_type is any valid c data type, and expression may be constant, variable or
expression.

Example: 1x=(int)a+b*d;

The following rules have to be followed while converting the expression from one type to
another to avoid the loss of information;
1. All integer types to be converted to float.
2. All float types to be converted to double.
3. All character types to be converted to integer

Examples:
/*implicit type conversion example*/

#include<stdio.h>
main()
{
int i = 17;
char c = 'c'; /* ascii value is 99 */
int sum;
sum = i + c;
printf("Value of sum : %d\n", sum );
}
Output:
Value of sum : 116

/* Explicit Type Conversion example */


#include <stdio.h>
int main ()
{
float x;
x = (float) 7/5;
printf("%f",x);
}

Output:
1.400000

Input and Output function in C language


Input: Input means to provide the program with some data to be used in the program

Output: Output means to display data on screen or write the data to a printer or a file.

C programming language provides many built-in functions to read any given input and to display
data on screen when there is a need to output the result. C programming language has standard
libraries that allow input and output in a program. The stdio.h or standard input output library in
C that has methods for input and output.
 Input output built-in functions in C falls into two categories, namely, formatted
input output (I/O) functions and unformatted input output (I/O) functions.
 printf() and scanf() are examples for formatted input and output
functions and getch(), getche(), getchar(), gets(), puts(), putchar()
etc. are examples of unformatted input output functions.

Formatted Input and Output functions:

The function printf() is used for formatted output to standard output based on a
format specification. The format specification string, along with the data to be
output,are the parameters to the printf() function.

Syntax for printf

printf( format-control-string, other-arguments );


In this syntax format is the format specification string. This string contains, for
each variable to be output, a specification beginning with the symbol % followed
by a character called the conversion character.

Example: printf(“%d is a digit”,4);

Syntax for scanf


scanf( format-control-string, other-arguments );

The function scnaf() reads and converts characters from the standards input
depending on the format specification string and stores the input in memory
locations represented by the other arguments (num1, num2,….).

For Example:
scanf(― %c %d‖,&Name, &Roll No);

Example:
Example:

#include<stdio.h>
main()
{
int a;
float f;
double d;
char ch;
printf("Enter char,int,float and double values:\n");
scanf("%c%d%f%lf",&ch,&a,&f,&d);
printf("\n char ch=%c\n",ch);
printf("int a=%d\n",a);
printf("float f=%f\n",f);
printf("double d=%lf\n",d);
}

Output:
Enter char,int,float and double values:
r
15
63.75
123568.59

char ch=r
int a=15
float f=63.750000
double d=123568.590000

You might also like