afaq

Fascinating Number Program in Java

Example: 327 Multiply with 2: 327×2=654 Multiply with 3: 327×3=981 Now, concatenate the all number. “327”+”654″+ “981”= 327654981 Here we can see that all digits from 1 to 9 are available in concatenating string. import java.util.Scanner; public class FascinatingNumber { public static void main(String args[]) { int num, num2, num3; Scanner sc = new Scanner(System.in); […]

Evil Number Program in Java

import java.util.Scanner; public class EvilNumber { public static void main(String[] args) { int n,num; Scanner sc = new Scanner(System.in); System.out.print(“Enter number=”); n = sc.nextInt(); int binaryDigits=0; String binary = “”; num=n; while (num > 0) { binary= num % 2 + binary ; if(num%2==1) { binaryDigits++; } num = num / 2; } if(binaryDigits%2==0) { […]

Insertion Sort Program in Java

import java.util.*; public class InsertionSort { public static void main(String[] args) { int arr[] = new int[10]; Scanner sc = new Scanner(System.in); for (int i = 0; i < 10; i++) { System.out.print(“Enter the number ar[” + i + “]:”); arr[i] = sc.nextInt(); } int n = arr.length; int temp, j; for (int i = […]

Deleting Element From Array Program in Java

import java.util.Scanner; public class DeletingElementFromArray { public static void main(String[] args) { int arr[] = new int[10]; Scanner sc = new Scanner(System.in); for (int i = 0; i < 10; i++) { System.out.print(“Enter the number ar[” + i + “]:”); arr[i] = sc.nextInt(); } int n = arr.length; int newarr[] = new int[n – 1]; […]

Adding Element In Array Program in Java

import java.util.Scanner; public class AddingElementInArray { public static void main(String[] args) { int arr[] = new int[10]; Scanner sc = new Scanner(System.in); for (int i = 0; i < 10; i++) { System.out.print(“Enter the number ar[” + i + “]:”); arr[i] = sc.nextInt(); } int n = arr.length; int newarr[] = new int[n + 1]; […]

Capricorn or Kaprekar Number Program in Java

A number is called Capricorn or Kaprekar number whose square is divided into two parts in any conditions and parts are added, the additions of parts is equal to the number, is called Capricorn or Kaprekar number.

Example: 45

45 =  (45)2 = 2025

2025
All parts for 2025:-
202 + 5 = 207 (not 45)
20 + 25 = 45
2 + 025 = 27 (not 45)

Above we can see one combination is equal to number so that 45 is Capricorn or Kaprekar number.

LCM and HCF of two numbers Program in C

/*Program to find the LCM and HCF of two numbers*/ #include<stdio.h> int main(void) { int x,y,a,b; printf(“Enter two numbers : “); scanf(“%d%d”,&x,&y); a=x; b=y; while(a!=b) { if(ab) a=a-b; else b=b-a; } printf(“HCF of %d and %d is %d\n”,x,y,a); return 0; } Output: Enter two numbers : 36 48 LCM of 36 and 48 is 144 […]

Find day of week from a given date Program in C

/*P5.41 Program to find day of week from a given date*/ #include<stdio.h> int main(void) { int d,m,y,j,f,h,fh,day; printf(“Enter date(dd/mm/yyyy): “); scanf(“%d/%d/%d”,&d,&m,&y); j=d; switch(m-1) { case 11: j+=30; /*Fall thru in all cases*/ case 10: j+=31; case 9: j+=30; case 8: j+=31; case 7: j+=31; case 6: j+=30; case 5: j+=31; case 4: j+=30; case 3: […]

Difference of two dates in years, months, days Program in C

/*Program to get difference of two dates in years, months, days*/ #include<stdio.h> int main(void) { int d1,d2,d,m1,m2,m,y1,y2,y; printf(“Enter first date(dd/mm/yyyy): “); scanf(“%d/%d/%d”,&d1,&m1,&y1); printf(“Enter second date(dd/mm/yyyy): “); scanf(“%d/%d/%d”,&d2,&m2,&y2); if(d2<d1) { if(m2==3) { if(y2%100!=0 && y2%4==0 || y2%400==0) /*check for leap year*/ d2=d2+29; else d2=d2+28; } else if(m2==5 || m2==7 || m2==10 || m2==12) d2=d2+30; else d2=d2+31; […]

Check whether a date is valid or not Program in C

/*Program to check whether a date is valid or not*/ #include<stdio.h> int main(void) { int d,m,y; int flag=1,isleap=0; printf(“Enter date(dd/mm/yyyy): “); scanf(“%d/%d/%d”,&d,&m,&y); if(y%100!=0 && y%4==0 || y%400==0) isleap=1; if(y2050 || m12 || d31) flag=0; else if(m==2) /*Check for number of days in February*/ { if(d==30 || d==31 || (d==29 && !isleap) ) flag=0; } else […]

1 3 4 5 6 7 36