Bismillahir Rahmanir Rahim
At first, you have to know what is prime number.
Prime Numbers:
A prime number can be divided, without a remainder, only by itself and by 1. For example, 17 can be divided only by 17 and by 1.
1. write a program in C the number is prime or not (Hints: without using loop).
Solution:we can easily solve this problem by using loop but here we can.t use any loop.
th alternate way to solve this problem is using goto function(keywards).If you don't know about goto function, click
Now see the program:-----#include<stdio.h> void main() { int Num,i,Count; Count=0; i=2; printf("Enter A Number :\n"); scanf("%d",&Num); Loop: if(Num%i==0) Count=Count+1; i=i+1; if(i<=Num) goto Loop; if(Count==1) printf("Number: %d is Prime.",Num); else printf("Number: %d is Not Prime.",Num); }
2.write a program in C the number is prime or not (Hints:using loop).
Solution:
Solution:
#include<stdio.h> void main() { int Num,i,Count; Count=0; printf("Enter A Number :\n"); scanf("%d",&Num); for(i=2;i<=Num;i++) { if(Num%i==0) Count=Count+1; } if(Count==1) printf("Number: %d is Prime.",Num); else printf("Number: %d is Not Prime.",Num); }
Find or print the prime number in 1 to 100.
#include<stdio.h> void main() { int num,i,count; for(num = 1;num<=100;num++) { count = 0; for(i=2;i<=num;i++) { if(num%i==0) count++; } if(count==1) printf("%d ",num); } }