Skip to main content

Posts

Featured

Write a program to check if a number is prime or not.

 //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 . .

Latest Posts

Nested loop.

Loop Control Statements

write a program to calculate the sum of all numbers from 1 and 100.

write a program to print reverse of the table for a number n.

write a program to print the factorial of a number n.

write a program to print all the odd numbers from 1 to 100.

program to (keep taking number as input from user until user enters a number which is multiple of 5.)

write a program (keep taking numbers as input from user until user enters an Odd number)

Write a program to print the table of number input by the user.

write a program to print the sum of first n natural numbers and also, print them in reverse.