commit
This commit is contained in:
1 parent
9cebf357a5
commit
038ca57c53
4 files changed
+188
-188
No files matched your search
+24
-24
@@ -1,25 +1,25 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
// step 1: get last digit by n%10;
|
// step 1: get last digit by n%10;
|
||||||
// step 2: get first digit by n / pow(10,log10(n))
|
// step 2: get first digit by n / pow(10,log10(n))
|
||||||
// step 3: swap first digit with last by n- last digit + first
|
// step 3: swap first digit with last by n- last digit + first
|
||||||
// step 4: swap last digit with first by n - pow(10,log10(n))*first digit: get the numbers aside from first
|
// step 4: swap last digit with first by n - pow(10,log10(n))*first digit: get the numbers aside from first
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int n = 8673;
|
int n = 8673;
|
||||||
int last_digit = n%10;
|
int last_digit = n%10;
|
||||||
int c = log10(n);
|
int c = log10(n);
|
||||||
int b = pow(10,c);
|
int b = pow(10,c);
|
||||||
int first_digit = n / b;
|
int first_digit = n / b;
|
||||||
|
|
||||||
printf("first digit is %d and last digit is %d\n",first_digit,last_digit);
|
printf("first digit is %d and last digit is %d\n",first_digit,last_digit);
|
||||||
|
|
||||||
int n_without_fd = n - b*first_digit;
|
int n_without_fd = n - b*first_digit;
|
||||||
int new_n = last_digit*b + n_without_fd;
|
int new_n = last_digit*b + n_without_fd;
|
||||||
new_n = new_n - last_digit + first_digit;
|
new_n = new_n - last_digit + first_digit;
|
||||||
|
|
||||||
printf("n: %d",new_n);
|
printf("n: %d",new_n);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+23
-23
@@ -1,24 +1,24 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
void findMax(int *max, int a)
|
void findMax(int *max, int a)
|
||||||
{
|
{
|
||||||
if (a > *max)
|
if (a > *max)
|
||||||
{
|
{
|
||||||
max = &a;
|
max = &a;
|
||||||
printf("max is now: %d", *max);
|
printf("max is now: %d", *max);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
printf("Not bigger");
|
printf("Not bigger");
|
||||||
|
|
||||||
}
|
}
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int a = 6;
|
int a = 6;
|
||||||
int b = 5;
|
int b = 5;
|
||||||
|
|
||||||
int *pB = &b;
|
int *pB = &b;
|
||||||
|
|
||||||
findMax(pB,a);
|
findMax(pB,a);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+69
-69
@@ -1,70 +1,70 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
typedef struct complex_no
|
typedef struct complex_no
|
||||||
{
|
{
|
||||||
float real;
|
float real;
|
||||||
float imaginary;
|
float imaginary;
|
||||||
} Complex;
|
} Complex;
|
||||||
|
|
||||||
Complex add(Complex a, Complex b)
|
Complex add(Complex a, Complex b)
|
||||||
{
|
{
|
||||||
Complex Sum;
|
Complex Sum;
|
||||||
Sum.real = a.real + b.real;
|
Sum.real = a.real + b.real;
|
||||||
Sum.imaginary = a.imaginary + b.imaginary;
|
Sum.imaginary = a.imaginary + b.imaginary;
|
||||||
}
|
}
|
||||||
|
|
||||||
Complex multi(Complex a, Complex b)
|
Complex multi(Complex a, Complex b)
|
||||||
{
|
{
|
||||||
Complex Product;
|
Complex Product;
|
||||||
Product.real = a.real * b.real - a.imaginary*b.imaginary;
|
Product.real = a.real * b.real - a.imaginary*b.imaginary;
|
||||||
Product.imaginary = a.real*b.imaginary + a.imaginary*b.real;
|
Product.imaginary = a.real*b.imaginary + a.imaginary*b.real;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Backing Up
|
/* Backing Up
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
typedef struct Complex_No
|
typedef struct Complex_No
|
||||||
{
|
{
|
||||||
float real;
|
float real;
|
||||||
float imaginary;
|
float imaginary;
|
||||||
} Complex;
|
} Complex;
|
||||||
|
|
||||||
Complex Add(Complex no1, Complex no2)
|
Complex Add(Complex no1, Complex no2)
|
||||||
{
|
{
|
||||||
Complex Sum;
|
Complex Sum;
|
||||||
Sum.real = no1.real + no2.real;
|
Sum.real = no1.real + no2.real;
|
||||||
Sum.imaginary = no1.imaginary + no2.imaginary;
|
Sum.imaginary = no1.imaginary + no2.imaginary;
|
||||||
return Sum;
|
return Sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
Complex Multiply(Complex no1, Complex no2)
|
Complex Multiply(Complex no1, Complex no2)
|
||||||
{
|
{
|
||||||
Complex Product;
|
Complex Product;
|
||||||
Product.real = no1.real*no2.real - no1.imaginary*no2.imaginary;
|
Product.real = no1.real*no2.real - no1.imaginary*no2.imaginary;
|
||||||
Product.imaginary = no1.real*no2.imaginary + no1.imaginary*no2.real;
|
Product.imaginary = no1.real*no2.imaginary + no1.imaginary*no2.real;
|
||||||
return Product;
|
return Product;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Complex no1, no2;
|
Complex no1, no2;
|
||||||
no1.real = 5;
|
no1.real = 5;
|
||||||
no1.imaginary = 3.2;
|
no1.imaginary = 3.2;
|
||||||
|
|
||||||
no2.real = 13;
|
no2.real = 13;
|
||||||
no2.imaginary = 2;
|
no2.imaginary = 2;
|
||||||
|
|
||||||
Complex Sum = Add(no1,no2);
|
Complex Sum = Add(no1,no2);
|
||||||
Complex Multiplication = Multiply(no1,no2);
|
Complex Multiplication = Multiply(no1,no2);
|
||||||
|
|
||||||
printf("Sum is %f + i%f\n",Sum.real,Sum.imaginary);
|
printf("Sum is %f + i%f\n",Sum.real,Sum.imaginary);
|
||||||
printf("Product is %f + i%f",Multiplication.real,Multiplication.imaginary);
|
printf("Product is %f + i%f",Multiplication.real,Multiplication.imaginary);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
+72
-72
@@ -1,73 +1,73 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int Check_Prime(int n)
|
int Check_Prime(int n)
|
||||||
{
|
{
|
||||||
if (n<=1) return 0;
|
if (n<=1) return 0;
|
||||||
for (int i = 2;i<n;i++)
|
for (int i = 2;i<n;i++)
|
||||||
{
|
{
|
||||||
if (n%i == 0)
|
if (n%i == 0)
|
||||||
{
|
{
|
||||||
// printf("%d is Not prime",n);
|
// printf("%d is Not prime",n);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//printf("%d is prime",n);
|
//printf("%d is prime",n);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Check_Sphenic_off(int n)
|
int Check_Sphenic_off(int n)
|
||||||
{
|
{
|
||||||
int divisors[2];
|
int divisors[2];
|
||||||
int no = 0;
|
int no = 0;
|
||||||
int divisor_counter = 0;
|
int divisor_counter = 0;
|
||||||
for (int i=2;i<n;i++)
|
for (int i=2;i<n;i++)
|
||||||
{
|
{
|
||||||
if (n%i == 0)
|
if (n%i == 0)
|
||||||
{
|
{
|
||||||
if (Check_Prime(i) == 1)
|
if (Check_Prime(i) == 1)
|
||||||
{
|
{
|
||||||
divisors[divisor_counter] = i;
|
divisors[divisor_counter] = i;
|
||||||
divisor_counter++;
|
divisor_counter++;
|
||||||
}
|
}
|
||||||
no ++;
|
no ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((no == 6) && divisor_counter == 3)
|
if ((no == 6) && divisor_counter == 3)
|
||||||
{
|
{
|
||||||
if (divisors[0] && divisors[1] && divisors[2])
|
if (divisors[0] && divisors[1] && divisors[2])
|
||||||
printf("%d is sphenic",n);
|
printf("%d is sphenic",n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Check_Sphenic(int n)
|
int Check_Sphenic(int n)
|
||||||
{
|
{
|
||||||
if (n < 30) printf("sphenic");
|
if (n < 30) printf("sphenic");
|
||||||
int divisors_cnt = 0;
|
int divisors_cnt = 0;
|
||||||
|
|
||||||
for (int i = 2;i<n;i++)
|
for (int i = 2;i<n;i++)
|
||||||
{
|
{
|
||||||
if (n%i == 0)
|
if (n%i == 0)
|
||||||
{
|
{
|
||||||
divisors_cnt++;
|
divisors_cnt++;
|
||||||
if (divisors_cnt > 6)
|
if (divisors_cnt > 6)
|
||||||
{printf("not sphenic");
|
{printf("not sphenic");
|
||||||
break;}
|
break;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (divisors_cnt == 6)
|
if (divisors_cnt == 6)
|
||||||
printf("sphenic");
|
printf("sphenic");
|
||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int n = 64;
|
int n = 64;
|
||||||
Check_Sphenic_off(n);;
|
Check_Sphenic_off(n);;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user