Sunteți pe pagina 1din 4

1.

If there are fewer intializers than the size of the array, the remaining eleme ntsare initialized to zero.Example 5. int n[10] = {5, 26}; Based from the declaration, we say that:n[0]=5n[1]=26n[2]=0n[3]=0n[4]=0n[5]=0n[6 ]=0n[7]=0n[8]=0n[9]=02.An initializer list that is greater than the array size i s a syntax error.Example 6. int g[3] = {5, 16, -3, 67}; Therefore, the declaration above is wrong because there are four initializers in the initializer list while the size of the array is only three.3.If the array s ize is omitted from a declaration with an initializer list, thenumber of element s in the array will be the number of elements in theinitializer list.Example 7. int exam[ ] = {88, 89, 90, 60, 78}; The declaration above will automatically create a five-element array of type int eger with the following values:exam[0]=88exam[1]=89exam[2]=90exam[3]=60exam[4]=7 8 Element 0 is 5Element 1 is 10Element 2 is 15Element 3 is 20Element 4 is 25The su m is 39Example 8. Write a C program that will print the values of the following array:int n[5] = {5, 10, 15, 20, 25}.#include<stdio.h>main( ){int n[5] = {5, 10, 15, 20, 25];int x;for (x = 0; x <= 4; x++)printf( Element %d is %d , x, n[x]);getch ( );} SAMPLE OUTPUT: Example 9. Write a C program that will compute and display the sum of thefollowi ng array:int a[5] = {2, 1, 0, 5, 2, 7, 4, 3, 10, 5}#include<stdio.h>main( ){int a[5] = {2, 1, 0, 5, 2, 7, 4, 3, 10, 15};int x, sum;sum = 0;for (x = 0; x <= 9; x ++)sum += a[x]; printf( The sum is %d , sum);getch( );} SAMPLE OUTPUT: PROGRAMMING EXERCISES 1.Write a program that will search for the largest value in an array of integers of length 10.2.Write a program that will search for the smallest value in an ar ray of integers of length 10.3.Write a program that will take the sum of all the array elements greater than 80 inan array of 10 elements completely filled by t he user.4.Write a program that will print the odd positioned elements in an arra y of 10integers.5.Write a program that will print the even positioned elements i n an array of 10integers.6.Write a program that will arrange the elements of a 1 0-integer array in ascendingorder.7.Write a program that will arrange the elemen ts of a 10-integer array in descendingorder.8.Write a program that will compute and display the average of a 20-element arraywhose values are inputted by the us er.9.Write a program that will output all the even numbers found in an array of 20integers. Display also the sum of the values found.10.Write a program that wil l output all the odd numbers found in an array of 20integers. Display also the s um of the values found.

1.If there are fewer intializers than the size of the array, the remaining eleme ntsare initialized to zero.Example 5. int n[10] = {5, 26}; Based from the declaration, we say that:n[0]=5n[1]=26n[2]=0n[3]=0n[4]=0n[5]=0n[6 ]=0n[7]=0n[8]=0n[9]=02.An initializer list that is greater than the array size i s a syntax error.Example 6. int g[3] = {5, 16, -3, 67}; Therefore, the declaration above is wrong because there are four initializers in the initializer list while the size of the array is only three.3.If the array s ize is omitted from a declaration with an initializer list, thenumber of element s in the array will be the number of elements in theinitializer list.Example 7. int exam[ ] = {88, 89, 90, 60, 78}; The declaration above will automatically create a five-element array of type int eger with the following values:exam[0]=88exam[1]=89exam[2]=90exam[3]=60exam[4]=7 8 Element 0 is 5Element 1 is 10Element 2 is 15Element 3 is 20Element 4 is 25The su m is 39Example 8. Write a C program that will print the values of the following array:int n[5] = {5, 10, 15, 20, 25}.#include<stdio.h>main( ){int n[5] = {5, 10, 15, 20, 25];int x;for (x = 0; x <= 4; x++)printf( Element %d is %d , x, n[x]);getch ( );} SAMPLE OUTPUT: Example 9. Write a C program that will compute and display the sum of thefollowi ng array:int a[5] = {2, 1, 0, 5, 2, 7, 4, 3, 10, 5}#include<stdio.h>main( ){int a[5] = {2, 1, 0, 5, 2, 7, 4, 3, 10, 15};int x, sum;sum = 0;for (x = 0; x <= 9; x ++)sum += a[x]; printf( The sum is %d , sum);getch( );} SAMPLE OUTPUT: PROGRAMMING EXERCISES 1.Write a program that will search for the largest value in an array of integers of length 10.2.Write a program that will search for the smallest value in an ar ray of integers of length 10.3.Write a program that will take the sum of all the array elements greater than 80 inan array of 10 elements completely filled by t he user.4.Write a program that will print the odd positioned elements in an arra y of 10integers.5.Write a program that will print the even positioned elements i n an array of 10integers.6.Write a program that will arrange the elements of a 1 0-integer array in ascendingorder.7.Write a program that will arrange the elemen ts of a 10-integer array in descendingorder.8.Write a program that will compute and display the average of a 20-element arraywhose values are inputted by the us er.9.Write a program that will output all the even numbers found in an array of 20integers. Display also the sum of the values found.10.Write a program that wil l output all the odd numbers found in an array of 20integers. Display also the s um of the values found.

