cp_1_lect_34 - Storing values in Arrays continued. #include...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
5/10/10 more examples on Initialization : Storing values in Arrays continued… #include <stdio.h> main() { int i; int max[5] = {8, 7}; for (i=0;i<=7;i++) printf ("%d\n", max[i]); return 0; } bash$ ./a.out 8 7 0 0 0 5 -1076194544 -1076194472 bash$
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
5/10/10 Storing values in Arrays continued… Inputting for ( i = 0; i < 9; i++) scanf (“%d”, &score [i]); For filling completely If all the elements are not to be filled, use event controlled loops like while or do… while Assigning values: score [3] = 34; for (i = 0; i < 25; i++) second [i] = first [i]; Copying elements for (i = 0; i < 9; i++) score [i] = i*2; Values follow a pattern
Background image of page 2
5/10/10 Program to display the elements of 2 arrays #include< stdio.h > void main( ) { int i,num[]={24,34,12,44,56,17}, num1[]{12,24,35,78,85,22}; Printf(“Elements of 1st array – 2nd array = Addition”); for(i=0;i<=5;i++) printf(“\n\t\t%d + %d =\t %d”, num[i],num1[i],num[i]+num1[i]); } Output: Elements of 1st array – 2nd array = Addition 24 + 12 =36
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
/* Program to count the no of positive and negative numbers*/ #include< stdio.h > void main( ) { int a[50],n,count_neg=0,count OUTPUT: Enter the size of the array: 5 1 2 -3 4 -5 There are 2 negative numbers. There are 3 positive
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 15

cp_1_lect_34 - Storing values in Arrays continued. #include...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online