Digital जीवन

Free Online Education for India...

Full width home advertisement

Computer Basic

C Programming

Engineering Graphics

Post Page Advertisement [Top]

Dr. A.P.J. Abdul Kalam Technical University, Lucknow

KCS151 / KCS251 Programming for Problem Solving - Using C Language


Lab Exercises


11. Write a program to print the entire prime no between 1 and 300.


/*
 File: Prgrm11.c
 Author: Aditya Saini
 Date: Jan 16, 2021
 Description: Program to print the entire prime no between 1 and 300.
*/

#include <stdio.h>

int main (void)
{
     int i, j;

     printf ("Prime numbers between 1 and 300: ");

     for (i = 2; i <= 300; i++)
     {
          //Checking if i is prime or not
          for (j = 2; j < i; j++)
          {
               if (i % j == 0)
                    break;
          }

          //Print if i is prime
          if (j == i)
               printf ("%d ", j);
     }

     return 0;
};

Output

Prime numbers between 1 and 300: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293



No comments:

Post a Comment

Please do not post spam links.

Bottom Ad [Post Page]

| Designed by Colorlib