Archive Pages Design$type=blogging

Write a Program in C to Determine Whether a Number is Prime or Not.

"A prime number is one, which is divisible only by 1 or itself." To determine whether a number is prime or not, we have to divide ...


Program in C to Determine Whether a Number is Prime or Not.
"A prime number is one, which is divisible only by 1 or itself."

To determine whether a number is prime or not, we have to divide the number successively by all numbers from 2 to one less than itself.

If remainder of any of these divisions is zero, the number is not a prime.

If no division yields a zero then the number is a prime number.



Program in C to Determine Whether a Number is Prime or Not


Steps:

  1. Declare integers num and i inside main()
  2. Prompt the message allow the input using printf() and scanf()
  3. Test whether a Number is prime or not using while() function.

Code:

#include <stdio.h>

int main()
{

int num, i;


printf("Enter a number");
scanf ("%d",&num);

i=2;

while (i<=num-1)
{

if (num%i==0)
{
printf("Not a prime number\n");
break;
}

i++;
}

if (i==num)

printf("Prime number\n");

return 0;
}



Related Posts: 



تعليقات

الاسم

Artificial Intelligence(AI) Backlinking Basic IT Best List Blogging Tips C C# C++ Computer Architecture Computer Fundamental Computer Security Computer/IT Officer Exam CSS Data Mining and Warehousing Data Recovery Tools Data Structure Database Management System E-commerce E-government Internet & Web Designing IT Law IT Tips and Tricks IT Tutorials Java JavaScript Keyword Research Tools MIS Multiple Choice Question (MCQ) Networking Online Earning Online IT Jobs Operating System Oracle Forms and Reports Programming Guide Programming Language SEO Social Networking Sites Software Download Software Engineering System Analysis and Design Top List VB.Net
false
rtl
item
Max6: Write a Program in C to Determine Whether a Number is Prime or Not.
Write a Program in C to Determine Whether a Number is Prime or Not.
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihC5EZrKaMZmSVPjp3IYfk8XUldjRLIFx02wdP1gWqPqGpCFEJNtV7iYX_6mSQO6dfTiR0i3d71oxpg2qAd05lP1Mn7vUUIIkDpXx5IqaJY_7FRM4yfXqK7MrMc3c1rpnoBAa8-vMDOV1k/s1600/c-prime-not.PNG
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihC5EZrKaMZmSVPjp3IYfk8XUldjRLIFx02wdP1gWqPqGpCFEJNtV7iYX_6mSQO6dfTiR0i3d71oxpg2qAd05lP1Mn7vUUIIkDpXx5IqaJY_7FRM4yfXqK7MrMc3c1rpnoBAa8-vMDOV1k/s72-c/c-prime-not.PNG
Max6
https://maxs29.blogspot.com/2014/07/write-program-in-c-to-determine-whether.html
https://maxs29.blogspot.com/
http://maxs29.blogspot.com/
http://maxs29.blogspot.com/2014/07/write-program-in-c-to-determine-whether.html
true
4303790511137642940
UTF-8
لم يتم العثور على اى مواضيع شاهد الكل اقرأ المزيد رد احذف الرد حذف بواسطة الرئيسية صفحات مواضيع شاهد الكل نوصى لك التسميات الارشيف بحث لم يتم العثور على ماتبحث عنه عودة للرئيسية الاحد الاثنين الثلاثاء الاربعاء الخميس الجمعة السبت الاحد الاثنين الثلاثاء الاربعاء الخميس الجمعة السبت يناير فبراير مارس ابريل مايو يونيو يوليو اغسطس سبتمبر اكتوبر نوفمبر ديسمبر يناير فبراير مارس ابريل مايو يونيو يوليو اغسطس سبتمبر اكتوبر نوفمبر ديسمبر just now 1 دقيقة مضت $$1$$ دقيقة مضت 1 hour ago $$1$$ ساعة مضت الامس $$1$$ يوم مضى $$1$$ اسبوع مضى اكثر من 5 اسابيع مضت