Good Essays
By the end of this lab session, you will be able to - declare an integer and character array - assign values to array during compilation and during execution - print contents of an array using repetition structure SAMPLE PROGRAM 1 /1. A program reads a series of numbers and print it reversed / include stdio.h void main (void) int i, Num, numbers10 printf(You may enter up to 10 integersn) printf(How many integers would you like to enter ) scanf (d, Num) if (Num 10) Num 10 printf(nEnter your numbers ) for (i 0 i Num i) scanf(d, numbersi) printf(nYour numbers reversed are ) for (i Num - 1 i 0 --i) printf(d , numbersi) printf(nn) SAMPLE PROGRAM 2 /2. Program that demonstrates the use of for loop to accept 8 numbers from user and displays certain numbers from the array / includestdio.h void main() int num, numbers8 printf(You need to enter 8 numbers ... n) for(num 0 num 7 num) scanf(i,numbersnum) printf(nn) printf(Your 1st element is dn,numbers0) printf(Your 2nd element is dn,numbers1) printf(Your 3rd element is dn,numbers2) printf(Your 8th element is dn,numbers7) printf(nn) printf(nnAll together your numbers aren) for(num 0 num 7 num) printf(d ,numbersnum) printf(nn) SAMPLE PROGRAM 3 /3. Program declares an array called charArray and assigns a single character to each of the array element using the initialize braces. Finally, the program prints the content of the array. / includestdio.h void main() char charArray8 F,r,i,e,n,d,s int i for(i 0 i 7 i) printf(charArrayd has a value of cn,i, charArrayi) printf(nMy favourite comedy sitcom is snn, charArray) SAMPLE PROGRAM 4 /4. Program consists of arrays (i.e. integer array and character array). It uses loops to sort the integer array elements in ascending and descending order. Then it displays the contents of the array elements respectively. / includestdio.h void main(void) int array10 0,1,2,3,4,5,6,7,8,9, i char string20 This is a string for(i

You May Also Find These Documents Helpful