BeginnersBook.in

Programming For Geeks

  • Home
  • All Tutorials
    • Learn C
    • Learn Python
  • Programs
    • Java Programs
    • C++ Programs
    • C Programs
  • Algorithms
    • Sorting
  • MCQ’s
    • MySQL
    • Operating System
  • WordPress
    • Genesis Pro Themes
    • Blogs
  • Tools
    • Direct Download Link Generator
    • HTML Compiler
  • How to
    • Web Examples
  • Write For Us

C Program to Print Maximum Prime Number Between 1 to N

April 15, 2018 By Mr. Robot

In this example, you will learn print maximum prime number between 1 to n (entered by the user). The user will enter 100 input number and program will check all prime numbers till 100 and print highest prime number among them.

A prime is a number that is divisible only by itself and 1 (e.g. 2, 3, 5, 7, 11)

1
2
Input: 100
Output: 97 (Because 97 is the highest prime between 1 to 100)

Example: Maximum Number Between 1 to N

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<stdio.h>
int main()
{
    int num,i;
    int count = 0,j,maxPrime = 1;
    printf("Enter a number: ");
    scanf("%d",&num);
    for(i = 1; i <= num; i++)
    {
        count = 0;
        for(j = 1; j <= i; j++)
        {
            if(i % j == 0)
            {
                count++;
            }
        }
        if(count == 2)
        {
            if(maxPrime < i)    
            {
                maxPrime = i;
            }
        }
    }
    printf("Maximum Prime number between 1 to %d is %d\n",num,maxPrime);
    //exit status
    return 0;
}
When you run the program, the output will be following:
1
2
Enter a number: 100                                                                                                            
Maximum Prime number between 1 to 100 is 97

Filed Under: C Examples

Related Posts

  • C Program to Display Fibonacci Series
  • C Program to Add Digits of a Number
  • C Program to Addition Subtraction Multiplication Division of Numbers

Recent Posts

  • Download Grand Theft Auto: Vice City Audio File | Highly Compressed
  • Grand Theft Auto: Vice City Game Download For PC | Full Setup
  • SQL SHOW DATABASES Statement
  • Direct view storage Tube (DVST) in Computer Graphics
  • CRT Color Monitor in Computer Graphics

More…

  • C Tutorial

C Examples

  • Hello, World
  • Add Two Numbers
  • Area of Triangle
  • Sum of All Digits
  • Characters a to z
  • Characters A to Z
  • Check Leap Year
  • Reverse a Number
  • Palindrome Number
  • Sum of N Numbers
  • Multiply Using Addition
  • Print 1 to 10 Numbers
  • Even or Odd Number
  • Armstrong Number
  • Swap Using Temp
  • Swap Without Temp
  • Find Largest Numbers
  • Check Prime Number
  • Max Prime Number
  • Fibonacci Series
  • Numbers Divisible by 2
  • Factorial of a Number
  • Convert Total Days
  • Add Digits of Number
  • Count Whitespaces
  • Count Vowels
  • Magic Number
  • Happy Number
  • Strong Number
  • Perfect Number
  • Length of String
  • Count Words
  • Get More 200+ Examples ..

Copyright © 2019 - BeginnersBook.in - All Right Reserved || Sitemap