SlideShare a Scribd company logo
One Dimentional Array
Presented By:
Presented To:
One Dimensional Array
♣Structured collection of components.
♣Structure given a single name.
♣Individual elements accessed by index indicating
relative position in collection.
♣Type of elements stored in an array can be “just
about” anything.
♣Index of an array must be an integer.
Declaring Arrays
¤ Declaration examples:
int[] counts;
double[] scores;
String[] studentNames;
¤Syntax:
Data type Array name [constant]
Array Allocation
Arrays are allocated using the Java new operator
The syntax is:
new type[size];
Examples:
counts = new int[10];
scores = new double[15];
studentNames = new String[10];
Array Organization
counts
Each box is an int variable
The numbers on top are each variable’s
subscript or index
An array of size 10 has subscripts 0 to 9
0 1 2 3 4 5 6 7 8 9
Array Initialization
• Arrays can be initialized by giving a list of their elements
• If your list contains n elements the subscripts will range
from 0 to n – 1
• Do not need to allocate the array explicitly after it is
initialized
• Example:
int [] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
Arrays of Objects
•Arrays of objects are declared in the same manner
as arrays of primitive variables
•Assuming that a class Student was declared
elsewhere a client application could declare and
allocate an array of 10 students using
Student[ ] students;
students = new Student[10];
#include<stdio.h>
#include<string.h>
int main()
{
char s1[80],s2[80];
gets (s1);
gets (s2);
puts(s1);
puts(s2);
printf("length:%d %dn",strlen(s1),strlen(s2));
return 0;
}
Example of 1D ARRAY
#include <stdio.h>
int main()
{
int i, n;
float
a[100],sum=0,sum_pos=0,sum_neg=0,avg;
printf("enter the value:");
scanf("%d",&n);
for(i=0;i<n; i++)
{ scanf("%f",&a[i]);
}
for(i=0;i<n; i++)
{
if(a[i]>0)
sum_pos=sum_pos+a[i];
}
for(i=0;i<n; i++)
{
if(a[i]<0)
sum_neg=sum_neg+a[i];
}
sum=sum_pos+sum_neg;
avg=sum/n;
printf("%fn",sum);
printf("%fn",avg);
return 0;
}
Example of 1D ARRAY
Thank
you

More Related Content

ODP
C++ arrays part1
PDF
Arrays in C++
PPTX
Array in Java
PPT
PDF
Array in Java
PPTX
Loops and arrays
PDF
SPL 10 | One Dimensional Array in C
PPTX
C++ arrays part1
Arrays in C++
Array in Java
Array in Java
Loops and arrays
SPL 10 | One Dimensional Array in C

What's hot (20)

PPTX
PPt. on An _Array in C
PPTX
Java arrays
PPTX
Array in c
PPTX
Arrays in java
PPT
Presentation of array
PPTX
Learn ActionScript programming myassignmenthelp.net
PPT
Array
PPTX
2CPP06 - Arrays and Pointers
PDF
Arrays In C
PPTX
PDF
Arrays in Java
PPTX
Chapter 6 java
PPTX
OOPs with java
PPT
C++ Arrays
PPTX
Object Class
PDF
Arrays in java
PPTX
R DATA STRUCTURES 1
PDF
Flash workshop Day Three
PPt. on An _Array in C
Java arrays
Array in c
Arrays in java
Presentation of array
Learn ActionScript programming myassignmenthelp.net
Array
2CPP06 - Arrays and Pointers
Arrays In C
Arrays in Java
Chapter 6 java
OOPs with java
C++ Arrays
Object Class
Arrays in java
R DATA STRUCTURES 1
Flash workshop Day Three
Ad

Viewers also liked (8)

PPT
Ch5 array nota
PPTX
Array in c language
PPT
Selection Control Structures
PPTX
Introduction to Array ppt
PPTX
Arrays In C++
PPTX
Array in C
PPT
Array Presentation (EngineerBaBu.com)
PPT
Ch5 array nota
Array in c language
Selection Control Structures
Introduction to Array ppt
Arrays In C++
Array in C
Array Presentation (EngineerBaBu.com)
Ad

Similar to One Dimentional Array (20)

