SlideShare a Scribd company logo
Rumman Ansari
All arrays consist of contiguous memory locations. The lowest address corresponds
to the first element and the highest address to the last element.
Declaring Arrays
Type arrayName [ arraySize ];
double balance[10];
int balance[16];
float balance[15];
Array
one-dimensional array
two-dimensional array
three-dimensional array
Initialization of one-dimensional array:
int age[5]={2,4,34,3,4};
int age[]={2,4,34,3,4};
Accessing array elements
scanf("%d",&age[i]);
printf("%d",age[i]);
Example of array in C programming
C program to find the sum marks of n students using arrays
#include <stdio.h>
int main(){
int marks[10],i,n,sum=0;
printf("Enter number of students: ");
scanf("%d",&n);
for(i=0;i<n;++i){
printf("Enter marks of student%d: ",i+1);
scanf("%d",&marks[i]);
sum+=marks[i];
}
printf("Sum= %d",sum);
return 0;
}
Initialization of two-dimensional array:
float a[2][6];
int c[2][3]={ {1,3,0}, {-1,5,9} };
OR
int c[][3]={ {1,3,0}, {-1,5,9} };
OR
int c[2][3]={1,3,0,-1,5,9};
int a[3][4] = {
{0, 1, 2, 3} , /* initializers for row indexed by 0 */
{4, 5, 6, 7} , /* initializers for row indexed by 1 */
{8, 9, 10, 11} /* initializers for row indexed by 2 */
};
int a[3][4] = {0,1,2,3,4,5,6,7,8,9,10,11};
#include <stdio.h>
int main ()
{
/* an array with 5 rows and 2 columns*/
int a[5][2] = { {0,0}, {1,2}, {2,4}, {3,6},{4,8}};
int i, j;
/* output each array element's value */
for ( i = 0; i < 5; i++ )
{
for ( j = 0; j < 2; j++ )
{
printf("a[%d][%d] = %dn", i,j, a[i][j] );
}
}
return 0;
}
Accessing Two-Dimensional Array Elements:
Write a C program to find sum of two matrix of order 2*2 using multidimensional arrays where, elements of matrix
are entered by user.
#include <stdio.h>
int main(){
float a[2][2], b[2][2], c[2][2];
int i,j;
printf("Enter the elements of 1st matrixn");
for(i=0;i<2;++i)
for(j=0;j<2;++j){
printf("Enter a%d%d: ",i+1,j+1);
scanf("%f",&a[i][j]);
}
printf("Enter the elements of 2nd matrixn");
for(i=0;i<2;++i)
for(j=0;j<2;++j){
printf("Enter b%d%d: ",i+1,j+1);
scanf("%f",&b[i][j]);
}
for(i=0;i<2;++i)
for(j=0;j<2;++j){
c[i][j]=a[i][j]+b[i][j]; /* Sum of corresponding elements of two arrays. */
}
printf("nSum Of Matrix:");
for(i=0;i<2;++i)
for(j=0;j<2;++j){
printf("%.1ft",c[i][j]);
if(j==1) /* To display matrix sum in order. */
printf("n");
}
return 0;
}
#include <stdio.h>
int main(){
int a[2][2], b[2][2], c[2][2];
int i,j;
printf("Enter the elements of 1st matrixn");
for(i=0;i<2;++i)
for(j=0;j<2;++j){
printf("Enter a%d%d: ",i+1,j+1);
scanf("%d",&a[i][j]);
}
printf("Enter the elements of 2nd matrixn");
for(i=0;i<2;++i)
for(j=0;j<2;++j){
printf("Enter b%d%d: ",i+1,j+1);
scanf("%d",&b[i][j]);
}
Write a C program to find sum of two matrix of order 2*2 using multidimensional
arrays where, elements of matrix are entered by user.
// this is 1st matrix
printf(" this is 1st matrix nn");
for(i=0;i<2;++i)
{
for(j=0;j<2;++j)
{
printf("%d ",a[i][j]);
}
printf(" n");
}
//this is second matrix
printf(" this is second matrix nn");
for(i=0;i<2;++i)
{
for(j=0;j<2;++j)
{
printf("%d ",b[i][j]);
}
printf(" n");
}
for(i=0;i<2;++i)
for(j=0;j<2;++j){
/* Writing the elements of multidimensional array using loop. */
c[i][j]=a[i][j]+b[i][j];
/* Sum of corresponding elements of two arrays. */
}
printf("nSum Of Matrix:");
for(i=0;i<2;++i)
{
for(j=0;j<2;++j)
{
printf("%dt",c[i][j]);
}
printf(" n");
}
return 0;
}
Display Largest Element of an array
// Display Largest Element of an array
#include <stdio.h>
int main(){
int i,n;
float arr[100];
printf("Enter total number of elements(1 to 100): ");
scanf("%d",&n);
printf("n");
for(i=0;i<n;++i) /* Stores number entered by user. */
{
printf("Enter Number %d: ",i+1);
scanf("%f",&arr[i]);
}
for(i=1;i<n;++i) /* Loop to store largest number to arr[0] */
{
if(arr[0]<arr[i]) /* Change < to > if you want to find smallest element*/
arr[0]=arr[i];
}
printf("Largest element = %.2f",arr[0]);
return 0;
}
Find Transpose of a Matrix
#include <stdio.h>
int main()
{
int a[10][10], trans[10][10], r, c, i, j;
printf("Enter rows and column of matrix: ");
scanf("%d %d", &r, &c);
/* Storing element of matrix entered by user in array a[][].
*/
printf("nEnter elements of matrix:n");
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
printf("Enter elements a%d%d: ",i+1,j+1);
scanf("%d",&a[i][j]);
}
/* Displaying the matrix a[][] */
printf("nEntered Matrix: n");
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
printf("%d ",a[i][j]);
if(j==c-1)
printf("nn");
}
/* Finding transpose of matrix a[][] and storing it in
array trans[][]. */
for(i=0; i<r; ++i)
for(j=0; j<c; ++j)
{
trans[j][i]=a[i][j];
}
/* Displaying the transpose,i.e, Displaying array
trans[][]. */
printf("nTranspose of Matrix:n");
for(i=0; i<c; ++i)
for(j=0; j<r; ++j)
{
printf("%d ",trans[i][j]);
if(j==r-1)
printf("nn");
}
return 0;
}
Multiply to matrix in C programming
#include <stdio.h>
int main()
{
int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k;
printf("Enter rows and column for first matrix: ");
scanf("%d%d", &r1, &c1);
printf("Enter rows and column for second matrix: ");
scanf("%d%d",&r2, &c2);
/* If colum of first matrix in not equal to row of second matrix, asking user to enter
the size of matrix again. */
while (c1!=r2)
{
printf("Error! column of first matrix not equal to row of second.nn");
printf("Enter rows and column for first matrix: ");
scanf("%d%d", &r1, &c1);
printf("Enter rows and column for second matrix: ");
scanf("%d%d",&r2, &c2);
}
/* Storing elements of first matrix. */
printf("nEnter elements of matrix 1:n");
for(i=0; i<r1; ++i)
for(j=0; j<c1; ++j)
{
printf("Enter elements a%d%d: ",i+1,j+1);
scanf("%d",&a[i][j]);
}
/* Storing elements of second matrix. */
printf("nEnter elements of matrix 2:n");
for(i=0; i<r2; ++i)
for(j=0; j<c2; ++j)
{
printf("Enter elements b%d%d: ",i+1,j+1);
scanf("%d",&b[i][j]);
}
/* Initializing elements of matrix mult to 0.*/
for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
{
mult[i][j]=0;
}
/* Multiplying matrix a and b and storing in array mult. */
for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
for(k=0; k<c1; ++k)
{
mult[i][j]+=a[i][k]*b[k][j];
}
/* Displaying the multiplication of two matrix. */
printf("nOutput Matrix:n");
for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
{
printf("%d ",mult[i][j]);
if(j==c2-1)
printf("nn");
}
return 0;
}
Ad

