• Lets discuss a program on how to print prime numbers from 1 to 100.
  • Here by default we need to print all prime numbers from 1 to 100.
  • No need to ask user to enter a number because we need to end loop at 100.
  • Using for loop iterate from 1 to 100
  • Take one more loop and check each number is divisible by 1 and itself or not.
  • Program to print prime number between 1 to 100 in c

#1.C program to print prime numbers from 1 to 100

  1. #include <stdio.h>

  2. // c program to print prime numbers from 1 to 100
  3. // www.instanceofjava.com
  4. int main()
  5. {
  6.    int n, i,k, count = 0;
  7.  
  8.  printf("Prime numbers from 1 to 100\n");
  9. for(i=2;i<=100;i++)
  10.  {
  11.   for(k=2;k<i;k++)
  12.   {
  13.    if(i%k==0)
  14.    break;
  15.    else if(i==k+1)
  16.    printf("%d\n",i);
  17. }
  18. }
  19.  
  20.     getch();
  21.     
  22. }
  23.     



prime numbers from 1 to 100



Instance Of Java

We are here to help you learn! Feel free to leave your comments and suggestions in the comment section. If you have any doubts, use the search box on the right to find answers. Thank you! 😊
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu