Skip to content

Instantly share code, notes, and snippets.

View jatinsharrma's full-sized avatar

Jatin Sharma jatinsharrma

  • India
View GitHub Profile
@jatinsharrma
jatinsharrma / Kaprekar-number.py
Last active March 2, 2019 12:36
Kaprekar number in range
#This program accepts two numbers from user in different lines and calculate all the Kaprekar numbers between entered numbers.
#In mathematics, a non-negative integer is called a "Kaprekar number" for a given base if the representation of its square in that base can be split into two parts that add up to the original number, with the proviso that the part formed from the low-order digits of the square must be non-zero—although it is allowed to include leading zeroes. For instance, 45 is a Kaprekar number, because 452 = 2025 and 20 + 25 = 45. The number 1 is Kaprekar in every base, because 12 = 01 in any base, and 0 + 1 = 1. Kaprekar numbers are named after D. R. Kaprekar.
#-----------------------------------------
#function to calculate Kaprekar number
#-----------------------------------------
def calc(number):
global b
given = number
a= str(number*number)
@jatinsharrma
jatinsharrma / Kaprekar number_1.py
Created March 2, 2019 12:33
Program calculate Kaprekar numbers in range(1 and 100000)
# In mathematics, a non-negative integer is called a "Kaprekar number" for a given base if the representation of its square in that base can be split into two parts that add up to the original number, with the proviso that the part formed from the low-order digits of the square must be non-zero—although it is allowed to include leading zeroes. For instance, 45 is a Kaprekar number, because 452 = 2025 and 20 + 25 = 45. The number 1 is Kaprekar in every base, because 12 = 01 in any base, and 0 + 1 = 1. Kaprekar numbers are named after D. R. Kaprekar.
#this program calculate Kaprekar numbers between 1 and 100000
#this is shortform of the bigger program i wrote "Kaprekar number.py" that program can calculate a larger range. See my git.
#can increase the range by adding more Kaprekar number in all list.
start = int(input())
end = int(input())
all = [1, 9, 45, 55, 99, 297, 703, 999, 2223, 2728, 4950, 5050, 7272, 7777, 9999, 17344, 22222, 77778, 82656, 95121, 99999]
@jatinsharrma
jatinsharrma / GCD.c
Created March 27, 2019 12:45
to find GCD of two numbers
#include <stdio.h>
int gcd(int a, int b){
int ans = -1;
while(ans != 0){
ans = a%b;
a = b;
b = ans;
}
return(a);
@jatinsharrma
jatinsharrma / reverse.c
Created March 27, 2019 13:06
Reverse a given number
#include <stdio.h>
int reverse(int a){
int temp = 0 ;
int reverse = 0;
while (a != 0){
temp = a % 10;
reverse = reverse*10 + temp;
a = a/10;
@jatinsharrma
jatinsharrma / fibonacci.c
Last active March 27, 2019 13:48
Fibonacci Series
#include <stdio.h>
int fibnocci(int x){
int fib[x];
fib[0] = 0;
fib[1] = 1;
if (x>=2){
int temp = 2;
@jatinsharrma
jatinsharrma / prime_number.c
Created March 27, 2019 17:59
Find prime number to a specific number
//this program takes alot of memory if given number is big. Can optimize it by using dynamic array concept
#include <stdio.h>
int print(int p[], int index){
for(int i =0; i<index;i++){
printf("%d\n",p[i]);
}
}
int prime(int x){
@jatinsharrma
jatinsharrma / swap.c
Created March 31, 2019 12:10
Swapping two numbers - call by refernce
#include <stdio.h>
int swap(int* a, int* b){
int temp;
temp = *a;
*a = *b;
*b = temp;
}
@jatinsharrma
jatinsharrma / factorial.c
Created March 31, 2019 12:47
Factorial using recursion
#include <stdio.h>
int fact(int a){
if (a == 0){
return 1;
}
else{
return a * fact(a-1);
}
}
void main(){
@jatinsharrma
jatinsharrma / power.c
Last active March 31, 2019 14:41
Power function using recursion
#include <stdio.h>
int power(int a, int b){
if (b == 1){
return(a);
}
else{
return (a * power(a,b-1));
}
}
void main(){
@jatinsharrma
jatinsharrma / Sort.c
Last active April 1, 2019 10:41
Sorting a array - Sort
#include <stdio.h>
int Sort(int array[], int size){
for (int i = 0 ; i< size ;i++){
for (int j = i; j <size; j++){
if (array[j]< array[i]){
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}