0% found this document useful (0 votes)
2 views

Document (2)

The document provides an overview of arrays in C programming, detailing their types (one-dimensional, two-dimensional, and multi-dimensional) and characteristics such as homogeneity and fixed size. It also explains operators in C, including arithmetic, relational, assignment, logical, unary, bitwise, and conditional operators, along with examples for each. Additionally, it covers looping statements (while, do-while, for, nested for), algorithms, flowcharts, and pseudocode, highlighting their definitions, advantages, and disadvantages.

Uploaded by

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

Document (2)

The document provides an overview of arrays in C programming, detailing their types (one-dimensional, two-dimensional, and multi-dimensional) and characteristics such as homogeneity and fixed size. It also explains operators in C, including arithmetic, relational, assignment, logical, unary, bitwise, and conditional operators, along with examples for each. Additionally, it covers looping statements (while, do-while, for, nested for), algorithms, flowcharts, and pseudocode, highlighting their definitions, advantages, and disadvantages.

Uploaded by

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

1. What is array? Types full explain.

Array in c is one of the most used data structures in c programming. An array in c


collection of data items of similar data Types. One or more values are store same
data Types, which may be primitive data Types such as int , char , float etc. It is a
simple and fast way of storing multiple values under a single name.

Some examples where the concept of an array can be used:


❖ List of temperatures recorded every hour in day, or a month, or a year.
❖ List of employee in an organization.
❖ List of products and their cost sold by a store.
❖ Test scores of a class of students.
❖ List of customers and their telephone numbers.
❖ Table of daily rainfall data.

Characteristics of array of an array

Homogenous: array typically store elements of the same data Type.

Fixed size : she number of element is determined at compile time .

Contiguous memory : array store elements in a single block of memory.

Declaration of an array

Data type, array name[array size];

Program

#include<stdio.h>

#include<conio.h>

main()

int number[5] = {10,20,30,40,50};

int I;

printf(“The Array Elements Are”);

for(i=; i<5; i++)

printf(“%d”, number[i]);
}

return0;

There are some types of an array :

a. One dimensional array


b. Two dimensional array
c. Multi dimensional array or three dimensional array

1. One dimensional array => The one dimensional array is collection of


elements of the same data Type store in Contiguous memory location.
The one dimensional array also known a 1D array in c are those array that
Have only one domain .
Declaration of an array
Data type, array name, array size[];
Program
#include<stdio.h>
#include<conio.h>
main()
{
char arr[6] ={‘A’,’R’,’M’,’A’,’N’\’0’};
int I=0;
while(arr[i])
{
printf(“%c”, are[I++]);
}
return0;
}
2. Two dimensional array=> A two dimensional array is a collection of
elements of the same data Type store in a table like structure with rows
and columns.

Deceleration of an array

Data type ,array name ,array size[][];


Program

#include<stdio.h>

#include<conio.h>

main()

int are[2][3]={10,20,30,40,50,60};

int I;

printf(“2D array: \n”);

for(inti=0; I<2; I++)

for(intj=0; j<2; j++)

for(int j=0; j<3; j++)

printf(“%d”, are[I][j]);

printf(“\n”);

return0;

3. Multi dimensional array => a three or multi dimensional array is collection

Elements of the same data Type store in a cube like or higher dimensional array

Structure. A 3D array needs a subscripts to define first for depth next row and

Columns.

Deceleration of an array

Data Type, array name array size [][][];


Program

#include<stdio. h>

#include<conio.h>

main()

int[3][3][3]=

{11,12,13};

{14,15,16};

{17,18,19};

{21,22,23};

{24,25,26};

{27,28,29};

{31,32,33};

{34,35,36};

{37,38,39};

};

};

printf(“printing 3D array elements \n”)

for(I=0; i<3; I++)

for(j=0; j<3; j++)


{

for(k=0; k<3; k++)

printf(“%d”,arr[i][j][k]);

printf(“\n”);

printf(“\n”);

return0;

2. What’s an operator’s ?types with Program.

In Programming, an Operator is a symbol or a keyword that is


Used to perform a specific operation or action on one or more
Operands are values or variable that are being Operated on.
For example a+b*5 where +,* are Operators. A,B are variables
(Operands) ,5 is constant and a+b*5 is an expressions.
Types of c Operators
Operators Names Operators symbols
Arithmetic Operators +,-,*,/,%
Relational Operators <,>,<=,>=,==,!=
Assignment Operators &&,||,!
Logical Operators =,+=,-=,*=,/=
Unary/ increment decrement Operators ++,--
Bitwise Operators &,|,^,<<,>>
Conditional Operators ?,:

• Arithmetic Operators: Arithmetic Operators are used to perform Arithmetic


operations in c Programming. C Programming supports 5 Arithmetic
Operators. For example: Addition, subtraction Operators, Multiplication
Operators, Division Operators, Modulo Operators.
Program
#include<stdio. h>
#include<conio. h>
main()
{
int a, b, c, i, j , k, l, m, n, p, q, r, x, y, z;
a=10,b=5;
c=a+b;
i=10,j=5;
k=i-j;
l=10,m=5;
n=l*m
p=10,q=5;
r=p/q;
x=10,y=5;
z=x % d;
Printf(“%d\n %d\n %d\n %d\n %d\n %d”, c, k, n, r, z);
getch();
}
• Relational Operators: Relational Operators in c Programming is Used for
specifying the Relation between two Operands such as greater then, less
then and equals . in c Programming we can compare the value stored
between two variables and depending on the result we can follow different
blocks using Relational Operator in c. Each Operators compare their left side
with their right side. It evaluates to 0 if the Condition is false and 1 if it is true.
Program
#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
printf(“\n Enter Two Numbers “);
scanf(“%d %d”,&a,&b);
printf(“\n a>b is =%d”, a>b);
printf(“\n a>b is =%d”, a<b);
getch();
}
• Assignment Operators: an Assignment Operator is Used to form an
Assignment expression, which assigns the value to an identifier. The most
commonly used Assignment Operator is = .

Program

#include<stdio. H>

#include<conio. h>

main()

int a,b;

a=4;

b=2;

a+=b;

printf(“\n value of a=%d”, a);

a-=b;

printf(“\n value of a =%d”, a);

a*=b;

printf(“\n value of a =%d”, a);

getch();

• Logical Operators : logical Operators are used to combine two or more


Conditions. In c, there are 3 logical Operators:

&&=> logical AND

||=> logical OR

!=> logical NOT

Program

#include<stdio.h>
#include<conio.h>

main()

char a = ‘a’;

char b = ‘\0’;

if(a&&b)

printf(“Line 1 – Condition is true\n”);

if(a||b)

printf(“Line 2- Condition is true\n”);

return0 ;

. }

• Unary/ increment or decrement Operators: The increment or decrement


Operators ate Unary Operators because they operate on a single Operand.
The increment decrement Operator increment decrement the value of the
variable by 1.these Operator should be used only with variable, they can not
be used with constant or expressions. For example: -

++x increment Operator x=x+1

--x decrement Operator x=x-1

Program (Increment Operator)

#include<stdio.h>

#include<conio.h>

main()

int x, y;
clrscr();

x=7;

y=++x;

printf(“%d”, y);

getch();

Program (decrement Operator)

#include<stdio.h>

#include<conio.h>

main()

x=7;

y= --;

printf(“%d”, y);

getch();

• Bitwise Operators: Bitwise Operators are special types of Operators that are
used in Programming the processor. In processor, mathematical operations
like: Addition subtraction, Addition and Division are done using the Bitwise
Operators which makes processing faster and saves power.

&&,||,<<,>>,~

Program(&). Program(>>)

#include<stdio.h>. #include<stdio.h>

#include<conio.h>. #include<conio.h>

main() main()

{ {

Int a, b, c; int a,b,c;


a=10; a=10;

b=25; //b=25;

c=a&b; c=a>>2

printf(“a&b=%d”,c); printf(“a>>2=%d”,c);

getch(); getch();

} }

• Conditional Operators: The Conditional expression can be used as


shorthand for some if-else statements. It is a ternary Operator consists of
two symbols : question marks(?),and colon(:).

Program

#include<stdio.h>

#include<conio.h>

main()

int a,b,c;
clrscr();

printf(“value of a&“\n”);

scanf(“%d %d”, &a,&b);

c=(a>b)?a:b;

Printf(“result is %d”,c);

getch();

3. what is a Looping statements ? Its Types with Programs .


Looping statements are also called iterative statements. There may be situations
when we need to execute a block of statements several number of times. In such
Situation , loops provide away to repeat statements and they also control how many
times the statements to be repeated . C provides different types of loops. There are
three types of loops which are as follows.:
a. While loop
b. Do while loop
c. For loop
d. Nested for loop

a .While loop: A While loop in c programming that construct repeats a block code While
specific Condition is true. in other words, in While statements get executed as long as
Condition is true. In While loop it checks the Condition first and if Condition is true then it
executes the statement s later.

Syntax

While (condition)

Statements;

Program

#include< stdio.h>
#include<conio.h>
main()
{
int I=1;
while(I<=5)
{
printf(“%d\n”, i);
i++;
}
return0;
}

b. Do while loop: The do While loop is similar to the While loop with one important
different. The body of do While loop is executed at least ones. O only then the test
expression is evaluated the syntax of do While loop it.

do
{
The body of loop
………………….…
}While(test expression)
Program
#include<stdio.h>
#include<conio.h>
main()
{
int i=1;
do
{
printf(“%d\n”, i);
i++;
}
while(I<=5)
return0;
}

C. For loop: the for loop statements get execute as long as Condition is true. For loop is
used to execute set of statements repeatedly. For loop has three part:- initiatization ,
Condition, increment/decrement.

Syntax

for(initialization ,Condition, increment/decrement)

Statement-block;

Program

#include<stdio. H>

#include<conio.h>

main()

int a;

for(a=0; a<=5; a++)


{

printf(“%d”, a);

c.Nested for loop: Nested for loop we can also Nested for loop I.e. one for loop statement
inside another for loop statement.

Syntax

For(initialisation; Condition; increment /decrement)

Statement;

Program

#include<stdio. H>

#include<conio.h>

main()

int i, j;

/*First for loop */

for(i=1; i<5; i++)

printf(“\n”);

/*second for inside the first */

for(j=1; j>0; j--)

printf(“%d”, j);
}

4.What is an algorithm with example ? Advantage and


disadvantage of algorithm.
Algorithm is a step by step instructions to solve a problem. Its special kind of solving to
problem , algorithm is written in natural language. In the algorithm, plain test is used.
Example:

Step 1: start

Step 2: Read the two numbers in to a,b

Step 3: c=a+b

Step 4: Print c

Step 5: stop

Characteristic of an algorithm

There are some characteristic where every algorithm follow.

Input: there are more quantities that are supplied.

Output: at least one quantity is produced

Definiteness: each instruction of the algorithm should be clear and unambiguous.

Finiteness: the process should be terminated after a finite number of steps.

Effectiveness: every instructions must be basic enough to be carried out theoretically or


by using paper and pencil.

Advantages

• Algorithm is Step by process, so it is very easy to understand.


• The algorithm does not follow any rules.
• Every step in algorithm as it logical sequence so it is easy to debug error.
Disadvantage
• Algorithm is time consuming.
• Big tasks are difficult to put in algorithm.
• Difficult to show branching and Looping.

5.What is an flowchart with example? Advantages and


disadvantages.
To solve a problem in a sequence or Stepwise diagrammatically or pictorially is called
flowchart. Flowcharts are a symbolic representation of steps in an algorithm. In other
words, we can also show steps of an algorithm in a graphical form by using some symbols.
This called flowcharting . some name of flowchart,:

Name. Symbols

Start /Step.

Input /output

Processing

Decision box

Flow of control

Stop
Flowchart of Adding two numbers

Start

Read A and B

C=A+B

Print C
Stop

Advantages

• Easy to draw.
• Flowchart can help clarity processes and make them easier to understand.
• Flowchart can help with problem solving.
• Proper documentation.

Disadvantages

• Creating and updating Flowchart can be time consuming.


• Flowchart can become complex and confusing.
• Difficult for modification.
• Reproduction become a problem.

6.What is a pseudo code with example? Advantages and


disadvantages and its characteristics.
Pseudo code is a programming analysis tool. Pseudo code are a means to represent an
algorithm in coded form . pseudo code is a way to describe a Program logic and structure in
a natural language. there are some Advantages and disadvantages of Pseudo code.

Example

//computes Greatest number

//Input: two values a & b

//output: Greatest no a or b

If(a>b)

Printf “ a is Greatest ”

Else
Printf “b is Greatest”

Diagram

Algorithm – Pseudo code – Program

Advantages

• Easier for non Programs.


• Pseudo code is written in a natural programming language , making a easier for
people who are not Programmer to understand.
• No specific syntax or rules and not required to execute .
Disadvantages
• Pseudo is not executable.
• Pseudo code can not be directly executed by a computer so it can not be used for
debugging or performance testing .
• Difficult to written in a mathematical logic.

Characteristics of Pseudo code

• Easy to read and understand


• Platform – independent
• Language – independent
• Focusses on logic and algorithm
• Ignores syntax and statements
• Uses natural language like statement
• Many uses Symbols and abbreviations.
• Pseudo code is used to documentation.
• Pseudo code can be Easily converted into various Programming languages such
as python, java, c++, java script, c# .

7.What is a Big O Notation with example?

Big o Notation is a mathematical Notation that describes the complexity of an algorithm


.which is the amount of time or space it requires as the Input size grows. It is used classify
algorithm based on their performance. The size of the Input its usually expressed as a
function. The input size typical represented as ‘n’ common examples of big o Notation.

Example

• 0(1) – constant time complexity


• 0(logn) – logarithmic time complexity
• 0(n log n) – linearithmic time complexity
• 0(n^2) – quadratic time complexity
• 0(2^n) – exponential time complexity
• 0(n) – linear time complexity
• 0(n!)– factorial time complexity

Diagram

8.What is a matrix? Operations on matrix with program .


A matrix is rectangular arrangement of numbers , variables, symbols or expressions that
can be used for operations like addition, subtraction, multiplication.

Operations of matrix

• Addition
• Subtraction
• Multiplication
1.Addition matrix: in c Programming, matrix addition is the process of Adding two
matrices of the same size using nested loops.

Example

[I][j] = m1[I][j]+m2[I][j];

Program

#include<stdio.h> OUTPUT

#include<conio.h>.

main(). Matrix 1

{ 1 2

int i, j; 3 4

int m1[2][2]={{1,2},{3,4}}; Matrix 2

int m2[2][2]={{5,7},{7,8}}; 5 7

int result[2][2]; 7 8

printf(“matrix\n”); Matrix result

for(i=0; i<2; i++). 6 9

{ 10 12

for(j=0; j<2; j++)

printf(“%d”, m1[i][j]);

printf(“\n”);

printf(“matrix 2\n”);

for(i=0; i<2; i++)

for(i=0; j<2; i++)


{

printf(“%d”, m2[i][j]);

printf(“\n”);

for(i=0; i<2; i++)

for(j=0; j<2; j++)

result[i][j]=m1[i][j]+m2[i][j];

printf (“result matrix\n”);

for(i=0; i<2; i++)

for(j=0; j<2; j++)

printf(“%d”, result[i][j]);

printf(“\n”);

return0;

2.Subtraction matrix: in c Programming, matrix subtraction is the process of subtraction


corresponding Elements form two or more matrices.

Example
Result[I][j]=m1[i][j]-m2[I][j];

Program

#include<stdio.h> OUTPUT

#include<conio.h>

main() Matrix 1

{ 1 2

int m1[2][2]={{1,2},{3,4}}; 3 4

int m2[2][2]={{5,7},{7,8}}; Matrix 2

int result[2][2]; 5 7

printf(“matrix 1\n”); 7 8

for(i=0; i<2; i++). Matrix result

{ -4 -5

for(j=0; j<2; j++). -4 -1

printf(“%d”, m1[I][j]);

printf(“\n”);

printf(“matrix 2\n”);

for(i=0; i<2; i++)

for(j=0; j<2; j++)

printf(“%d”, m2[i][j]);

printf(“\n”);
}

for(i=0; i<2; i++);

for(j=0; j<2; j++)

result[i][j]=m1[I][j]-m2[I][j];

printf(“result of matrix\n”);

for(j=0; j<2; j++)

printf(“%d”, result[I][j]);

printf(“\n”);

return0;

3.Multiplication matrix: in c matrix multiplication is the process of Multiplying two


matrices to get a new matrix that represents the composition of the original two matrices.
Example:

Result[I][j]=m1[I][j]*m2[I][j];

Program

#include<stdio.h> OUTPUT

#include<conio.h>

main(). Matrix 1

{ 1 2

int i, j; 3 4

int m1[2][2] ={{1,2},{3,4}};


int m2 [2][2]={{5,7},{7,8}}; Matrix 2

int result[2][2] ; 5 7

printf(“matrix 1\n”); 7 8

for(i=0; i<2; i++). Matrix result

{ 5 14

for(j=0; j<2; j++). 21 40

printf(“%d”, m1[I][j]);

printf(“\n”);

printf(“matrix 2\n”);

for(i=0; i<2; i++)

for(j=0; j<2; j++)

printf(“%d”,m2[I][j]);

printf(“\n”);

for(i=0; i<2; i++)

for(j=0; j<2; j++)

result[I][j] =m1[I][j] × m2[I][j];

}
}

printf (“result of matrix\n”);

for(i=0; i<2; i++);

for(j=0; j<2; j++)

printf(“%d”, result[I][j]);

return0;

9.What is Data type? Full explain.


A Data type is a set of values and set of operation that can be applied to those values. In c
Programming, Data type are used to declare variables and specify the Data type of data
that can be store in them. In other words, in c Programming language Data type refers to
an experience system used for Declaring variables or function of different types. There are
data Types in c:- Diagram
• Basic Types: the arithmetic types and are further classified into: (a). Integer types
(b)floating point type
• The Type void : The Type specifies void indicates that no value is available.
• Derived types: the include (a) pointer types, (b) Array types, (c) structure types, (d)
union types and ( e) function types.
• Enumerated types: they are again arithmetic types and they are used to define
variables that can only assign certain discrete integer values throughout the
program.

Storage size and ranges are shown below: -

Size Format
Data Type (bytes) Range Specifier

short int 2 -32,768 to 32,767 %hd

unsigned
2 0 to 65,535 %hu
short int

unsigned int 4 0 to 4,294,967,295 %u

-2,147,483,648 to
int 4 %d
2,147,483,647

-2,147,483,648 to
long int 4 %ld
2,147,483,647
Size Format
Data Type (bytes) Range Specifier

unsigned
4 0 to 4,294,967,295 %lu
long int

long long int 8 -(2^63) to (2^63)-1 %lld

unsigned 0 to
8 %llu
long long int 18,446,744,073,709,551,615

signed char 1 -128 to 127 %c

unsigned char 1 0 to 255 %c

float 4 1.2E-38 to 3.4E+38 %f

double 8 1.7E-308 to 1.7E+308 %lf

long double 16 3.4E-4932 to 1.1E+4932

• User define: user define include enum. Enum type allow you to create a new data
Type that consists of set of named constants. Enum is a value type that enables you
to define a set of named values.
10.Discuss a Programming languages with translators ?
Programming languages are very necessary to communicate. Computer the help of
languages to understand user’s instructions or input .Programming languages are:

(a)machine language

(b)Assembly language

( c)High level language

(d)compiler translator

(e)interpreter translator

(a).Machine language:- it is language of Programming language. Machine language is a


binary language that understood by computer. To computer processer can understand
directly but difficult for human to understand and write to Machine language because it
consists of only 0 and1 .

Diagram

Machine language ->no need translator ->Machine language

(b).Assembly language: - it is a Programming language. This language is a used to write


Programs that are directly carry out by the computer but computer language cannot
understand Assembly language directly, so the computer takes the help of translator called
a Assembler to understand this language. In this language are many symbol . symbolic is
also called mnemonic. Example:

ADD, MOV, SUB, MUL .

Diagram

Assembly language -> Assembler -> machine language

(C).High level language: - it is Programming languages. These are further away to Machine
language and closer to human language. The computer cannot understand this language
directly so the compiler which is a translator or converts the high level language into
Machine language so that it can be understand easily. There are many language in this
language such as :- java , c, c++ , fortan, python, cobol, html etc.

Diagram

High level language-> compiler -> Machine language


(d).Interpreter:- An interpreter is a software Programs that directly executes high level
Programming language code . translates high level language code into Machine code in
Programming, we can execute a Program in two way . firstly through complication and
secondly through on interpreter.

Diagram

Source -> interpreter -> output

(e).Compiler: - a compiler is a software Program that translates source code written in a


high level programming language . example: c++, java, python

Diagram

HLL-> compiler -> low level language


What is c language?
C is procedural Programming language. It developed by Dennis Ritchie in the year 1972 at
bell laboratories of AT&T (American telephone& telegram) labs . it was mainly developed as
system Programming language to write the Unix operating system .

Syntax

#include<stdio.h>

#include<conio.h>

Main()

// code/ statement

C is widely used

• C is widely used for developing os such as Unix and Linux .


• C is used in embedded system, such as microcontrollers, robots and automotive
system.
• C is used in Database system such as MYSQL and PostgreSQL .
• C is widely used for Creating desktop applications.
• C is widely used for designing compilers .
INDEX
S.NO. TOPIC. PAGE NO. SIGNATURE

1. What is c language 1

2. Full explain Array 2-5

3. Full explain Operator’s 5-11

4. Looping statements 11-14

5. Algorithm 15

6. Flowchart 15-18

7. Pseudo code 18-19

8. Big o notation 19-20

9. Matrix 20-25

10. Data Type 25-28

11. Programming languages and. 28-30

translator

You might also like