Posts

Showing posts from August, 2017

C Program to Check Prime or Armstrong Number Using User-defined Function

Image
Example to check whether an integer is a prime number or an Armstrong or both by creating two separate functions. C Program to Check Prime or Armstrong Number Using User-defined Function To understand this example, you should have the knowledge of following C programming topics: C Program to Display Prime Numbers Between Intervals Using Function In this program, two user-defined functions  checkPrimeNumber()  and  checkArmstrongNumber() are created. The  checkPrimeNumber()  returns 1 if the number entered by the user is a prime number. Similarly,  checkArmstrongNumber()  returns 1 if the number entered by the user is an Armstrong number. Example: Check Prime and Armstrong Number #include <stdio.h> #include <math.h> int checkPrimeNumber(int n); int checkArmstrongNumber(int n); int main() {     int n, flag;     printf("Enter a positive integer: ");     scanf("%d", &n);     // Check prime nu

C Program to Display Prime Numbers Between Intervals Using Function

Image
Example to print all prime numbers between two numbers (entered by the user) by making a user-defined function. Prime Numbers To understand this example, you should have the knowledge of following C programming topics: C Program to Calculate the Power of a Number C Program to Check Whether a Number is Palindrome or Not To find all prime numbers between two integers,  checkPrimeNumber()  function is created. This function  C Program to Reverse a Number Example: Prime Numbers Between Two Integers #include <stdio.h> int checkPrimeNumber(int n); int main() {     int n1, n2, i, flag;     printf("Enter two positive integers: ");     scanf("%d %d", &n1, &n2);     printf("Prime numbers between %d and %d are: ", n1, n2);     for(i=n1+1; i<n2; ++i)     {         // i is a prime number, flag will be equal to 1         flag = checkPrimeNumber(i);         if(flag == 1)             printf("%d ",i);