Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- //funkciq zadacha 1
- int isPrime(int n){
- for(int i = 2; i < n; i++){
- if(n % i == 0){
- return 0;
- }
- }
- return 1;
- }
- //funkciq zadacha 2
- void Eratosthen(int n){
- int numbers[n];
- numbers[0] = 1;
- numbers[1] = 1;
- int start = 2;
- while(start <= 7){
- if(numbers[start] == 1){
- start++;
- continue;
- }
- numbers[start] = 0;
- for(int i = start * 2; i <= n; i += start){
- numbers[i] = 1;
- }
- start++;
- }
- for(int i = 0; i < n; i++){
- if(numbers[i] == 0){
- printf("%d\n", i);
- }
- }
- }
- //funkciq zadacha 3
- void BubbleSort(int arr[], int n){
- int temp;
- for(int i = 0 ; i < n - 1; i++){
- for(int j = 0 ; j < n - i - 1; j++){
- if(arr[j] > arr[j+1]){
- temp = arr[j];
- arr[j] = arr[j+1];
- arr[j+1] = temp;
- }
- }
- }
- }
- //funkciq zadacha 4
- int factorial(int n){
- if (n == 0){
- return 1;
- }
- return factorial(n - 1) * n;
- }
- //funkciq zadacha 5
- int Fibonachi(int* arr, int n, int start){
- arr[0] = 0;
- arr[1] = 1;
- arr[start] = arr[start - 1] + arr[start - 2];
- if(start <= n){
- Fibonachi(arr, n, start + 1);
- }
- return arr[n - 1];
- }
- //funkciq zadacha 6
- int power(int n1, int n2);
- int power(int a, int b) {
- if (b != 0){
- return (a * power(a, b - 1));
- }else{
- return 1;
- }
- }
- //funkciq zadacha 7
- int NOD(int a, int b){
- if (a == 0){
- return b;
- }else if (b == 0){
- return a;
- }
- if (a == b){
- return a;
- }
- if (a > b){
- return NOD(a-b, b);
- return NOD(a, b-a);
- }
- }
- //funkciq zadacha 8
- double sumArr(double* arr, int size, int start){
- if (start == size){
- return 0;
- }
- return arr[start] + sumArr(arr, size, start + 1);
- }
- int main(){
- //zadacha 1
- //printf("%s\n", isPrime(13) ? "Yes" : "No");
- //zadacha 2
- //Eratosthen(100);
- //zadacha 3
- /*
- int arr[] = {7, 20, 6, 3, 33};
- BubbleSort(arr, 5);
- for(int i = 0; i < 5; i++){
- printf("%d\n", arr[i]);
- }
- */
- //zadacha 4
- //printf("%d\n", factorial(7));
- //zadacha 5
- /*
- int n = 8;
- int arr[n];
- printf("%d\n", Fibonachi(arr, n, 2));
- */
- //zadacha 6
- /*
- int a, b, result;
- printf("Enter number: ");
- scanf("%d", &a);
- printf("Enter power: ");
- scanf("%d", &b);
- result = power(a, b);
- printf("%d", result);
- */
- //zadacha 7
- /*
- int a = 24;
- int b = 16;
- printf("Largest common divisor is %d ", NOD(a, b));
- */
- //zadacha 8
- /*
- double arr[] = {7, 3, 6, 11, 8};
- printf("%f\n", sumArr(arr, 5, 0));
- */
- return 0;
- }
Add Comment
Please, Sign In to add comment