please answer these two questions Write a C program to decide if an integer that
ID: 3581359 • Letter: P
Question
please answer these two questions
Write a C program to decide if an integer that the user inputs is prime or not. A prime number is a number greater than 1 with no positive divisors. The user should only input an integer from 0 to 100. If the user inputs 17 the output should be: 17 is a prime number. Do you want to input another (y/n)? If the user inputs y and then inputs 52 the output would be: 2 is not a prime number. Do you want to input another (y/n)? Write a C program that counts the number of words and also counts the non-word characters in a piece of text (held in a string variable called text_string). For example if the following code was in the program: char text_string[]="This is an eye-opening test!!!"; Then the output would be: This text has 5 words and 7 non-word characters in it.Explanation / Answer
#include<stdio.h>
#include<conio.h>
void isPrime(int);
int main(){
int number;
char option;
do{
printf("Enter a numberber: ");
scanf("%d",&number);
isPrime(number);
printf("do you want to input another(y/n)?");
scanf("%d",&option);
//isPrime(number);
}
while(option!='n');
getch();
//return 0;
}
void isPrime(int number){
int i,count=0;
for(i=2;i<=number/2;i++){
if(number%i==0){
count++;
break;
}
}
if(count==0 && number!= 1)
printf("%d is a prime numberber",number);
else
printf("%d is not a prime numberber",number);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.