More Related Content

What's hot (20)

Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
Saranya saran
 
7 functions
7  functions7  functions
7 functions
MomenMostafa
 
C programming
C programmingC programming
C programming
Samsil Arefin
 
Intro to c chapter cover 1 4
Intro to c chapter cover 1 4Intro to c chapter cover 1 4
Intro to c chapter cover 1 4
Hazwan Arif
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
MomenMostafa
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
Saranya saran
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
MomenMostafa
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
eShikshak
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
MomenMostafa
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
MomenMostafa
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nm
mohamed sikander
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
MomenMostafa
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
Muthuganesh S
 
C tech questions
C tech questionsC tech questions
C tech questions
vijay00791
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
Amit Kapoor
 
4. chapter iii
4. chapter iii4. chapter iii
4. chapter iii
Chhom Karath
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
Chhom Karath
 
Functions
FunctionsFunctions
Functions
SANTOSH RATH
 
Function basics
Function basicsFunction basics
Function basics
mohamed sikander
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
Saranya saran
 
Intro to c chapter cover 1 4
Intro to c chapter cover 1 4Intro to c chapter cover 1 4
Intro to c chapter cover 1 4
Hazwan Arif
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
MomenMostafa
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
Saranya saran
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
MomenMostafa
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
eShikshak
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
MomenMostafa
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
MomenMostafa
 
