Skip to main content

Printing Even Number within a given range | C programming

 Q.2  WAP in C/ C++/ java to print the even numbers between M and N ( 0> M,N <100 ).


Solution : 

#include<stdio.h>

void main()
{
    int M,N;
    printf("\nEnter the lower limit : ");
    scanf("%d"&M);

    printf("Enter the upper limit : ");
    scanf("%d"&N);

    ifM>N || M==N || M<1 || M>100 || N<1 || N>100)
    {
        printf("\nInvalid input. Enter the inputs again -->");
        main();
    }
    else
    {
        printf("The even numbers are : ");
        for ( int i = Mi < Ni++)
        {
            /* code */
            if(i%2==0)
                printf("%d, "i);
        }
        
    }
} // end of main()



Comments

Popular posts from this blog

Finding Factorial of a number | C programming

  Q.6      WAP in C/ C++/ java to find the factorial of the number. Solution :  #include <stdio.h> void   main () {      int   n ;      printf ( " \n Enter any positive number : " );      scanf ( " %d " ,  & n );      if  ( n < 0 )     {          printf ( " \n Invalid input! Enter the value again -->" );          main ();  // calls the main() function again     }      else     {          int   fact = 1 ;          for ( int   i = 1 ;  i <= n ;  i ++ )         {  ...

Neon Number | C programming

 Q.8     WAP in C/ C++/ java to check whether the number is a Neon number or not. Input: 9 Output: Neon Number Explanation: the square is 9*9 = 81 and the sum of the digits of the square ( 8+1) is 9. Solution :  #include <stdio.h> int   sumofdigits ( int  x)  // function to compute sum of digits {      int   sum = 0 ;      while (x > 0 )     {          sum += x % 10 ;         x = x / 10 ;     }      return   sum ; } int   main () {      int   n ;         printf ( " \n Enter any positive number : " );      scanf ( " %d " ,  & n );      if  ( n < 0 )     { ...

Special Number | C programming

 Q.9    WAP in C/ C++/ java to check whether the number is a Special Number or not. Definition: If the sum of the factorial of digits of a number (N) is equal to the number itself, the number (N) is called a  special  number. INPUT : 145     The digits of the number are: 1, 4, 5 Factorial of digits: 1! = 1 4! = 4*3*2*1 = 24 5! = 5*4*3*2*1 = 120 Sum of factorial of digits = 1 + 24 + 120 = 145             Hence, the given number 145 is a special number. Solution :  #include   <stdio.h> int   factorial ( int  x)  // function to return factorial of the number {      int   f   =   1 ;      for  ( int   i   =   1 ;  i   <=  x;  i ++ )     {     ...