Showing posts with label Not. Show all posts
Showing posts with label Not. Show all posts

C Program to Detection of a Prime Number

How to write a C Program to Detection of a Prime Number in C Programming Language ?

Write a program to determine whether a number is prime or not. 

Note :A prime number is one, which is divisible only by 1 or itself. 

  1. #include<stdio.h>
  2. main()
  3. {
  4. int num, i;
  5.  
  6. printf ("Enter a number:");
  7. scanf ("%d", &num);
  8.  
  9. i=2;
  10. while (i<=num - 1)
  11.  
  12. {
  13. if (num % i ==0)
  14.  
  15. {
  16. printf ("Not a prime number");
  17. break;
  18. }
  19.  
  20. i++;
  21. }
  22.  
  23. if (== num)
  24.  
  25. printf ("Prime Number");
  26. }

C Program to Check Given String is Palindrome or Not

How to write a C Program to Check Given String is Palindrome or Not in C Programming Language ?


Solution:

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <string.h>
  4. void main()
  5. {
  6.  char a[10],b[10];
  7.  clrscr();
  8.  printf("\nEnter a string: ");
  9.  gets(a);
  10.  strcpy(b,a);
  11.  strrev(b);
  12.  if(strcmp(a,b)==0)
  13.  {
  14.   printf("%s is palindrom",a);
  15.  }
  16.  else
  17.  {
  18.   printf("%s is not palindrom",a);
  19.  }
  20.  getch();
  21. }

C Program To Find Prime Number And If Number Is Not Prime Then Find Factors

Write a C program to find prime number and if number is not prime then find factors of the number in C Programming Language ?


Solution:

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main()
  4. //C Program to Check whether the Given Number is a Prime
  5. //C program to display all the factors of a number entered by user.
  6. {
  7.  int flag=0,i,n,r,a[100],b=0,s;
  8.  clrscr();
  9.  printf("\n Enter Number: ");
  10.  scanf("%d",&n);
  11.  for(i=2;i<=n/2;i++)
  12.  {
  13.   r=n%i;
  14.   if(r==0)
  15.   {
  16.    flag=s;
  17.    a[b]=i;
  18.    b++;
  19.   }
  20.  }
  21.  if(flag==s)
  22.  {
  23.   printf(" So The Number %d is not prime",n);
  24.   printf("\n The factors are: ");
  25.   for(i=0;i<b;i++)
  26.   {
  27.    printf("%d ",a[i]);
  28.   }
  29.  }
  30.  else
  31.  {
  32.   printf("\n So The Number %d is prime",n);
  33.  }
  34.  getch();
  35. }

C Program to Check Whether Number Is Perfect Or Not

How to Write A C Program Whether a Number Is Perfect Or Not ?


Solution:

  1. #include<stdio.h>
  2. int main()
  3. {
  4.     int number,sum=0,i;
  5.     scanf("%d", &number);
  6.  
  7.     for(i=1; i<=number/2; i++) {
  8.         if(number%i==0) {
  9.             sum = sum + i;
  10.         }
  11.     }
  12.     if(sum==number) {
  13.         printf("Perfect Number");
  14.     }
  15.     else {
  16.         printf("Not");
  17.     }
  18. }

Input a Number and Check if it's Palindrome or not C Program

How to write a C Program to input a number and check if it's palindrome or not in C Programming Language ?



//Program to input a number and check if it's palindrome or not.
#include<stdio.h>
#include<conio.h>

void main()
{
int number,

clrscr();

printf("Enter number: ");
scanf("%d", &number);

while(number != 0) {
number % 10);
number = number / 10;
}

getch();
}

check if the number is a palindrome number or not.