Program to Print Prime Number less then N

-- Leave a Comment
Hello Here is A program to Print the Prime Number up to That Number which is inserted by users. Here we are using function. If you are not using function yet You can read the number in second function and process.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<stdio.h>
void prime(int);
void main()
    {
    int num;
    printf("Enter a Number up to which the prime numbers to be printed:- ");
    scanf("%d",&num);
    prime(num);
    }
void prime(int a)
    {
    int i,j;
    printf("1\t2\t");
    for (i=3;i<=a;i++)
        {
        for (j=2;j<i;j++)
            {
            if ((i%j)==0)
            break;
            }
        if(i==j)
        printf("%d\t",i);
        }
    }

Here we ask users for the max number up to which we need to print out the prime number and from there. we Pass that value to The function and Display the value.

Hello This is Sagar Devkota. Studying Bachelor of Software Engineering at Pokhara University. I know something about Linux, Android, Java, Nodejs, Unity3D and 3 dots :)

0 comments:

Post a Comment