Understanding storage class using nm
Understanding storage class using nmUnderstanding storage class using nm
Understanding storage class using nm
mohamed sikander
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
MomenMostafa
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
Muthuganesh S
 
C tech questions
C tech questionsC tech questions
C tech questions
vijay00791
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
Amit Kapoor
 

Viewers also liked (20)

How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program
Rumman Ansari
 
C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1
Rumman Ansari
 
C Programming Language Part 5
C Programming Language Part 5C Programming Language Part 5
C Programming Language Part 5
Rumman Ansari
 
C Programming Language Step by Step Part 3
C Programming Language Step by Step Part 3C Programming Language Step by Step Part 3
C Programming Language Step by Step Part 3
Rumman Ansari
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1
Rumman Ansari
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
avikdhupar
 
My first program in c, hello world !
My first program in c, hello world !My first program in c, hello world !
My first program in c, hello world !
Rumman Ansari
 
Build Features, Not Apps
Build Features, Not AppsBuild Features, Not Apps
Build Features, Not Apps
Natasha Murashev
 
Medicaid organization profile
Medicaid organization profileMedicaid organization profile
Medicaid organization profile
Anurag Byala
 
Основи мови Ci
Основи мови CiОснови мови Ci
Основи мови Ci
Escuela
 
C programming tutorial for beginners
C programming tutorial for beginnersC programming tutorial for beginners
C programming tutorial for beginners
Thiyagarajan Soundhiran
 
C tutorial
C tutorialC tutorial
C tutorial
Chukka Nikhil Chakravarthy
 
C program compiler presentation
C program compiler presentationC program compiler presentation
C program compiler presentation
Rigvendra Kumar Vardhan
 
Software testing Training Syllabus Course
Software testing Training Syllabus CourseSoftware testing Training Syllabus Course
Software testing Training Syllabus Course
TOPS Technologies
 
Steps for Developing a 'C' program
 Steps for Developing a 'C' program Steps for Developing a 'C' program
Steps for Developing a 'C' program
Sahithi Naraparaju
 
Introduction to programming with c,
Introduction to programming with c,Introduction to programming with c,
Introduction to programming with c,
Hossain Md Shakhawat
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
Bharat Kalia
 
Composicio Digital _Practica Pa4
Composicio Digital _Practica Pa4Composicio Digital _Practica Pa4
Composicio Digital _Practica Pa4
Marcos Baldovi
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
 
How c program execute in c program
How c program execute in c program How c program execute in c program
How c program execute in c program
Rumman Ansari
 
C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1C Programming Language Step by Step Part 1
C Programming Language Step by Step Part 1
Rumman Ansari
 
C Programming Language Part 5
C Programming Language Part 5C Programming Language Part 5
C Programming Language Part 5
Rumman Ansari
 
C Programming Language Step by Step Part 3
C Programming Language Step by Step Part 3C Programming Language Step by Step Part 3
C Programming Language Step by Step Part 3
Rumman Ansari
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1
Rumman Ansari
 
Basics of C programming
Basics of C programmingBasics of C programming
Basics of C programming
avikdhupar
 
My first program in c, hello world !
My first program in c, hello world !My first program in c, hello world !
My first program in c, hello world !
Rumman Ansari
 
Medicaid organization profile
Medicaid organization profileMedicaid organization profile
Medicaid organization profile
Anurag Byala
 
Основи мови Ci
Основи мови CiОснови мови Ci
Основи мови Ci
Escuela
 
Software testing Training Syllabus Course
Software testing Training Syllabus CourseSoftware testing Training Syllabus Course
Software testing Training Syllabus Course
TOPS Technologies
 
Steps for Developing a 'C' program
 Steps for Developing a 'C' program Steps for Developing a 'C' program
Steps for Developing a 'C' program
Sahithi Naraparaju
 
Introduction to programming with c,
Introduction to programming with c,Introduction to programming with c,
Introduction to programming with c,
Hossain Md Shakhawat
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
Bharat Kalia
 
Composicio Digital _Practica Pa4
Composicio Digital _Practica Pa4Composicio Digital _Practica Pa4
Composicio Digital _Practica Pa4
Marcos Baldovi
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
 
Ad

Similar to C Programming Language Part 8 (20)

ADA FILE
ADA FILEADA FILE
ADA FILE
Gaurav Singh
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
 
week-5x
week-5xweek-5x
week-5x
KITE www.kitecolleges.com
 
2D array
2D array2D array
2D array
A. S. M. Shafi
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
C programs
C programsC programs
C programs
Koshy Geoji
 
Cpds lab
Cpds labCpds lab
Cpds lab
praveennallavelly08
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
manoj11manu
 
Pnno
PnnoPnno
Pnno
shristichaudhary4
 
array.ppt
array.pptarray.ppt
array.ppt
DeveshDewangan5
 
C Prog - Pointers
C Prog - PointersC Prog - Pointers
C Prog - Pointers
vinay arora
 
Arrays
ArraysArrays
Arrays
mohamed sikander
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
Er Ritu Aggarwal
 
Vcs16
Vcs16Vcs16
Vcs16
Malikireddy Bramhananda Reddy
 
DAA Lab File C Programs
DAA Lab File C ProgramsDAA Lab File C Programs
DAA Lab File C Programs
Kandarp Tiwari
 
Cpd lecture im 207
Cpd lecture im 207Cpd lecture im 207
Cpd lecture im 207
Syed Tanveer
 
SaraPIC
SaraPICSaraPIC
SaraPIC
Sara Sahu
 
Sorting programs
Sorting programsSorting programs
Sorting programs
Varun Garg
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
sandeep kumbhkar
 
Ad

More from Rumman Ansari (17)

Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
Rumman Ansari
 
C programming exercises and solutions
C programming exercises and solutions C programming exercises and solutions
C programming exercises and solutions
Rumman Ansari
 
Java Tutorial best website
Java Tutorial best websiteJava Tutorial best website
Java Tutorial best website
Rumman Ansari
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and Answers
Rumman Ansari
 
servlet programming
servlet programmingservlet programming
servlet programming
Rumman Ansari
 
C program to write c program without using main function
C program to write c program without using main functionC program to write c program without using main function
C program to write c program without using main function
Rumman Ansari
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program execution
Rumman Ansari
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
Rumman Ansari
 
What is token c programming
What is token c programmingWhat is token c programming
What is token c programming
Rumman Ansari
 
What is identifier c programming
What is identifier c programmingWhat is identifier c programming
What is identifier c programming
Rumman Ansari
 
