How to write a C Program to print all prime numbers from 1 to 300. Using nested loops, break and continue statements in C Programming Language ?
This C Program to print all prime numbers from 1 to 300. (Hint: Use nested loops, break and continue statements.)- #include<stdio.h>
- main()
- {
- int number, div, ifprime;
- for (number=2;number<=300;number++)
- {
- for (div=2; div<number; div++)
- {
- if (number%div==0)
- {
- ifprime=0;
- break;
- }
- ifprime=1;
- }
- if (ifprime)
- {
- printf("\n%d", number);
- }
- }
- }
Try Some simple method to print all prime numbers from 1 to 300:
- #include
- void main()
- {
- int a,b;count=2;
- for(a=3;a<=50;a++)
- {
- for(b=2;b<=a-1;b++)
- if(a%b==0)
- break;
- else if(b==a-1)
- {
- count=count+1;
- printf("%d is a prime number\n",a);
- }
- }
- getche();
- }
- #include
- int main()
- {
- int num,div;
- for(num=2;num<=300;num++)
- {
- for(div=2;div<num;div++)
- {
- if((num%div==0))
- {
- break;
- }
- else if(div==num-1)
- {
- printf ("\n%d",num);
- }
- }
- }
- return(0);
- }
even more simple is here C Program to print all prime numbers from 1 to 300.
- #include
- void main()
- {
- int i,num;
- for(num=2;num<=1000 ;num++)
- {
- for(i=2;i<=num;i++)
- { if(num%i==0)
- break;
- }
- if(i==num)
- printf("\n%d is Prime",num);
- }
- }
c program to print prime numbers in a given range
You can change the i <= 300; like i <=1000 to print all prime numbers from 1 to 1000.
- int i,j;
- printf("2\t");
- for (i = 3; i <= 300; i++)
- {
- for (j = 2; j < i; j++)
- {
- if(i % j == 0)
- break;
- }
- if (i == j)
- printf("%d\t", i);
- }
Learn More :
print
- PRINT PRIME NUMBERS BETWEEN 1-300 USING BREAK AND CONTINUE IN C
- Write a c program to print Pascal triangle.
- C or C++ Program To Print Prime Number
- C Program print fill zero & mod/div
- C Program to printf & scanf Example
- C Program to Print a String Without Use Semicolon.
- C Program To Input & Print More Than One Words In Single Line
- C Program To Print Alphabets Like {Aa Bb Cc...}
- C Program To Print Alphabets Like {Az By Cx...}
- C Program To Print Lines Of A Paragraph Having More Than 15 Characters
- C Program To Print Prime Numbers Upto The Number You Want
- C Program To Print String In Formatted Output Form
- C Program To Print Sum Of n Digit Number
- C Program To Print Table Horizontally
- C Program To Print Tridiagonal Matrix
- C Program To Print Text Into Uppercase
- Printing ASCII Table with Numbers and corresponding characters
- C program that lets the user choose if he wants to add a item to the shopping list or print it out
- C Program to print table vertically
- Loudness Program: Gets loudness level from user; chooses a response And prints it using logical and operative statements
- C program that receives 10 float numbers from the console and sort them in non-ascending order, and prints the result
- Function should print the cartesian coordinates of the struct argument
- C Program Read a char & print next char ( file to file )
- Primul meu program in C Program
Prime Number
- PRINT PRIME NUMBERS BETWEEN 1-300 USING BREAK AND CONTINUE IN C
- Check given number is prime number or not using c program.
- C Program to Check Prime Use Loop And Recursive
- C or C++ program to print prime number
- C or C++ Program To Print Prime Number
- C Program For Prime Number or Not
- C Program For Prime Number Using Function
- C Program For Prime Number
- Huge Prime in C Program
- C Program to Detection of a Prime Number
- C Program To Find Prime Number And If Number Is Not Prime Then Find Factors
- C Program to Find Prime Number and Complex Number
- C Program to accept n numbers & store all prime numbers in an array & display this result
Continue Statement