Recap Challenge #1
Part of the Fundamentals section of Coddy's C journey — lesson 49 of 63.
Challenge
EasyWrite a C program that implements the following functions:
- A function called
isPrimethat takes an integer as an argument and returns 1 if the number is prime, and 0 otherwise. - A function called
sumOfPrimesthat takes two integer arguments (start and end) and returns the sum of all prime numbers in that range (inclusive). - In the
mainfunction, read two integers from input and use them as arguments for thesumOfPrimesfunction, and print the result.
Your program should validate that the input numbers are positive and that the first number is smaller than the second. If these conditions are not met, print out Invalid input and end the program
Try it yourself
#include <stdio.h>
// Declare your functions here
int main() {
// Your code here
return 0;
}All lessons in Fundamentals
4Control Flow
If StatementIf - ElseElse-IfSwitch CaseTernary Conditional OperatorRecap ChallengeNested If - Else7Functions
Declare a FunctionReturn TypesParametersRecap Challenge #1Recursion BasicsFunction PrototypesRecap Challenge #23Operators
Arithmetic OperatorsModulo OperatorIncrement/DecrementAssignment OperatorsRelational OperatorsLogical Operators Part 1Logical Operators Part 2Logical Operators Part 3Recap Challenge