Document (2)
Document (2)
Declaration of an array
Program
#include<stdio.h>
#include<conio.h>
main()
int I;
printf(“%d”, number[i]);
}
return0;
Deceleration of an array
#include<stdio.h>
#include<conio.h>
main()
int are[2][3]={10,20,30,40,50,60};
int I;
printf(“%d”, are[I][j]);
printf(“\n”);
return0;
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
#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(“%d”,arr[i][j][k]);
printf(“\n”);
printf(“\n”);
return0;
Program
#include<stdio. H>
#include<conio. h>
main()
int a,b;
a=4;
b=2;
a+=b;
a-=b;
a*=b;
getch();
||=> logical OR
Program
#include<stdio.h>
#include<conio.h>
main()
char a = ‘a’;
char b = ‘\0’;
if(a&&b)
if(a||b)
return0 ;
. }
#include<stdio.h>
#include<conio.h>
main()
int x, y;
clrscr();
x=7;
y=++x;
printf(“%d”, y);
getch();
#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()
{ {
b=25; //b=25;
c=a&b; c=a>>2
printf(“a&b=%d”,c); printf(“a>>2=%d”,c);
getch(); getch();
} }
Program
#include<stdio.h>
#include<conio.h>
main()
int a,b,c;
clrscr();
printf(“value of a&“\n”);
c=(a>b)?a:b;
Printf(“result is %d”,c);
getch();
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
Statement-block;
Program
#include<stdio. H>
#include<conio.h>
main()
int 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
Statement;
Program
#include<stdio. H>
#include<conio.h>
main()
int i, j;
printf(“\n”);
printf(“%d”, j);
}
Step 1: start
Step 3: c=a+b
Step 4: Print c
Step 5: stop
Characteristic of an algorithm
Advantages
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
Example
//output: Greatest no a or b
If(a>b)
Printf “ a is Greatest ”
Else
Printf “b is Greatest”
Diagram
Advantages
Example
Diagram
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 m2[2][2]={{5,7},{7,8}}; 5 7
int result[2][2]; 7 8
{ 10 12
printf(“%d”, m1[i][j]);
printf(“\n”);
printf(“matrix 2\n”);
printf(“%d”, m2[i][j]);
printf(“\n”);
result[i][j]=m1[i][j]+m2[i][j];
printf(“%d”, result[i][j]);
printf(“\n”);
return0;
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 result[2][2]; 5 7
printf(“matrix 1\n”); 7 8
{ -4 -5
printf(“%d”, m1[I][j]);
printf(“\n”);
printf(“matrix 2\n”);
printf(“%d”, m2[i][j]);
printf(“\n”);
}
result[i][j]=m1[I][j]-m2[I][j];
printf(“result of matrix\n”);
printf(“%d”, result[I][j]);
printf(“\n”);
return0;
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 result[2][2] ; 5 7
printf(“matrix 1\n”); 7 8
{ 5 14
printf(“%d”, m1[I][j]);
printf(“\n”);
printf(“matrix 2\n”);
printf(“%d”,m2[I][j]);
printf(“\n”);
}
}
printf(“%d”, result[I][j]);
return0;
Size Format
Data Type (bytes) Range Specifier
unsigned
2 0 to 65,535 %hu
short int
-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
unsigned 0 to
8 %llu
long long int 18,446,744,073,709,551,615
• 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
(d)compiler translator
(e)interpreter translator
Diagram
Diagram
(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
Diagram
Diagram
Syntax
#include<stdio.h>
#include<conio.h>
Main()
// code/ statement
C is widely used
1. What is c language 1
5. Algorithm 15
6. Flowchart 15-18
9. Matrix 20-25
translator