//program to check if a number is prime or not. //number that is divisible only by itself and 1 (e.g. 2, 3, 5, 7) // 0 and 1 are not prime numbers. // 2 is the only even prime number. #include<stdio.h> int main() { int n , a; printf("enter any number\n"); scanf("%d", &n); for(int i=1; i<=n; i++){ /*for loop is executed until the i value is equal to i*/ if(i%n==0){ a++; /* a will get increment if i%n=0 */ } } if(a==2){ printf("n is a prime number"); } else{ printf("n is not a prime number"); } return 0; } output : enter any number 5 n is not a prime number -------------------------------- Process exited after 8.33 seconds with return value 0 Press any key to continue . .
What is c? C is a programming language developed at AT & T' s Bell laboratories of USA in 1972. It was written and designed by a man named Dennis Ritchie. Why it is called C? It is called "C" because of it came after programming language "B" Which was created by Thompson. Why C is popular? C is popular because it is simple, easy, reliable to use. In industries new programs, tools, and technologies emerge and vanish day by day, a language that has survived for more than three decades has to be really good. Why do we need to learn C? C++, c#, java, and many other languages use the concept of (OOP) Object Oriented Programming to organize the program. OOP has lots of advantages to offer. TO use (OOP) you would still need a good hold over the language elements of C and the basic programming skills. So it makes more sense to first learn C and then migrate to other programming languages. Characters used in C In C, Characters include any Alphabet, Digits, and Sp...
Comments
Post a Comment
Please do not enter any spam link in the comment box.