What is keyword in c programming
What is keyword in c programmingWhat is keyword in c programming
What is keyword in c programming
Rumman Ansari
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
Rumman Ansari
 
C Programming
C ProgrammingC Programming
C Programming
Rumman Ansari
 
Tail recursion
Tail recursionTail recursion
Tail recursion
Rumman Ansari
 
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structure
Rumman Ansari
 
Spyware manual
Spyware  manualSpyware  manual
Spyware manual
Rumman Ansari
 
Linked list
Linked listLinked list
Linked list
Rumman Ansari
 
C programming exercises and solutions
C programming exercises and solutions C programming exercises and solutions
C programming exercises and solutions
Rumman Ansari
 
Java Tutorial best website
Java Tutorial best websiteJava Tutorial best website
Java Tutorial best website
Rumman Ansari
 
Java Questions and Answers
Java Questions and AnswersJava Questions and Answers
Java Questions and Answers
Rumman Ansari
 
C program to write c program without using main function
C program to write c program without using main functionC program to write c program without using main function
C program to write c program without using main function
Rumman Ansari
 
Steps for c program execution
Steps for c program executionSteps for c program execution
Steps for c program execution
Rumman Ansari
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
Rumman Ansari
 
What is token c programming
What is token c programmingWhat is token c programming
What is token c programming
Rumman Ansari
 
What is identifier c programming
What is identifier c programmingWhat is identifier c programming
What is identifier c programming
Rumman Ansari
 
What is keyword in c programming
What is keyword in c programmingWhat is keyword in c programming
What is keyword in c programming
Rumman Ansari
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
Rumman Ansari
 
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structure
Rumman Ansari
 

Recently uploaded (20)

introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdfReese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
W1 WDM_Principle and basics to know.pptx
W1 WDM_Principle and basics to know.pptxW1 WDM_Principle and basics to know.pptx
W1 WDM_Principle and basics to know.pptx
muhhxx51
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Routing Riverdale - A New Bus Connection
Routing Riverdale - A New Bus ConnectionRouting Riverdale - A New Bus Connection
Routing Riverdale - A New Bus Connection
jzb7232
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Comparing Emerging Cloud Platforms –like AWS, Azure, Google Cloud, Cloud Stac...
Comparing Emerging Cloud Platforms –like AWS, Azure, Google Cloud, Cloud Stac...Comparing Emerging Cloud Platforms –like AWS, Azure, Google Cloud, Cloud Stac...
Comparing Emerging Cloud Platforms –like AWS, Azure, Google Cloud, Cloud Stac...
SiddhiKulkarni18
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
2025 Apply BTech CEC .docx
2025 Apply BTech CEC                 .docx2025 Apply BTech CEC                 .docx
2025 Apply BTech CEC .docx
tusharmanagementquot
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdfReese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary_ The Role of Perseverance in Engineering Success.pdf
Reese McCrary
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
W1 WDM_Principle and basics to know.pptx
W1 WDM_Principle and basics to know.pptxW1 WDM_Principle and basics to know.pptx
W1 WDM_Principle and basics to know.pptx
muhhxx51
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
theory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptxtheory-slides-for react for beginners.pptx
theory-slides-for react for beginners.pptx
sanchezvanessa7896
 
Routing Riverdale - A New Bus Connection
Routing Riverdale - A New Bus ConnectionRouting Riverdale - A New Bus Connection
Routing Riverdale - A New Bus Connection
jzb7232
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Comparing Emerging Cloud Platforms –like AWS, Azure, Google Cloud, Cloud Stac...
Comparing Emerging Cloud Platforms –like AWS, Azure, Google Cloud, Cloud Stac...Comparing Emerging Cloud Platforms –like AWS, Azure, Google Cloud, Cloud Stac...
Comparing Emerging Cloud Platforms –like AWS, Azure, Google Cloud, Cloud Stac...
SiddhiKulkarni18
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 

