Lectures on Programming with Arrays
for
Open Educational Resource
On
Programming Concepts (EC208)
by
Dr. Piyush Charan
Assistant Professor
Department of Electronics and Communication Engg.
Integral University, Lucknow
Introduction to Arrays
11/2/2020 Dr. Piyush Charan, Dept. of ECE, Integral University, Lucknow 2
Simple program on Arrays to accept ‘n’
numbers and display the same
11/2/2020 Dr. Piyush Charan, Dept. of ECE, Integral University, Lucknow 3
11/2/2020 Dr. Piyush Charan, Dept. of ECE, Integral University, Lucknow 4
11/2/2020 Dr. Piyush Charan, Dept. of ECE, Integral University, Lucknow 5
11/2/2020 Dr. Piyush Charan, Dept. of ECE, Integral University, Lucknow 6
11/2/2020 Dr. Piyush Charan, Dept. of ECE, Integral University, Lucknow 7
Sorting of Array- Bubble Sort
11/2/2020 Dr. Piyush Charan, Dept. of ECE, Integral University, Lucknow 8
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50], n, i, j, temp;
clrscr();
printf("Enter the size of array=");
scanf("%d", &n);
printf("Enter the elements in the array: ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
//Sorting Logic
printf("The Sorted Array in Ascending order is ");
for(i=0;i<=(n-2);i++)
{
for(j=0;j<=(n-2)-i;j++)
{
if (a[j]>a[j+1])
11/2/2020 Dr. Piyush Charan, Dept. of ECE, Integral University, Lucknow 9
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
//Printing Sorted Array Logic
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
getch();
}
11/2/2020 Dr. Piyush Charan, Dept. of ECE, Integral University, Lucknow 10
Sum of Two Arrays
11/2/2020 Dr. Piyush Charan, Dept. of ECE, Integral University, Lucknow 11

Unit 4 Arrays

  • 1.
    Lectures on Programmingwith Arrays for Open Educational Resource On Programming Concepts (EC208) by Dr. Piyush Charan Assistant Professor Department of Electronics and Communication Engg. Integral University, Lucknow
  • 2.
    Introduction to Arrays 11/2/2020Dr. Piyush Charan, Dept. of ECE, Integral University, Lucknow 2
  • 3.
    Simple program onArrays to accept ‘n’ numbers and display the same 11/2/2020 Dr. Piyush Charan, Dept. of ECE, Integral University, Lucknow 3
  • 4.
    11/2/2020 Dr. PiyushCharan, Dept. of ECE, Integral University, Lucknow 4
  • 5.
    11/2/2020 Dr. PiyushCharan, Dept. of ECE, Integral University, Lucknow 5
  • 6.
    11/2/2020 Dr. PiyushCharan, Dept. of ECE, Integral University, Lucknow 6
  • 7.
    11/2/2020 Dr. PiyushCharan, Dept. of ECE, Integral University, Lucknow 7
  • 8.
    Sorting of Array-Bubble Sort 11/2/2020 Dr. Piyush Charan, Dept. of ECE, Integral University, Lucknow 8 #include<stdio.h> #include<conio.h> void main() { int a[50], n, i, j, temp; clrscr(); printf("Enter the size of array="); scanf("%d", &n); printf("Enter the elements in the array: "); for(i=0;i<n;i++) { scanf("%d",&a[i]); } //Sorting Logic printf("The Sorted Array in Ascending order is "); for(i=0;i<=(n-2);i++) { for(j=0;j<=(n-2)-i;j++) { if (a[j]>a[j+1])
  • 9.
    11/2/2020 Dr. PiyushCharan, Dept. of ECE, Integral University, Lucknow 9 { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } //Printing Sorted Array Logic for(i=0;i<n;i++) { printf("%d ",a[i]); } getch(); }
  • 10.
    11/2/2020 Dr. PiyushCharan, Dept. of ECE, Integral University, Lucknow 10 Sum of Two Arrays
  • 11.
    11/2/2020 Dr. PiyushCharan, Dept. of ECE, Integral University, Lucknow 11