I suspect that you mean that you want to define constants, which is not possible in Python. Any variable can be rebound to something else at any time.
def factors(n): return [(x, sum([1 for y in range(1,int(ceil(log(n, x)))+1) if n%x**y == 0])) for x in range(2,int(n/2)) if all([x%q!=0 for q in range(2,int(x/2)+1)]) and n % x == 0] This will give you a list of factors with their exponents: print(factors(60)) # prints: [(2, 2), (3, 1), (5, 1)]
#include #include#define N 100 /* change the upper limit by changing value of N */int main(){int i;clrscr();printf("\nPROGRAM TO PRINT NUMBERS DIVISIBLE BY 8 between 1 and 100\n");for(i=1;i
/*PROGRAM TO IMPLEMENT GAUSS-jordan method.#include#define MX 20main(){float a[MX] [MX+1],m,p;int i,j,k,n;puts("\n how many equations?:");scanf("%d",&n);for(i=0;i
Algorithm: transpose Input: a matrix M[x][y] Output: the transpose of M (a matrix of order y * x) allocate N[y][x] for r = 0 to x-1 // iterate over rows for c = 0 to y-1 // iterate over columns N[c][r] = M[r][c] next c next r return N
#include <stdio.h> #include <string.h> #define N 100 #define PALINDROME 0 #define NONPALINDROME 1 /*Program that tells you whether what you enter is a palindrome or not*/ char pal[N]; //input line int i; //counter int k; //counter int tag; int flag = PALINDROME; /*flag=0 ->palindrome, flag =1 ->nonpalindrome*/ int main() { printf("Enter something: \n"); scanf("%s", pal); tag = strlen(pal); /*determine length of string*/ /* pointer running from the beginning and the end simultaneously looking for two characters that don't match */ /* initially assumed that string IS a palindrome */ /* the following for loop looks for inequality and flags the string as a non palindrome the moment two characters don't match */ for (i=0,k=tag-1; i=0; i++,k--) { if(pal[i] != pal[k]) { flag=NONPALINDROME; break; } } if(flag == PALINDROME) { printf("This is a palindrome\n"); } else { printf("This is NOT a palindrome\n"); } return 0; } #include <stdio.h> #include <string.h> #define N 100 #define PALINDROME 0 #define NONPALINDROME 1 /*Program that tells you whether what you enter is a palindrome or not*/ char pal[N]; //input line int i; //counter int k; //counter int tag; int flag = PALINDROME; /*flag=0 ->palindrome, flag =1 ->nonpalindrome*/ int main() { printf("Enter something: \n"); scanf("%s", pal); tag = strlen(pal); /*determine length of string*/ /* pointer running from the beginning and the end simultaneously looking for two characters that don't match */ /* initially assumed that string IS a palindrome */ /* the following for loop looks for inequality and flags the string as a non palindrome the moment two characters don't match */ for (i=0,k=tag-1; i=0; i++,k--) { if(pal[i] != pal[k]) { flag=NONPALINDROME; break; } } if(flag == PALINDROME) { printf("This is a palindrome\n"); } else { printf("This is NOT a palindrome\n"); } return 0; }
#define fact(n) ( n == 0 ? 1 ; (n*(fact(n-1) ) ) )
A recursive formula for the factorial is n! = n(n - 1)!. Rearranging gives (n - 1)! = n!/n, Substituting 'n - 1' as 0 -- i.e. n = 1 -- then 0! = 1!/1, which is 1/1 = 1.
// Author : SAGAR T.U, PESIT #define TRUE 1 #define FALSE 0 int isStrictBinaryTree (struct tree * n) { if( n NULL ) return TRUE; return FALSE; }
def factors(n): return [(x, sum([1 for y in range(1,int(ceil(log(n, x)))+1) if n%x**y == 0])) for x in range(2,int(n/2)) if all([x%q!=0 for q in range(2,int(x/2)+1)]) and n % x == 0] This will give you a list of factors with their exponents: print(factors(60)) # prints: [(2, 2), (3, 1), (5, 1)]
#include #include#define N 100 /* change the upper limit by changing value of N */int main(){int i;clrscr();printf("\nPROGRAM TO PRINT NUMBERS DIVISIBLE BY 8 between 1 and 100\n");for(i=1;i
The simplest answer is - because it is only defined for n = 0 (0! = 1) and n > 0 (n! = (n-1)! x n).
equation works for n = 0 and n = 1 as factors are n and n - 1
/*PROGRAM TO IMPLEMENT GAUSS-jordan method.#include#define MX 20main(){float a[MX] [MX+1],m,p;int i,j,k,n;puts("\n how many equations?:");scanf("%d",&n);for(i=0;i
The simple answer is that it is defined to be 1. But there is reason behind the decision.As you know, the factorial of a number (n) is equal to:n! = n * (n-1) * (n-2) ... * 1Another way of writing this is:n! = n * (n-1)!Suppose n=1:1! = 1 * 0!or1 = 1 * 0!or1 = 0!So by defining 0! as 1, formula involving factorials will work for all integers, including 0.
n! = n * (n-1) ! n!/n = n*(n-1)!/n //divid by n both sides n!/n = (n-1)! let n = 1 1!/1 = (1-1)! 1 = 0! Hence proved that 0! = 1.
#include#includevoid main(){int a[10],i=0,c=0,n;printf("\n enter the gray code");scanf("%d",&n);while(n!=0){a[i]=n%10;n/=10;i++;c++;}for(i=c-1;i>=0;i--){if(a[i]==1){if(a[i-1]==1)a[i-1]=0;elsea[i-1]=1;}}printf("\n the binary code is");for(i=c-1;i>=0;i--)printf("%d",a[i]);getch();}
8n2+4=12n 8n2-12n+4=0 2n2-3n+1=0 (2n-1)(n-1)=0 2n-1=0 or n-1=0 2n=1 n=1/2 or n=1