Retake CPE100 Computer Programming
Retake CPE100 Computer Programming
#include<stdio.h>
int main() {
int num1,num2,i,j,count=0,isPrime;
scanf("%d %d", &num1,&num2); // scanf the range of the total number
//To find the total prime number from the range between num1 and num2
for(i=num1 ; i<=num2 ; i++){
isPrime=1;
for(j=2 ; j<=i-1 ; j++){
if(i%j == 0){
isPrime=0;
break;
}
}
//If it is the prime number, count and collect it, to find the total prime
number from the given range
if(i>1 && isPrime){
count++;
}
}
//printf the total number of prime number from the given range.
printf("%d", count);
return 0;
• num1 and num2 are the input integers that will be the range to find the total prime number
• for loop -> for(i=num ; i <= num2 ; i++) is used to set the range to find the prime number
• isPrime is the thing that use to check if it is prime number, it will collect the quantity in the count
variable.
• For loop -> for(j=2 ; j <= i-1 ; j++) is used to check i that it is divisible by 2 and i-1
• If i is not the prime number (isPrime = 0;) then the inner loop will stop working which is break.
• Then it will run like this until num2 and display the total number of the prime number.
#include <stdio.h>
#include <string.h>
int main() {
int d, m;
char day[20];
//printf("Enter day (dd): ");
scanf("%d %d", &d, &m);
strcpy(day, getDay(d, m, 2009));
printf("%s\n", day);
return 0;
}
For this question
• I have used “getDay” function to get the day of the week from input date and month in year 2009
• When you input the date, it will go check what day of this date or is it Error in “getDay” function
• Then strcpy will copy the result from “getDay” function
• Lastly, it will display the day of the date that we have input by using printf.
int main()
{
int num, base = 0, rem = 0, place = 1;