Problem solving through programming (18escs01)
INITIALIZATION OF ARRAYS (CONTD.)
Download 215.92 Kb.
|
Module 3 C program
- Bu sahifa navigatsiya:
- INITIALIZATION OF ARRAYS (CONTD.)
- EXAMPLE – 1: DISPLAY ELEMENTS ELEMENT’S
- DIFFERENT WAYS OF INITIALIZATION OF ARRAYS
- (B) PARTIAL ARRAY INITIALIZATION
INITIALIZATION OF ARRAYS (CONTD.)
#include { int i; int arr[ ] = {2, 3, 4}; //Compile time array initialization for(i = 0 ; i < 3 ; i++) { printf("%d\t", arr[i]); } } 6 Output: 2 3 4 INITIALIZATION OF ARRAYS (CONTD.)7
#include { int arr[3]; int i, j; printf("Enter array element"); for(i = 0; i < 3; i++) { scanf("%d", &arr[i]); } for(j = 0; j < 3; j++) { printf("%d\n", arr[j]); } //Run time array initialization } Output: 2 3 4 EXAMPLE – 1: DISPLAY ELEMENTS ELEMENT’S#include { int n[ 10 ]; /* n is an array of 10 integers */ int i, j; /* initialize elements of array n to 0 */ for ( i = 0; i < 10; i++ ) { n[ i ] = i + 100; /* set element at location i to i + 100 */ } /* output each array element's value */ for (j = 0; j < 10; j++ ) { printf("Element[%d] = %d\n", j, n[j] ); } return 0; } 8 Output: Element[0] = 100 Element[1] = 101 Element[2] = 102 Element[3] = 103 Element[4] = 104 Element[5] = 105 Element[6] = 106 Element[7] = 107 Element[8] = 108 Element[9] = 109 DIFFERENT WAYS OF INITIALIZATION OF ARRAYS
9 (A) INITIALIZING ALL SPECIFIED MEMORY LOCATION
when their initial values are known in advance.
(B) PARTIAL ARRAY INITIALIZATION
MANJUNATH C R
Download 215.92 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling