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