nejaké funkcie...:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stddef.h> #include <math.h>
void change_whites(char string[]){ int i = 0; while (string[i] == '\0') { if (string[i] == ' ' || string[i] == '\n'){ string[i] = '.'; } i++; } } ... ... void swap_sign(const int size, int array[]){ if (array == NULL){ return; } for (int i = 0; i < size; i++){ array[i] = - array[i]; } } ... ... int count_zeroes_2d(const int size, int array[][size]) { int rt = 0; for (int i = 0; i < size;i++) { for (int j = 0; j < size;j++){ if (array[i][j] == 0){ rt++; } } }
return rt; } ... ... long multiples(const int bellow){ if (bellow >= 10000 || bellow < 0){ return -1; } int rt = 0; int multiple = 3; while (multiple < bellow){ rt += multiple; multiple += 3; }
multiple = 5;
while (multiple < bellow){
if (multiple % 3 != 0){ rt += multiple; }
multiple += 5;
}
return rt; } ... ... int pick_possible(const int corner){ if (corner < 0){ return -1; }else if(corner == 0){ return 0; }else { return 1; } } ... ... MEDIAN:
#include <stdio.h> #include <stdbool.h> #include <math.h> #include <string.h>
int main() { int a,n; int array[10000]; int num; int num2; float vysledok; scanf("%d",&n); for(int i=0; i<n; i++){ scanf("%d",&a); array[i]=a; } if(n%2 != 0){ num = n/2; printf("%d\n",array[num]); } else{ num = n/2; num2 = n/2-1; vysledok = (array[num]+array[num2])/2.0; if(array[num]+array[num2] % 2 ==0){ printf("%d\n",(int)vysledok) } else{ printf("%.1f\n",vysledok); } } return 0; } ... ... WORKER DIV:
#include <stdio.h> #include <stdbool.h> #include <math.h> #include <string.h>
int main() {
int min_nm = 0; int max_nm = 0; scanf("%d", &min_nm); scanf("%d", &max_nm); if(min_nm < 1 || max_nm > 10000){ return 0; } for (int i = min_nm; i < max_nm;i++){
if (i %7 == 2 || i % 7 == 3){ printf("%d\n",i); }
}
return 0; } ... int is_whites(const char string[]){ int sum = 0; if(string == NULL){ return -1; } for(int i = 0; i < strlen(string); i++){ if((string[i] == '\n') || (string[i] == '\t') || (string[i] == ' ')){ sum++; } } return sum; } ... int last_positive(const int array[], const int size){ int a = 0; if(array == NULL){ return -1; } for(int i = 0; i < size; i++){ if(array[i] > 0){ a = array[i]; } } return a; } ... int fibonachi(const int c){ if(c <= 1){ return c; }else{ return fibonachi(c-1) + fibonachi(c-2); } } ... void mocnina(){ int a, b, c; scanf("%d %d %d", &a, &b, &c); //printf("%d %d %d\n", a, b, c); for(int i = a; i <= b; i++){ printf("%d : 1 ",i); int d = i; for(int j = 0; j < c; j++){ d *= i; printf("%d", d); if(j+1 < c){ printf(" "); } } printf("\n"); } } ... void dec_to_bin(){ int n; scanf("%d", &n); int binarynum[32]; int i = 0; while(n > 0){ binarynum[i] = n % 2; n = n/2; i++; } for(int j = i - 1; j >= 0; j--){ printf("%d", binarynum[j]); } } ... int bin_to_dec(long long n) { int dec = 0; int i = 0; int rem; while (n != 0) { rem = n % 10; n /= 10; dec += rem * pow(2, i); ++i; } return dec; } ... int div_by_3(const int a){ if(a == NULL){ return -1; } if(a % 3 == 0){ return 1; } else{ return 0; } } ... int vowels(const char str[]){ int lowercase, uppercase; int sum = 0; if(str == NULL){ return -1; } for(int i = 0; i < strlen(str); i++){ if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u' || str[i] == 'A' || str[i] == 'E' || str[i] == 'I' || str[i] == 'O' || str[i] == 'U'){ sum++; } } return sum; } ... delenie 2 +-: int is_prime(const int num){ int i,p=0; for(i = 1; i<=num; i++){ if(num%i==0){ p++; } } if(p==2){ return 1; } else{ return 0; } } ... digits sum sequence: int main(){ int array[5]; digits_sum_sequence(5,array); for(int i= 0; i<5; i++){ printf("%d",array[i]); } printf("\n"); return 0; } void digits_sum_sequence(const int size, int array[]){ if(array == NULL || size == 0){ return 0; } array[0] = 1; int sum = 0; for(int i = 1; i<size; i++)]{ sum = sum + array[i-1]; array[i] = sum; } } ... Heslo: int main(){ printf("Zadaj pocet hesiel\n"); int p; scanf("%d",&p); for(int i= 0; i<p; i++){ char password[50]; scanf("%s",password); int jeden=0, dva=0, tri=0, nL=0; for(size_t index = 0; index < strlen(password); index++){ nL++; if(password[index] >= 'a' && password[index] <= 'z'){ jeden++; } else if(password[index] >= 'A' && password[index] <= 'Z'){ dva++; } else if(password[index] >= '0' && password[index] <= '9'){ tri++; } } if(jeden >= 1){ jeden = 1; } if(dva >= 1){ dva = 1; } if(tri >= 1){ tri = 1; } int s = jeden + dva + tri; if(s == 3){ printf("Strong password\n"); } else{ printf("Weak password\n"); } } return 0; } ... porovnanie dlzok slov: if(strlen(word1) > strlen(word2)){ return 1; } if(strlen(word1) < strlen(word2)){ return 2; } return 0; } ... spztka: if(spz == NULL){ return -1; } if(isupper(spz[0]) && isupper(spz[1]) && (spz[2] >= 0 || spz[2] <= 9) && (spz[3] >= 0 || spz[3] <= 9) && (spz[4] >= 0 || spz[4] <= 9) && isupper(spz[5]) && isupper(spz[6] )){ return 1; } return 0; } ... karel fallasleep: if(position == '-'){ return 1; } if(position == '|'){ return 0; } return -1; } ... find firstA: if(string == NULL){ return -1; } for(int i=0;i<strlen(string); i++){ if(string[i] == 'a' || string[i] == 'A'){ return i; } } return -1; } ... negative even: int negative_even(const int number){ if(number<0 && number&2==0){ return 1; } else{ return 0; } } ... fib2array: main(){ int array[20]; fib(20,array); for(int i=0; i<20; i++){ printf("%d\n",array[i]); } return 0; }
void fib(const int size, int array[]){ int n1 = 1, n2 = 2, num = 0; if(array == NULL){ return -1; } if(size==1){ array[0]=1; } if(size==2){ array[0]=1; array[1]=1; } if(size>=3){ array[0]=1; array[1]=1; for(int i=2; i<size; i++){ num= n1 + n2; array[i]=num; n2=n1; n1=num; } } } ... min2d: int min_2d(const int size, int array[][size]{ if(array == NULL){ return -1; } int min = array[0][0]; for(int i=0;i<size; i++){ for(int j=0;j<size; j++){ if(array[i][j] < (>max) min){ min = array[i][j]; } } } return min; } ... changearray: void sum(const int size, int array[]); int divide(int num); int main(){ int array[11]; sum(11,array); for(int n=0, n<11; n++){ printf("%d",arrat[n]); } return 0; } void sum(const int size, int array[]){ int sum=1; if(size <1 || array=NULL){ return; } array[0]=1; if(size>1){ array[1]=1; } if(size>2){ for(int i=2; i<size; ++i){ sum=sum+divide(sum); array[i]= sum; } } } int divide(int num){ int sum=0; while(num!=0){ sum = sum+num%10; num = num/10; } return sum; } } ... allpositive: int allpositive(cosnt int size, const int array[]); int main(){ const int array1[] = {1,2,0,-1,5}; const int array2[] = {4,6,2,11,7}; const int array3[] = {-5,-1,0,5,5}; printf("%d %d %d\n", allpositive(5,array1), allpositive(5,array2), allpositive(5,array3)); return 0; } int allpositive(const int size, const int array[]){ if(array == NULL){ return -1; } for(int i=0; i<size, i++){ if(array[i]<=0){ return 0; } } return 1; } } ...
|