Skip to main content

Posts

Program to find the suffix of a number (between 1-31) | C programming

  Q.3        WAP in C/ C++/ java to find the suffix of the given number.             Inputs               Outputs                1                            st                2                             nd                3                              rd                11                           th                21                          st    22                           nd               23                          rd Solution :  #include <stdio.h> // char* is a return type for string values char *   suffix ( int  x)  // function to return suffix of number in string form {      if  (x == 1   ||  x == 21   ||  x == 31 )          return   "st" ;      else   if  (x == 2   ||  x == 22 )          return   "nd" ;      else   if (x == 3   ||  x == 23 )          return   "rd" ;      else          return   "th" ;      } void   main () {      int   n ;      printf ( " \n Enter any positive number : " );      scanf

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 ( " \n Enter the lower limit : " );      scanf ( " %d " ,  & M );      printf ( "Enter the upper limit : " );      scanf ( " %d " ,  & N );      if (  M > N   ||   M == N   ||   M < 1   ||   M > 100   ||   N < 1   ||   N > 100 )     {          printf ( " \n Invalid input. Enter the inputs again -->" );          main ();     }      else     {          printf ( "The even numbers are : " );          for  (  int   i   =   M ;  i   <   N ;  i ++ )         {              /* code */              if ( i % 2 == 0 )                  printf ( " %d , " ,  i );         }              } } // end of main()

Program to perform to certain tasks using numbers | C programming

     1.          Q.1      WAP in C/ C++/ java to perform the following tasks : a.       Accept two numbers from the user( a and b). b.       Print the numbers. c.        Print the smallest number. d.       Calculate their :                                i.       Summation (a+b)                               ii.       Subtract them (a-b)                              iii.       Multiply them (a*b)                              iv.       Divide them (a/b – quotient)                               v.       Remainder (a%b)                              vi.       Square root of each number.

Number Program Exercise ( Level -1)

  Number Programs for Absolute Beginners : LEVEL 1 à 1.       WAP in C/ C++/ java to perform the following tasks : a.       Accept two numbers from the user( a and b). b.       Print the numbers. c.        Print the smallest number. d.       Calculate their :                                                               i.       Summation (a+b)                                                             ii.       Subtract them (a-b)                                                           iii.       Multiply them (a*b)                                                            iv.       Divide them (a/b – quotient)                                                              v.       Remainder (a%b)                                                            vi.       Square root of each numbers. 👉  View solution(1)   2.       WAP in C/ C++/ java to print the even numbers between M and N ( 0> M,N <100 )     👉  View solution(1)   3.       WAP in

Happy Number Solution | Recursion

  /**  * Write a Java program to find and print the Happy numbers between m and n. Happy number: Starting with any positive integer, replace the number by the sum of the squares of its digits,  and repeat the process until the number equals 1, or it loops endlessly in a cycle which does not include 1. Example: 19 is a happy number 1^2 + 9^2=82 8^2 + 2^2=68 6^2 + 8^2=100 1^2 + 0^2 + 02=1 The first few happy numbers are 1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100, ...  */ import java.util.*; public class HappyNum {     public static int digitSq( int x) // recursive function to find square of digits of the number     {         if(x<10)         return x*x;         else         return (x%10)*(x%10) + digitSq(x/10);     } // end of digitSq()          public static boolean isHappy(int num, int i)  // recursive function to check whether the no. is happy or not     {         //System.out.println(num);         if(num==1)         return true;         else i

Lucas Sequence Program Solution

  /**  * Write a Java program to display first N Lucas numbers. ( 3>N>100 ) The Lucas numbers or series are integer sequences named after the mathematician François Édouard Anatole Lucas,  who studied both that sequence and the closely related Fibonacci numbers.  Lucas numbers and Fibonacci numbers form complementary instances of Lucas sequences. The sequence of Lucas numbers : 2, 1, 3, 4, 7, 11, 18, 29, ….  */ import java.util.*; public class Lucas {     public static void lucas( int x, int a, int b) //recursive function to display lucas series     {         i f(x==0)             System.out.println();         else         {             int c=a+b;             a=b;             b=c;             System.out.print( ",   " +c);             lucas(x-1,a,b);         }     }   // end of lucas()          public static void main()     {         Scanner sc=new Scanner(System.in);         System.out.print( "\nEnter number of terms : " );         int N=sc.nextInt();      

Abundant Number Program Solution (Java) | Recursive Technique | ISC level

  /**  * Write a Java program to print all the possible Abundant numbers (integers) between M and N ( 1 > M,N < 100000) . In number theory, an abundant number is a number for which the sum of its proper divisors are greater than the number itself. The first few abundant numbers are: 12, 18, 20, 24, 30, 36, 40, 42, 48, 54, 56, 60, 66, 70, 72, 78, 80, 84, 88, 90, 96, 100,  102,... The integer 12 is the first abundant number. Its proper divisors are 1, 2, 3, 4 and 6 for a total of 16.  */ import java.util.*; public class AbundantNum {     public static int factors( int x, int f) / /recursive function to find the sum of factors of the number     {         if(x==f)              return 0;         else if(x%f==0)              return f+factors(x,f+1);         else              return factors(x,f+1);     }     public static void main()     {         Scanner sc=new Scanner(System.in);         System.out.print( "\nEnter the lower limit : " );         int M=sc.nextInt();