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

C program to check whether a number entered by user is even or odd.

C program to check whether a number entered by user is even or odd.



#include <stdio.h>
int main(){
      int num;
      printf("Enter an integer you want to check: ");
      scanf("%d",&num);
      if((num%2)==0)      /* Checking whether remainder is 0 or not. */
           printf("%d is even.",num);
      else
           printf("%d is odd.",num);
      return 0;
}

C++ Program to check if a year is a leap year.

C++ Program to check if a year is a leap year.




#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter a year: ";
cin>>a;
if(a%400==0)
cout<<"It's a leap year"<<endl;
else if(a%100==0)
cout<<"It's not a leap year"<<endl;
else if(a%4==0)
cout<<"It's a leap year"<<endl;
else
cout<<"It's not a leap year"<<endl;
getch();
}

C - Determine If a Number is Odd or Even

How to write a C program to determine if a number is odd or even ?


Info! C program to determine if a number is odd or even
Solution:
#include <stdio.h>

int main()
{
int x;

scanf("%d", &x);

if(x % 2 == 0)
printf("Even");
else
printf("Odd");

return 0;
}

This C Program Determine If a Number is Odd or Even

C++ Program to check if two strings are identical.

How to write a C++ Program to check if two strings are identical or not in C++ Programming ?



C++ Program to check if two strings are identical. How to compare two strings in C++ How to Compare Two Strings in C++ Programming  Check if sizes of two strings are same Check whether two strings are anagram of each other
C++ Program to check if two strings are identical.

Solution:
//Program to check if two strings are identical.
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
#include<string.h>

int main()
{
clrscr();
char a[80],b[80];
int z=0;
cout<<"Enter a string: ";
gets(a);
cout<<"Enter another string: ";
gets(b);
if(strlen(a)!=strlen(b))
cout<<"The strings are not identical.";
for(int i=0;a[i]!='\0';i++)
if(a[i]==b[i])
++z;
if(z==strlen(a))
cout<<"The strings are identical.";
else
cout<<"The strings are not identical.";
getch();
}

This C++ Program to check if two strings are identical.

C++ Program to check if a string is palindrome.

How to write a Program to check if a string is palindrome in C++ Programming ?

C++ Program to check whether a String is Palindrome or not C++ Program to Check Whether String is Palindrome Program to check a string is palindrome or not - C++ Tutorial C++ Program to check whether a string is PALINDROME Write a c++ program to check whether a string is a palindrom A program to check for palindromes for C++ Code Example C++ program to check whether the given string is Program:To check if a string is a palindrome or not c++ - Check if a string is palindrome palindrome program  c program to check if a string is palindrome using pointers c program to check if a string is palindrome or not check if string is palindrome java check if string is palindrome using recursion check if string is palindrome python check if string is palindrome using stack check if string is palindrome geeksforgeeks
C++ Program to check if a string is palindrome.



Solution:
//Program to check if a string is palindrome.
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
clrscr();
char a[80];
int z=1;
cout<<"Enter a string: ";
gets(a);
int n=strlen(a);
for(int i=0,j=n-1;i<=(n-1)/2;i++,j--)
{
if(a[i]!=a[j])
{
z=0;
break;
}
}
if(z==0)
cout<<"The string is not palindrome.";
else
cout<<"The string is palinrome.";
getch();
}

This C++ Program to check if a string is palindrome.

C Program to Check Even Or Odd Number

This program will compute whether or not there is an odd or even number of ones. User can only input integer numbers. Set up for loop for bit comparison.
C program to check odd or even, check whether a number entered by user is odd or even, C program for odd or even number,odd or even in c program c# iseven how to determine if a number is odd or even C check for odd number how to check if a number is odd in C how to find odd numbers objective c odd number c get odd numbers
Check whether the given Number is Even or Odd

Solution:
//how to determine if a number is odd or even.
//C Program to check whether the given Number is Even or Odd.
//Write a C Program to check if number is odd or even number.
//C Program to print whether or not there is an odd or even number.
#include <stdio.h>

int initial;
int counter = 0;
int mod;
int result;
int comparator = 1;
   
int main () {  
/* Read in value of which to compute factorial */
printf("This program will compute whether or not there is an odd or even number of ones.\nPlease enter a number: ");
scanf("%d", &initial);
printf("\n");

/*Check for invalid input*/
while (initial < 0) {
        printf("This input is not valid. Only positive integers up to 2^31 are accepted\nEnter N: ");
scanf("%d", &initial);
      printf("\n");
}

/* set up for loop for bit comparison */
for(; initial > 0; initial = initial >> 1)  {
counter += (initial&1);
}    
     
/* Check if odd number or even number of 1s and print answer*/
if ((counter%2) == 1) {
printf("Your value is odd\n");
}
else {
printf("Your value is even\n");
}
    return 0;
}

This C Program to Check whether the given Number is Even or Odd Ones.