Showing posts with label Check. Show all posts
Showing posts with label Check. Show all posts

CHECKING LEAP YEAR USING C PROGRAM.

How To CHECKING LEAP YEAR USING C PROGRAM.


#include<stdio.h>#include<conio.h>void main(){    int year;    clrscr();    printf("Enter any year: ");    scanf("%d",&year);    if(((year%4==0)&&(year%100!=0))||(year%400==0))         printf("%d is a leap year",year);    else         printf("%d is not a leap year",year);    getch();}

Check given number is prime number or not using c program.

How To Check given number is prime number or not using c program.


#include<stdio.h>
int main(){
    int num,i,count=0;
    printf("\nEnter a number:");
    scanf("%d",&num);
    for(i=2;i<=num/2;i++){
        if(num%i==0){
         count++;
            break;
        }
    }
   if(count==0)
        printf("%d is a prime number",num);
   else
      printf("%d is not a prime number",num);
   return 0;

}

Write a c program to check given string is palindrome number or not.

How to Write a c program to check given string is palindrome number or not.


#include<string.h>
#include<stdio.h>
int main(){
  char *str,*rev;
  int i,j;
  printf("\nEnter a string:");
  scanf("%s",str);
  for(i=strlen(str)-1,j=0;i>=0;i--,j++)
      rev[j]=str[i];
      rev[j]='\0';
  if(strcmp(rev,str))
      printf("\nThe string is not a palindrome");
  else
      printf("\nThe string is a palindrome");
  return 0;
}

C Program to Check Prime Use Loop And Recursive

How to write a C Program to Check Prime Use Loop And Recursive in C Programming Language ?


Solution For C Program :
/*Check Prime Use Loop And Recursive*/

C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not

How to write a C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not in C Programming Language ?


Solution For C Program :

/*C Program To Find The Length, Reverse Of A String And To Check It Is Palindrome or Not.*/

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,length=0,flag;
char str[10],rev[10];
clrscr();
printf("Enter the string==>");
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
{
length++;
}
printf("\nLength of %s is ==>%d\n",str,length);
length--;
for(i=0;length>=0;i++)
{
 rev[i]=str[length];
 length--;
}
rev[i]='\0';
printf("\nReverse of %s is ==>%s\n",str,rev);

 length++;
for(i=0;rev[i]!='\0';i++)
{
length++;
}
printf("\nLength of %s is ==>%d\n",rev,length);

for(i=0;str[i]!='\0'||rev[i]!='\0';i++)
{
if(str[i]!=rev[i])
    {
    flag=1;
    break;
    }
}
if(flag==1)
printf("\nString is not polyndrom");
else
printf("\nString is polyndrom");
getch();
}

C Program To Check The Given Value Is Vowel

How to write a C Program To Check The Given Value Is Vowel in C Programming Language ?

Solution For C Program :

/*C Program To Check The Given Value Is Vowel*/

#include<stdio.h>
void main()
{
int flag = 0;
int ceckvowel(void);
printf("\nIn Main Control.\n Check Vowel.\n");
do
{
if(checkvowel() == 1)
{
printf("\nThe Given Character is a Vowel.");
flag = 1;
}
else
{
printf("\nTry Again...");
flag = 0;
}
}while(flag == 0);
}
int checkvowel(void)
{
char ch;
printf("\nEnter Any Character : ");
ch = getche();
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' ||
ch == 'I' || ch =='O' || ch =='U')
return 1;
else
return 0;
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Function to Check Vowel

How to write a C Function to Check Vowel in C Programming Language ?


Solution:

C Function to Check Vowel