DOCX
Class notes(week 4) on arrays and strings
PDF
Class notes(week 4) on arrays and strings
PPTX
Arrays in Data Structure and Algorithm
PPT
L10 array
PPT
Data Structure Midterm Lesson Arrays
PPTX
6_Array.pptx
PDF
Arrays a detailed explanation and presentation
PPTX
Java arrays
PPT
Comp102 lec 8
PPT
9 cm604.9
PPT
Java: Introduction to Arrays
PPT
Md05 arrays
PPTX
ARRAYS.pptx
PPT
Ap Power Point Chpt6
DOCX
Java R20 - UNIT-3.docx
PDF
Java chapter 6 - Arrays -syntax and use
PPTX
2301107005 - ADNAN PP.pptx array of objects
PDF
intorduction to Arrays in java
PDF
PPT
Mesics lecture 8 arrays in 'c'
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
Arrays in Data Structure and Algorithm
L10 array
Data Structure Midterm Lesson Arrays
6_Array.pptx
Arrays a detailed explanation and presentation
Java arrays
Comp102 lec 8
9 cm604.9
Java: Introduction to Arrays
Md05 arrays
ARRAYS.pptx
Ap Power Point Chpt6
Java R20 - UNIT-3.docx
Java chapter 6 - Arrays -syntax and use
2301107005 - ADNAN PP.pptx array of objects
intorduction to Arrays in java
Mesics lecture 8 arrays in 'c'

More from Sonya Akter Rupa (9)

PPTX
Synchronous Counter in Digital Logic Device
PPTX
Method Overloading in Java
PPTX
Enviremental Pollution
PPTX
Switch Case in C Programming
PPT
File in C Programming
PPT
Pointer in C
PPTX
Two Dimentional Array
PPTX
The population is resource or burden for Bangladesh
PPT
Spherical Polar Coordinate System- physics II
Synchronous Counter in Digital Logic Device
Method Overloading in Java
Enviremental Pollution
Switch Case in C Programming
File in C Programming
Pointer in C
Two Dimentional Array
The population is resource or burden for Bangladesh
Spherical Polar Coordinate System- physics II

Recently uploaded (20)

PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
Well-logging-methods_new................
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
web development for engineering and engineering
PPTX
Current and future trends in Computer Vision.pptx
PPT
introduction to datamining and warehousing
PPTX
Lecture Notes Electrical Wiring System Components
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Construction Project Organization Group 2.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
Artificial Intelligence
PPTX
Sustainable Sites - Green Building Construction
PPT
Project quality management in manufacturing
PPT
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPT
Mechanical Engineering MATERIALS Selection
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPTX
UNIT 4 Total Quality Management .pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Well-logging-methods_new................
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
web development for engineering and engineering
Current and future trends in Computer Vision.pptx
introduction to datamining and warehousing
Lecture Notes Electrical Wiring System Components
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Construction Project Organization Group 2.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Artificial Intelligence
Sustainable Sites - Green Building Construction
Project quality management in manufacturing
Introduction, IoT Design Methodology, Case Study on IoT System for Weather Mo...
Internet of Things (IOT) - A guide to understanding
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Mechanical Engineering MATERIALS Selection
CYBER-CRIMES AND SECURITY A guide to understanding
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
UNIT 4 Total Quality Management .pptx

One Dimentional Array

  • 3. One Dimensional Array ♣Structured collection of components. ♣Structure given a single name. ♣Individual elements accessed by index indicating relative position in collection. ♣Type of elements stored in an array can be “just about” anything. ♣Index of an array must be an integer.
  • 4. Declaring Arrays ¤ Declaration examples: int[] counts; double[] scores; String[] studentNames; ¤Syntax: Data type Array name [constant]
  • 5. Array Allocation Arrays are allocated using the Java new operator The syntax is: new type[size]; Examples: counts = new int[10]; scores = new double[15]; studentNames = new String[10];
  • 6. Array Organization counts Each box is an int variable The numbers on top are each variable’s subscript or index An array of size 10 has subscripts 0 to 9 0 1 2 3 4 5 6 7 8 9
  • 7. Array Initialization • Arrays can be initialized by giving a list of their elements • If your list contains n elements the subscripts will range from 0 to n – 1 • Do not need to allocate the array explicitly after it is initialized • Example: int [] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
  • 8. Arrays of Objects •Arrays of objects are declared in the same manner as arrays of primitive variables •Assuming that a class Student was declared elsewhere a client application could declare and allocate an array of 10 students using Student[ ] students; students = new Student[10];
  • 9. #include<stdio.h> #include<string.h> int main() { char s1[80],s2[80]; gets (s1); gets (s2); puts(s1); puts(s2); printf("length:%d %dn",strlen(s1),strlen(s2)); return 0; } Example of 1D ARRAY
  • 10. #include <stdio.h> int main() { int i, n; float a[100],sum=0,sum_pos=0,sum_neg=0,avg; printf("enter the value:"); scanf("%d",&n); for(i=0;i<n; i++) { scanf("%f",&a[i]); } for(i=0;i<n; i++) { if(a[i]>0) sum_pos=sum_pos+a[i]; } for(i=0;i<n; i++) { if(a[i]<0) sum_neg=sum_neg+a[i]; } sum=sum_pos+sum_neg; avg=sum/n; printf("%fn",sum); printf("%fn",avg); return 0; } Example of 1D ARRAY