Introduction to Programming Indian Institute of Information Technology Allahabad One-Dimensional Arrays and Strings Email:
[email protected] Web: https://profile.iiita.ac.in/srdubey/
The content (text, image, and graphics) used in this slide are adopted from many sources for academic purposes, mainly from IIT Kgp. Broadly, the sources have been given due credit appropriately. However, there is a chance of missing out some original primary sources. The authors of this material do not claim any copyright of such material. 2
• Many applications require multiple data items that have common characteristics • In mathematics, we often express such groups of data items in indexed form: • x1 , x2 , x3 , ..., xn Array 3
• Many applications require multiple data items that have common characteristics • In mathematics, we often express such groups of data items in indexed form: • x1 , x2 , x3 , ..., xn • Array is a data structure which can represent a collection of data items which have the same data type (float/int/char/...) Array 4
5 int a, b, c; scanf(“%d”, &a); scanf(“%d”, &b); scanf(“%d”, &c); printf(“%d ”, c); printf(“%d ”, b); printf(“%d \n”, a); int a, b, c, d; scanf(“%d”, &a); scanf(“%d”, &b); scanf(“%d”, &c); scanf(“%d”, &d); printf(“%d ”, d); printf(“%d ”, c); printf(“%d ”, b); printf(“%d \n”, a); 3 numbers 4 numbers Example: Printing Numbers in Reverse