1.If there are fewer intializers than the size of the array, the remaining eleme ntsare initialized to zero.Example 5.

int n[10] = {5, 26}; Based from the declaration, we say that:n[0]=5n[1]=26n[2]=0n[3]=0n[4]=0n[5]=0n[6 ]=0n[7]=0n[8]=0n[9]=02.An initializer list that is greater than the array size i s a syntax error.Example 6. int g[3] = {5, 16, -3, 67}; Therefore, the declaration above is wrong because there are four initializers in the initializer list while the size of the array is only three.3.If the array s ize is omitted from a declaration with an initializer list, thenumber of element s in the array will be the number of elements in theinitializer list.Example 7. int exam[ ] = {88, 89, 90, 60, 78}; The declaration above will automatically create a five-element array of type int eger with the following values:exam[0]=88exam[1]=89exam[2]=90exam[3]=60exam[4]=7 8 Element 0 is 5Element 1 is 10Element 2 is 15Element 3 is 20Element 4 is 25The su m is 39Example 8. Write a C program that will print the values of the following array:int n[5] = {5, 10, 15, 20, 25}.#include<stdio.h>main( ){int n[5] = {5, 10, 15, 20, 25];int x;for (x = 0; x <= 4; x++)printf( Element %d is %d , x, n[x]);getch ( );} SAMPLE OUTPUT: Example 9. Write a C program that will compute and display the sum of thefollowi ng array:int a[5] = {2, 1, 0, 5, 2, 7, 4, 3, 10, 5}#include<stdio.h>main( ){int a[5] = {2, 1, 0, 5, 2, 7, 4, 3, 10, 15};int x, sum;sum = 0;for (x = 0; x <= 9; x ++)sum += a[x]; printf( The sum is %d , sum);getch( );} SAMPLE OUTPUT: PROGRAMMING EXERCISES 1.Write a program that will search for the largest value in an array of integers of length 10.2.Write a program that will search for the smallest value in an ar ray of integers of length 10.3.Write a program that will take the sum of all the array elements greater than 80 inan array of 10 elements completely filled by t he user.4.Write a program that will print the odd positioned elements in an arra y of 10integers.5.Write a program that will print the even positioned elements i n an array of 10integers.6.Write a program that will arrange the elements of a 1 0-integer array in ascendingorder.7.Write a program that will arrange the elemen ts of a 10-integer array in descendingorder.8.Write a program that will compute and display the average of a 20-element arraywhose values are inputted by the us er.9.Write a program that will output all the even numbers found in an array of 20integers. Display also the sum of the values found.10.Write a program that wil l output all the odd numbers found in an array of 20integers. Display also the s um of the values found.

1.If there are fewer intializers than the size of the array, the remaining eleme ntsare initialized to zero.Example 5. int n[10] = {5, 26}; Based from the declaration, we say that:n[0]=5n[1]=26n[2]=0n[3]=0n[4]=0n[5]=0n[6 ]=0n[7]=0n[8]=0n[9]=02.An initializer list that is greater than the array size i s a syntax error.Example 6. int g[3] = {5, 16, -3, 67}; Therefore, the declaration above is wrong because there are four initializers in

the initializer list while the size of the array is only three.3.If the array s ize is omitted from a declaration with an initializer list, thenumber of element s in the array will be the number of elements in theinitializer list.Example 7. int exam[ ] = {88, 89, 90, 60, 78}; The declaration above will automatically create a five-element array of type int eger with the following values:exam[0]=88exam[1]=89exam[2]=90exam[3]=60exam[4]=7 8 Element 0 is 5Element 1 is 10Element 2 is 15Element 3 is 20Element 4 is 25The su m is 39Example 8. Write a C program that will print the values of the following array:int n[5] = {5, 10, 15, 20, 25}.#include<stdio.h>main( ){int n[5] = {5, 10, 15, 20, 25];int x;for (x = 0; x <= 4; x++)printf( Element %d is %d , x, n[x]);getch ( );} SAMPLE OUTPUT: Example 9. Write a C program that will compute and display the sum of thefollowi ng array:int a[5] = {2, 1, 0, 5, 2, 7, 4, 3, 10, 5}#include<stdio.h>main( ){int a[5] = {2, 1, 0, 5, 2, 7, 4, 3, 10, 15};int x, sum;sum = 0;for (x = 0; x <= 9; x ++)sum += a[x]; printf( The sum is %d , sum);getch( );} SAMPLE OUTPUT: PROGRAMMING EXERCISES 1.Write a program that will search for the largest value in an array of integers of length 10.2.Write a program that will search for the smallest value in an ar ray of integers of length 10.3.Write a program that will take the sum of all the array elements greater than 80 inan array of 10 elements completely filled by t he user.4.Write a program that will print the odd positioned elements in an arra y of 10integers.5.Write a program that will print the even positioned elements i n an array of 10integers.6.Write a program that will arrange the elements of a 1 0-integer array in ascendingorder.7.Write a program that will arrange the elemen ts of a 10-integer array in descendingorder.8.Write a program that will compute and display the average of a 20-element arraywhose values are inputted by the us er.9.Write a program that will output all the even numbers found in an array of 20integers. Display also the sum of the values found.10.Write a program that wil l output all the odd numbers found in an array of 20integers. Display also the s um of the values found.

S-ar putea să vă placă și