Showing posts with label Prime Number program in C. Show all posts
Showing posts with label Prime Number program in C. Show all posts
Palindrome program in C

Palindrome program in C

What is Palindrome Number, 

Palindrome number in c language: A palindrome number is a number that is same after reverse. For example: 121, 131, 151, 34543, 343, 48984 are the palindrome numbers.

Palindrome number Program are asked interviewer for freshers and Experience holders.

How to Write a Palindrome number Program & its Execution Steps 

  • Take the number from user Input
  • Hold these number in temporary variable
  • Reverse Input number
  • Compare the temporary number with the reversed number
  • If both numbers are same, print palindrome number
  • Else print not palindrome number
Lets see how to write a Program of palindrome number using in C langusge. In this c program, we will get an input from the user and check whether number is palindrome or not.
  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. main()  
  4. {  
  5. int n,r,sum=0,temp;  
  6. clrscr();  
  7. printf("enter the number=");  
  8. scanf("%d",&n);  
  9. temp=n;  
  10. while(n>0)  
  11. {  
  12. r=n%10;  
  13. sum=(sum*10)+r;  
  14. n=n/10;  
  15. }  
  16. if(temp==sum)  
  17. printf("palindrome number ");  
  18. else  
  19. printf("not palindrome");  
  20. getch();  
  21. }  
Output:
enter the number=151
palindrome  number
enter the number=5621
not palindrome  number

Prime Number program in C language With Example

Prime Number program in C language

Prime numberPrime number is a whole number that is larger than one (1) and divided by 1 or itself.

 In other words, 

prime number has only two Factor that are 1 and itself. For example 2, 3, 5, 7, 11, 13, 17, 19, 23.... are the prime numbers.

Note: Zero (0) and 1 are not considered as prime numbers. Two (2) is the only one even prime number because all the Even numbers can be divided by 2.



Let's see how to write prime number program in C language and Execution of C Program. In this c program, we will get an input from the user and check This the number is prime or not.
  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. void main()  
  4. {  
  5. int n,i,m=0,flag=0;  
  6. clrscr();  
  7. printf("Enter the number to check prime:");  
  8. scanf("%d",&n);  
  9. m=n/2;  
  10. for(i=2;i<=m;i++)  
  11. {  
  12. if(n%i==0)  
  13. {  
  14. printf("Number is not prime");  
  15. flag=1;  
  16. break;  
  17. }  
  18. }  
  19. if(flag==0)  
  20. printf("Number is prime");  
  21. getch();  
  22. }   
Output:
Enter the number to check prime:56
Number is not prime
Enter the number to check prime:23
Number is prime

Popular Posts