Skip to content

Instantly share code, notes, and snippets.

@isaacssemugenyi
Created September 1, 2023 16:16
Show Gist options
  • Save isaacssemugenyi/5d20628c17ae00764a8f4bd57cd3eb14 to your computer and use it in GitHub Desktop.
Save isaacssemugenyi/5d20628c17ae00764a8f4bd57cd3eb14 to your computer and use it in GitHub Desktop.
Sum even number from an array
#include<stdio.h>
int main()
{
int numbers[10];
int i;
printf("You will be promted to enter any 10 numbers of choice, and only even numbers will be added \n\n");
for(i = 0; i < 10; i++) {
printf("Enter an integer number of your choice at position %d of 10 :\t", i + 1);
scanf("%d", &numbers[i]);
}
int sum_of_even_number = 0;
for(i = 0; i < 10; i++){
if(numbers[i] % 2 == 0){
sum_of_even_number += numbers[i];
}
}
printf("Sum of only even number is %d", sum_of_even_number);
return 0;
}
#include<stdio.h>
int main()
{
float heights[5];
int i;
printf("You will be promted choose any 5 heights values of choice and the max will be printed on screen \n\n");
for(i = 0; i < 5; i++) {
printf("Enter any float number of your choice at position %d of 5 :\t", i + 1);
scanf("%f", &heights[i]);
}
float max_height = 0.0;
for(i = 0; i < 5; i++){
if(heights[i] > max_height) {
max_height = heights[i];
}
}
printf("Maximum height of the 5 heights is %.2f", max_height);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment