Answer to Question #259839 in C for Shadow

Question #259839

1. Return types and basic algorithms

I. Write a program to find the sum of 10 integer numbers inside a separate function called sum() and print the total inside the main function.

II. Improve the above program to find even numbers in a given array.

III. Which parts of the above program (a) needs to be changed to code linear search?


1
Expert's answer
2021-11-02T14:43:34-0400
#include<stdio.h>
int sum(){
	int arr[10], total = 0;
	int i, j;
	printf("Enter 10 numbers\n");
	for(i=0; i<10; i++){
		scanf("%d", &arr[i]);
		total += arr[i];
	}
	printf("Even numbers are:  ");
	for(j=0; j<10; j++){
		if(arr[j] % 2==0){
			printf("%d  ", arr[j]);
		}
	}
	printf("\n");
	return total;
}
int main(){
	int total = sum();
	printf("Sum is: %d", total);
}

To do linear search, modify the sum function

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS