Solving simple scientific and statistical problems - Basic C Programs
Solving simple scientific and statistical problems
Write a C program to check, whether the given Prime or not.
A prime number is an integer which has no proper divisions. For example, 13 is a prime number, because 13 is not divisible by any number other than 1 and 13.
If 'n' has a factor greater than √n, it also has a factor less than √n. So, it is enough to check whether 'n' is divisible by any number between 2 and √n. If divisible, 'n' is not prime, otherwise it is prime.
/* Program to check the given number is prime or not */
#include <stdio.h>
main()
{
/* Local definitions */
int n,i,r;
printf("Enter the positive integer value.....");
scanf("%d", &n);
i=2;
Step1:
if(i<=sqrt(n))
{
r=n%i;
if(r==0)
{
printf("%d is not a prime",n);
goto end;
} /* if */
} /* if */
else
{
i++;
goto stepl;
} /* if else */
printf("%d is prime",n);
end:
printf(" ");
} * main */
OUTPUT
Enter the positive integer value.....3
3 is prime
EXPLANATION: Read n then checks whether the i<=sort(n), if the condition is true if block is executed and prints the entered value is not a prime. Otherwise else part is executed, then the variable i is increased by 1 then goto step1, after completion of else part finally the entered value is printed as prime.
Computer Programming C Laboratory: Basic C Programs : Tag: C Programming : - Write a C program to check, whether the given Prime or not
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
English Essentials I
EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
தமிழர் மரபு - Heritage of Tamils
UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Calculus
MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I
PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Chemistry I
CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Makerspace
ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming C
CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming Python
CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Fundamentals of Electrical and Electronics Engineering
EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Mechanical Engineering
ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Civil Engineering
CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing
CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I Laboratory
PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Applied Chemistry I Laboratory
CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming Python Laboratory
CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Engineering Drawing
ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electronics and Electrical Engineering
EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing - Laboratory
CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation