This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int gcd(int a, int b){ | |
int ans = -1; | |
while(ans != 0){ | |
ans = a%b; | |
a = b; | |
b = ans; | |
} | |
return(a); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int fibnocci(int x){ | |
int fib[x]; | |
fib[0] = 0; | |
fib[1] = 1; | |
if (x>=2){ | |
int temp = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int swap(int* a, int* b){ | |
int temp; | |
temp = *a; | |
*a = *b; | |
*b = temp; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int fact(int a){ | |
if (a == 0){ | |
return 1; | |
} | |
else{ | |
return a * fact(a-1); | |
} | |
} | |
void main(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int power(int a, int b){ | |
if (b == 1){ | |
return(a); | |
} | |
else{ | |
return (a * power(a,b-1)); | |
} | |
} | |
void main(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
OlderNewer