Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Array Practice
/* Write a C program that computes the sum of all the values in an array. Assume that he values are numbers. Write a C program that computes the average of all the values in an array. Assume that he values are all integers. Write a C program that finds the largest number in an array. Assume that he values are all integers. Write a C program that finds the smallest number in an array. Assume that he values are all integers. Write a C program that finds the second largest number in an array. Assume that he values are all integers. Write a C program that increments each value in an array. Assume that he values are numbers. */ /* #include <stdio.h> int main(){ int product[5]; int array1[5]={10, 20, 30, 40, 50}; int array2[5]={1, 2, 3, 4, 5}; for (int i=0; i<5; i++) { product[i]=array1[i]*array2[i]; printf("%d\n", product[i]); } return 0; } */ /* #include <stdio.h> int main(){ int array1[10]={10,20,30,40,50,60,70,80,90,100}; int array2[10]={1,2,3,4,5,6,7,8,9,10}; int array1Sum=0; int array2Sum=0; for (int i=0; i<10; i++){ array1Sum+=array1[i]; array2Sum+=array2[i]; printf("array1Sum is %d and array2Sum is %d in the loop\n", array1Sum, array2Sum); } printf("After the loop array1Sum is %d and array2Sum is %d", array1Sum, array2Sum); return 0; } */ /* #include <stdio.h> int main(){ int array1[10]={10,20,30,40,50,60,70,80,90,100}; int array2[10]={1,2,3,4,5,6,7,8,9,10}; int average1=0; int n1=0; int sum1=0; int average2=0; int sum2=0; int n2=0; for (int i=0; i<10; i++){ sum1+=array1[i]; ++n1; sum2+=array2[i]; ++n2; } average1=sum1/n1; printf("%d\n", average1); average2=sum2/n2; printf("%d\n", average2); return 0; } */ /* #include <stdio.h> int main(){ int array1[10]={1,2,3,4,5,6,5,4,3,2}; int array2[10]={10,20,30,40,50,60,70,80,90,100}; int largest=0; int largest2=0; for (int i=0; i<10; i++){ if (array1[i]>largest){ largest=array1[i]; } if (array2[i]>largest2){ largest2=array2[i]; } } printf("largest number in array1 is %d, largest number in array2 %d", largest, largest2); return 0; } */ /* #include <stdio.h> int main(){ int array1[10]={1,2,3,4,5,6,5,4,3,2}; int array2[10]={10,20,30,40,50,60,70,80,90,100}; int smallest; int smallest2; for (int i=0; i<10; i++){ if (array1[i]<smallest){ smallest=array1[i]; } if (array2[i]>smallest2){ smallest2=array2[i]; } } printf("smallest number in array1 is %d, smallest number in array2 %d", smallest, smallest2); return 0; } */ #include <stdio.h> int main(){ int smallest; int secondSmallest; int array[10]={1,2,8,6,5,6,7,9,10,13}; for (i=0; i<10; i++){ if (array[i]<smallest){ secondSmallest=array[i]; if (array[i]<secondSmallest){ array[i]=secondSmallest; } printf("smallest is %d and second smallest is %d in the loop\n", smallest, secondSmallest); } } return 0; }
run
|
edit
|
history
|
help
0
Funciones en C
2
hello 5
QuestResp
llist.h
C_141113_euclides
Spring 2017 Lab 5 v1
first C code
squareifnal
C Array Demonstration