Print All Prime Numbers between 1 and 100 : C Program

Computer Science » C Program » Print All Prime Numbers between 1 and 100

Program :

#include <stdio.h>
 
int main()
{
    int number,j,flag;
    printf(" The prime numbers between 1 and 100 : n");
    for(number=2;number<=100;number++)
    {
        flag=0;
        for(j=2;j<=number/2;j++)
        {
            if(number % j == 0)
            {
            flag = 1;
            break;
            }
        }
        if(flag==0)
            printf("n    %d ",number);
    }
    return 0;
}

Output :

The prime numbers between 1 and 100 : 

    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 
Subject Name : Computer Science
Exam Name : IIT GATE, UPSC ESE, RRB, SSC, DMRC, NMRC, BSNL, DRDO, ISRO, BARC, NIELIT
Posts Name : Assistant Engineer, Management Trainee, Junior Engineer, Technical Assistant
Computer Science Books

GATE 2023 Total InfoENGG DIPLOMAUGC NET Total Info
IES 2023 Total InfoPSUs 2022 Total InfoCSIR UGC NET Total Info
JAM 2023 Total InfoM TECH 2023 Total InfoRAILWAY 2022 Total Info

Related Posts

  • Print First 10 Natural Numbers : C ProgramComputer Science » C Program » Print First 10 Natural Numbers  Program : [php]#include<stdio.h> int main() { printf("1"); printf("2"); printf("3"); printf("4"); printf("5"); printf("6"); printf("7"); printf("8"); printf("9"); printf("10"); }[/php] Output : [php]12345678910[/php] Program : [php]#include<stdio.h> int main() { int i = 1; for (i = 1; i <= 10; i++) { printf("%d", i); } return (0); }[/php] Output : [php]12345678910[/php] Program : [php]#include<stdio.h> int main() { int i = 1; while (i <= 10) { printf("%d", i); i++; } return (0); }[/php] Output : [php]12345678910[/php] Program : [php]#include<stdio.h> int main() { int i = 1; do { printf("%d", i); i++; } while (i <= 10); return (0); }[/php] Output : [php]12345678910[/php] Program : [php]#include<stdio.h> int main() { int i = 0; Start: i = i + 1; printf("%d", i); if (i < 10) goto Start; }[/php] Output : [php]12345678910[/php]
    Tags: program, output, print, numbers, programs, computer, science
  • Find greatest in 3 numbers : C ProgramComputer Science » C Program » Find greatest in 3 numbers  Program : [php]#include&lt;stdio.h&gt; int main() { int a, b, c; printf(&quot;nEnter value of a, b &amp; c : &quot;); scanf(&quot;%d %d %d&quot;, &amp;a, &amp;b, &amp;c); if ((a &gt; b) &amp;&amp; (a &gt; c)) printf(&quot;na is greatest&quot;); if ((b &gt; c) &amp;&amp; (b &gt; a)) printf(&quot;nb is greatest&quot;); if ((c &gt; a) &amp;&amp; (c &gt; b)) printf(&quot;nc is greatest&quot;); return(0); }[/php] Output : [php]Enter value for a,b &amp; c : 12 16 20 c is greatest[/php]
    Tags: program, numbers, computer, science, output, programs
  • Check if a Number is Divisible by 3 : C ProgramComputer Science » C Program » Check if a Number is Divisible by 3 Program : [php]#include<stdio.h> int main() { int number; printf("Enter a number : "); scanf("%d",&number); if ((number % 3) == 0) printf("n%d is a multiple of 3.",number); else printf("n%d is not a multiple of 3.",number); return 0; }[/php] Output 1: [php]Enter a number : 9 9 is a multiple of 3.[/php] Output 2: [php]Enter a number : 8 8 is not a multiple of 3.[/php]
    Tags: program, output, computer, science, programs
  • Insert Element in An Array : C ProgramComputer Science » C Program » Insert Element in An Array Program : [php]#include<stdio.h> int main() { int arr[30], element, num, i, location; printf("nEnter no of elements : "); scanf("%d", &num); for (i = 0; i < num; i++) { scanf("%d", &arr[i]); } printf("nEnter the element to be inserted : "); scanf("%d", &element); printf("nEnter the location : "); scanf("%d", &location); //Create space at the specified location for (i = num; i >= location; i--) { arr[i] = arr[i - 1]; } num++; arr[location - 1] = element; //Print out the result of insertion for (i = 0; i < num; i++) printf("n %d", arr[i]); return (0); }[/php] Output : [php]Enter no of elements : 5 10 20 30 40 50 Enter the element to be inserted : 60 Enter the location : 3 10 20 60 30 40 50[/php]
    Tags: program, computer, science, output, programs
  • Reversing an Array Elements : C ProgramComputer Science » C Program » Reversing an Array Elements Program : [php]#include<stdio.h> int main() { int arr[30], i, j, num, temp; printf("nEnter no of elements : "); scanf("%d", &num); //Read elements in an array for (i = 0; i < num; i++) { scanf("%d", &arr[i]); } j = i - 1; // j will Point to last Element i = 0; // i will be pointing to first element while (i < j) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; i++; // increment i j--; // decrement j } //Print out the Result of Insertion printf("nArray after reversal : "); for (i = 0; i < num; i++) { printf("%d t", arr[i]); } return (0); }[/php] Output : [php]Enter no of elements : 5 10 20 30 40 50 Array after reversal : 50 40 30 20 10 [/php]
    Tags: program, computer, science, output, programs

LEAVE A REPLY

Please enter your comment!
Please enter your name here