C Programming Language Part 8

  • 2. All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. Declaring Arrays Type arrayName [ arraySize ]; double balance[10]; int balance[16]; float balance[15];
  • 3. Array one-dimensional array two-dimensional array three-dimensional array Initialization of one-dimensional array: int age[5]={2,4,34,3,4}; int age[]={2,4,34,3,4};
  • 4. Accessing array elements scanf("%d",&age[i]); printf("%d",age[i]); Example of array in C programming C program to find the sum marks of n students using arrays #include <stdio.h> int main(){ int marks[10],i,n,sum=0; printf("Enter number of students: "); scanf("%d",&n); for(i=0;i<n;++i){ printf("Enter marks of student%d: ",i+1); scanf("%d",&marks[i]); sum+=marks[i]; } printf("Sum= %d",sum); return 0; }
  • 5. Initialization of two-dimensional array: float a[2][6]; int c[2][3]={ {1,3,0}, {-1,5,9} }; OR int c[][3]={ {1,3,0}, {-1,5,9} }; OR int c[2][3]={1,3,0,-1,5,9}; int a[3][4] = { {0, 1, 2, 3} , /* initializers for row indexed by 0 */ {4, 5, 6, 7} , /* initializers for row indexed by 1 */ {8, 9, 10, 11} /* initializers for row indexed by 2 */ }; int a[3][4] = {0,1,2,3,4,5,6,7,8,9,10,11};
  • 6. #include <stdio.h> int main () { /* an array with 5 rows and 2 columns*/ int a[5][2] = { {0,0}, {1,2}, {2,4}, {3,6},{4,8}}; int i, j; /* output each array element's value */ for ( i = 0; i < 5; i++ ) { for ( j = 0; j < 2; j++ ) { printf("a[%d][%d] = %dn", i,j, a[i][j] ); } } return 0; } Accessing Two-Dimensional Array Elements:
  • 7. Write a C program to find sum of two matrix of order 2*2 using multidimensional arrays where, elements of matrix are entered by user. #include <stdio.h> int main(){ float a[2][2], b[2][2], c[2][2]; int i,j; printf("Enter the elements of 1st matrixn"); for(i=0;i<2;++i) for(j=0;j<2;++j){ printf("Enter a%d%d: ",i+1,j+1); scanf("%f",&a[i][j]); } printf("Enter the elements of 2nd matrixn"); for(i=0;i<2;++i) for(j=0;j<2;++j){ printf("Enter b%d%d: ",i+1,j+1); scanf("%f",&b[i][j]); } for(i=0;i<2;++i) for(j=0;j<2;++j){ c[i][j]=a[i][j]+b[i][j]; /* Sum of corresponding elements of two arrays. */ } printf("nSum Of Matrix:"); for(i=0;i<2;++i) for(j=0;j<2;++j){ printf("%.1ft",c[i][j]); if(j==1) /* To display matrix sum in order. */ printf("n"); } return 0; }
  • 8. #include <stdio.h> int main(){ int a[2][2], b[2][2], c[2][2]; int i,j; printf("Enter the elements of 1st matrixn"); for(i=0;i<2;++i) for(j=0;j<2;++j){ printf("Enter a%d%d: ",i+1,j+1); scanf("%d",&a[i][j]); } printf("Enter the elements of 2nd matrixn"); for(i=0;i<2;++i) for(j=0;j<2;++j){ printf("Enter b%d%d: ",i+1,j+1); scanf("%d",&b[i][j]); } Write a C program to find sum of two matrix of order 2*2 using multidimensional arrays where, elements of matrix are entered by user.
  • 9. // this is 1st matrix printf(" this is 1st matrix nn"); for(i=0;i<2;++i) { for(j=0;j<2;++j) { printf("%d ",a[i][j]); } printf(" n"); } //this is second matrix printf(" this is second matrix nn"); for(i=0;i<2;++i) { for(j=0;j<2;++j) { printf("%d ",b[i][j]); } printf(" n"); }
  • 10. for(i=0;i<2;++i) for(j=0;j<2;++j){ /* Writing the elements of multidimensional array using loop. */ c[i][j]=a[i][j]+b[i][j]; /* Sum of corresponding elements of two arrays. */ } printf("nSum Of Matrix:"); for(i=0;i<2;++i) { for(j=0;j<2;++j) { printf("%dt",c[i][j]); } printf(" n"); } return 0; }
  • 11. Display Largest Element of an array // Display Largest Element of an array #include <stdio.h> int main(){ int i,n; float arr[100]; printf("Enter total number of elements(1 to 100): "); scanf("%d",&n); printf("n"); for(i=0;i<n;++i) /* Stores number entered by user. */ { printf("Enter Number %d: ",i+1); scanf("%f",&arr[i]); } for(i=1;i<n;++i) /* Loop to store largest number to arr[0] */ { if(arr[0]<arr[i]) /* Change < to > if you want to find smallest element*/ arr[0]=arr[i]; } printf("Largest element = %.2f",arr[0]); return 0; }
  • 12. Find Transpose of a Matrix #include <stdio.h> int main() { int a[10][10], trans[10][10], r, c, i, j; printf("Enter rows and column of matrix: "); scanf("%d %d", &r, &c); /* Storing element of matrix entered by user in array a[][]. */ printf("nEnter elements of matrix:n"); for(i=0; i<r; ++i) for(j=0; j<c; ++j) { printf("Enter elements a%d%d: ",i+1,j+1); scanf("%d",&a[i][j]); }
  • 13. /* Displaying the matrix a[][] */ printf("nEntered Matrix: n"); for(i=0; i<r; ++i) for(j=0; j<c; ++j) { printf("%d ",a[i][j]); if(j==c-1) printf("nn"); } /* Finding transpose of matrix a[][] and storing it in array trans[][]. */ for(i=0; i<r; ++i) for(j=0; j<c; ++j) { trans[j][i]=a[i][j]; }
  • 14. /* Displaying the transpose,i.e, Displaying array trans[][]. */ printf("nTranspose of Matrix:n"); for(i=0; i<c; ++i) for(j=0; j<r; ++j) { printf("%d ",trans[i][j]); if(j==r-1) printf("nn"); } return 0; }
  • 15. Multiply to matrix in C programming #include <stdio.h> int main() { int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k; printf("Enter rows and column for first matrix: "); scanf("%d%d", &r1, &c1); printf("Enter rows and column for second matrix: "); scanf("%d%d",&r2, &c2); /* If colum of first matrix in not equal to row of second matrix, asking user to enter the size of matrix again. */ while (c1!=r2) { printf("Error! column of first matrix not equal to row of second.nn"); printf("Enter rows and column for first matrix: "); scanf("%d%d", &r1, &c1); printf("Enter rows and column for second matrix: "); scanf("%d%d",&r2, &c2); }
  • 16. /* Storing elements of first matrix. */ printf("nEnter elements of matrix 1:n"); for(i=0; i<r1; ++i) for(j=0; j<c1; ++j) { printf("Enter elements a%d%d: ",i+1,j+1); scanf("%d",&a[i][j]); } /* Storing elements of second matrix. */ printf("nEnter elements of matrix 2:n"); for(i=0; i<r2; ++i) for(j=0; j<c2; ++j) { printf("Enter elements b%d%d: ",i+1,j+1); scanf("%d",&b[i][j]); }
  • 17. /* Initializing elements of matrix mult to 0.*/ for(i=0; i<r1; ++i) for(j=0; j<c2; ++j) { mult[i][j]=0; } /* Multiplying matrix a and b and storing in array mult. */ for(i=0; i<r1; ++i) for(j=0; j<c2; ++j) for(k=0; k<c1; ++k) { mult[i][j]+=a[i][k]*b[k][j]; }
  • 18. /* Displaying the multiplication of two matrix. */ printf("nOutput Matrix:n"); for(i=0; i<r1; ++i) for(j=0; j<c2; ++j) { printf("%d ",mult[i][j]); if(j==c2-1) printf("nn"); } return 0; }