Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C Program to Check Prime Numbers, Exercises of Algorithms and Programming

The code for a simple c program that checks whether a given number is prime or not by calculating the number of divisors it has. The program uses standard input and output functions to read the number from the user and display the result.

What you will learn

  • How does the C program determine if a number is prime?
  • Can this C program be modified to find prime numbers within a given range?
  • What is the role of the for loop in the C program for prime number checking?

Typology: Exercises

2018/2019

Uploaded on 12/12/2019

halil-ibrahim-camur
halil-ibrahim-camur 🇹🇷

2 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<conio.h>
int main ()
{
int a,b=0,i;
printf("sayi giriniz");
scanf("%d",&a);
for(i=2;i<a;i++)
{
if(a%i==0)
b++;
}
if(b>0)
{
printf("sayi asal degildir");
}
if(b==0)
{
printf("sayi asaldir");
}
return 0;
}

Partial preview of the text

Download C Program to Check Prime Numbers and more Exercises Algorithms and Programming in PDF only on Docsity!

#include<stdio.h> #include<stdlib.h> #include<math.h> #include<conio.h> int main () { int a,b=0,i; printf("sayi giriniz"); scanf("%d",&a); for(i=2;i<a;i++) { if(a%i==0) b++; } if(b>0) { printf("sayi asal degildir"); } if(b==0) { printf("sayi asaldir"); } return 0; }