Professional Documents
Culture Documents
Activity 3:
Good day, Ma’am! I’m Karylle Delantes, and today I’m going to show you a program
that I have learned in my past classes.
It is just a simple program that determines the largest prime number and the
smallest composite number.
Before I start, Let’s define and differentiate prime and composite numbers.
• A Prime Number has exactly two factors. “1” and the number itself.
Example: 2, 5, 7, 19, and many more…
• A Composite Number has more than two factors.
Example: 4, 10, 15, 36, and many more…
Page 1 of 5
So, let’s go back to the program.
Program Description:
The program will ask for a set of positive integers. The program will only stop asking
for a number if the user enters a “0” or a negative number. From these positive
numbers, it will determine and print the largest prime and the smallest composite
numbers.
Check Function:
• The Declaration Statements in this function are i, which means initial, and c,
which means count.
• Inside the for-loop, the num will be checked whether if it has only two
factors or has more than two factors.
• Next, it will go through the if-else statements to see whether the variable c
is equals to two or not.
• If it equals 2, then it’s a Prime number which it returns to num as 0. On the
other hand, if c does not equals 2 then it’s a Composite number which it
returns to num as 1.
Page 2 of 5
Let's go back to the main function:
• It contains if-else statements, showing the Largest Prime number and the
Smallest Composite number on the screen.
To check:
1. Determines the Largest Prime number and the Smallest Composite number
Enter Number: 20
Enter Number: 2
Enter Number: 13
Enter Number: 9
Highest Prime Number: 19
Enter Number: 10 Smallest Composite Number: 9
Enter Number: 3
Enter Number: 19
Enter Number: 0
2. Determines the Largest Prime number and the Smallest Composite number
Enter Number: 17
Enter Number: 43
Highest Prime Number: 61
Enter Number: 61
Smallest Composite Number: 4
Enter Number: 12
Enter Number: 4
Enter Number: -2
Page 3 of 5
The program runs smoothly, and the expected outputs are correct.
That’s all, thank you for listening and have a wonderful day. Bye!
Code:
//DELANTES, Karylle - Determines the largest prime number and the smallest
composite number
//Activity 3 - Individual Programming Assignment (CCS104)
#include <stdio.h>
int main(){
int num, largestPrime = 0, smallestComp = 0, ans;
Page 4 of 5
do{
//Input
printf("Enter number: ");
scanf("%d", &num);
//Process
ans = check(num);
//Output
printf("\n--------------------------------\n");
//Name
printf("\nSumbitted by: Karylle Delantes BSIT-2\n");
("\nSumbitted to: Ma'am Isabel Retutal'\n");
printf("\nDate: August 17, 2021 (Tuesday)\n");
Page 5 of 5