Computer Engineering: Languag: \"C Programming\" Please make sure the code does
ID: 3586011 • Letter: C
Question
Computer Engineering:
Languag: "C Programming"
Please make sure the code does not have errors and is running before sending it.
thank you ^_^
Write a driver program and implement the functions specified below to determine several facts about a given number. We are going to determine the following: if a number is divisible by 7, 11, or 13 and is the number prime. Implement this function: void divisibility(int number, int *seven, int *eleven, int thirteen); int is_prime(int number); Sample Output: Enter a number: 7 Facts for your number: Divisibility by 7: YES Divisibility by 11: NO Divisibility by 13: NO Is Prime: YE Data Type Requirement: Input data is of type int and output is fixed string yes or no Input Validation: Input can be any positive integer plus 0. You should account for special nature of 0 and 1 when checking prime.Explanation / Answer
#include <stdio.h>
void divisibility(int number, int *seven, int *eleven, int *thirteen) {
*seven = number % 7;
*eleven = number % 11;
*thirteen = number % 13;
}
int is_prime(int number) {
int f;
for (f = 2; f <= number / 2; f++) {
if (number % f == 0) {
return 0;
}
}
return 1;
}
int main()
{
int n;
int seven, eleven, thirteen;
printf("Enter a number: ");
scanf("%d", &n);
divisibility(n, &seven, &eleven, &thirteen);
printf("Facts for your number ");
if(seven == 0) {
printf("Divisible by 7: YES ");
} else {
printf("Divisible by 7: NO ");
}
if(eleven == 0) {
printf("Divisible by 11: YES ");
} else {
printf("Divisible by 11: NO ");
}
if(thirteen == 0) {
printf("Divisible by 13: YES ");
} else {
printf("Divisible by 13: NO ");
}
if(is_prime(n) && n != 0 && n != 1) {
printf("Is Prime: YES ");
} else {
printf("Is Prime: NO ");
}
return 0;
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.