int check_vowel(char a)
{
    if ( a >= 'A' && a <= 'Z' )
       a = a + 'a' - 'A';   /* Converting to lower case */

    if ( a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
       return 1;

    return 0;
}

C Program To Check Leap Year

How to write a C Program To Check Leap Year in C Programming Language ?

Solution:

C Program To Check Leap Year

#include <stdio.h>

main()
{
   int year;

   printf("Enter a year to check if it is a leap year\n");
   scanf("%d", &year);

   if ( year%400 == 0)
      printf("%d is a leap year.\n", year);
   else if ( year%100 == 0)
      printf("%d is not a leap year.\n", year);
   else if ( year%4 == 0 )
      printf("%d is a leap year.\n", year);
   else
      printf("%d is not a leap year.\n", year);

   return 0;
}

C Program To Check If It Is A Palindrome Numbers Or Not

How to write a C Program To Check If It Is A Palindrome Numbers Or Not in C Programming Language ?

Solution:

C Program To Check If It Is A Palindrome Numbers Or Not

#include<stdio.h>

main()
{
   int n, reverse = 0, temp;

   printf("Enter a number to check if it is a palindrome or not\n");
   scanf("%d",&n);

   temp = n;

   while( temp != 0 )
   {
      reverse = reverse * 10;
      reverse = reverse + temp%10;
      temp = temp/10;
   }

   if ( n == reverse )
      printf("%d is a palindrome number.\n", n);
   else
      printf("%d is not a palindrome number.\n", n);

   return 0;
}

C Program to Check if a number is in an array[1000]

How to write a C Program to check if a number is in an array[1000] in C Programming Language ?

This C Program to Check if a number is in an array[1000].

Insert number for check.
If Number is found in the array[1000].
Else Number is not found in the array[1000].

Solution:

  1. #include <stdio.h>
  2. int check_number(double ar[1000],  double num);
  3. int main()
  4. {
  5.     double ar[1000], num;
  6.     int n ,i;
  7.     printf("n = ");
  8.     scanf("%d", &n);
  9.     printf("Insert Numbers : \n");
  10.     for(= 0 ; i < n ; i ++)
  11.     {
  12.         scanf("%lf", &ar[i]);
  13.     }
  14.     printf("Insert number for check : ");
  15.     scanf("%lf",&num);
  16.     if(1 == check_number(ar,num))
  17.     {
  18.         printf("Number is found in the array.\n");
  19.     }
  20.     else
  21.     {
  22.         printf("Number is not found in the array.\n");
  23.     }
  24.     return 0;
  25. }
  26. int check_number(double ar[1000], double num)
  27. {
  28.     int i;
  29.     for(= 0 ; ar[i] != '\0' ; i++)
  30.     {
  31.         if(num == ar[i])
  32.         {
  33.             return 1;
  34.         }
  35.     }
  36.     return 0;
  37. }

Armstrong Number Checker in C

How to write a C Program to Armstrong Number Checker in C Programming Language ?


An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.


Solution:

  1. #include <stdio.h>
  2.  
  3. int numbers[50];
  4. int digit, i=0, j, sum=0, lengthOfNumber, armstrong;
  5.  
  6. int separateDigits(num){
  7. // This function first takes modulus by dividing the number by 10 and then actually divides it by 10.
  8.     while(num>0){
  9.         numbers[i]=num%10;
  10.         num/= 10;
  11.         i++;
  12.     }
  13.     lengthOfNumber=i;
  14. }
  15. int checkArmstrong(originalNumber){
  16.     for(j=0; j<=lengthOfNumber; j++){
  17.         sum+=numbers[j]*numbers[j]*numbers[j];
  18.     }
  19.     if(sum==originalNumber){
  20.         return 1;
  21.     }
  22.     else return 0;
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28.     printf("Enter Number : ");
  29.     scanf("%d", &digit);
  30.     separateDigits(digit);              //We separate digits by calling a function separateDigits and giving the input as argument.
  31.     armstrong = checkArmstrong(digit);          // Variable 'armstrong' holds the value that the function returns.
  32.     if(armstrong==1){
  33.         printf("\nNumber is Armstrong !");
  34.     }
  35.     else printf("\nNumber is not Armstrong!");
  36.    return 0;
  37. }