Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]#include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <ctype.h>
- int sum_greater(const int a, const int b, const int c);
- int find_first_A(const char string[]);
- char last_letter(const char string[]);
- int min_2d(const int size, const int array[][size]);
- int is_vowel(const char c);
- int is_hex_digit(const char c);
- int last(const int size, const int array[]);
- int sum_positives(const int size, const int array[]);
- int count_zeroes_2d(const int size, int array[][size]);
- int n_fib(const int n);
- int longest_row(const int rows, const int cols, char array[rows][cols]);
- char last_special(const char string[]);
- int negative_even(const int number);
- void change_whites(char string[]);
- void sort_desc(int array[], const int size);
- int is_won(const char a, const char b, const char c);
- int direction_correction(const int degree);
- int sum_digits(const int n);
- int count_negative_evens(const int size, const int array[]);
- int is_in_array(const int num, const int size, const int array[]);
- int leap_year(const int year);
- void digits_sum_sequence(const int size, int array[]);
- void swap_sign_2d(const int size , int array[][size]);
- void swap_case_2d(const int rows,const int cols, char strings[][cols]);
- int vowels_count_2d(const int rows, const int cols, char strings[][cols]);
- int is_in_array_2d(const int num, const int size, int array[][size]);
- int binary_num(const int num);
- int is_special(const char c);
- int check_SPZ(const char spz[]);
- void fib_2_array(const int size, int array[]);
- void string_to_upper(char string[]);
- int karel_asleep(const char position);
- int main(){
- printf("%d\n", sum_greater(-1, 3, -2));
- printf("%d\n", find_first_A("Tomorrow afternoon"));
- printf("%c %c\n", last_letter("Once upon a time...."), last_letter("$a_b_c_d_1_2_3_4$"));
- int array[2][2] = { {1, 2}, {0, -3} };
- printf("%d\n", min_2d(2, array));
- printf("%d %d %d\n", is_vowel('b'), is_vowel('A'), is_vowel('a'));
- printf("%d %d\n", is_hex_digit('a'), is_hex_digit('F'));
- printf("%d %d\n", is_hex_digit('h'), is_hex_digit('3'));
- int arrayA[3] = {1,2,3};
- printf("%d\n", last(3, arrayA));
- int arrayB[] = {0,1,-2,3};
- printf("%d\n", sum_positives(4, arrayB));
- int arrayC[2][2] = { {1,2}, {0,0} };
- printf("%d\n", count_zeroes_2d(2, arrayC));
- printf("%d\n", n_fib(10));
- char arrayD[3][31] = {"Hello",
- "Hello, how are you?",
- "I hope today is a lucky day..."};
- printf("%d\n", longest_row(3,31,arrayD));
- printf("%c %c\n", last_special("Once upon a time....."), last_special("$a_b_c_d_1_2_3_4$"));
- printf("%d %d %d\n", negative_even(-10), negative_even(-11), negative_even(10));
- char str[] = "Hello world!";
- change_whites(str);
- printf("%s\n", str);
- int arrayE[5] ={10,20,50,30,40};
- sort_desc(arrayE, 5);
- for(int i = 0; i < 5; i++){
- printf("%d", arrayE[i]);
- }
- printf("%d %d\n", is_won('y', 'Y', 'y'), is_won('a', 'B', 'B'));
- printf("%d %d %d\n", direction_correction(-90), direction_correction(540), direction_correction(180));
- //printf("%d %d\n", sum_digits(0), sum_digits(15));
- return 0;
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- int sum_greater(const int a, const int b, const int c){
- if(a > c && a > b){
- return a + c;
- }
- else{
- return a + b;
- }
- if(b > a && b > c){
- return b + a;
- }
- else{
- return b + c;
- }
- if(c > a && c > b){
- return c + a;
- }
- else{
- return c + b;
- }
- }
- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- int find_first_A(const char string[]){
- if(string == NULL){
- return -1;
- }
- for(int i = 0; i < strlen(string); i++){
- if(string[i] == 'A' || string[i] == 'a'){
- return i;
- }
- }
- if(string != 'A' || string != 'a'){
- return -1;
- }
- }
- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- char last_letter(const char string[]){
- if(string == NULL){
- return '?';
- }
- char pos;
- for(int j = 0; j < strlen(string); j++){
- if(string[j] >= 'A' && string[j] <= 'Z' || string[j] >= 'a' && string[j] <= 'z'){
- pos = string[j];
- }
- }
- if((pos >= 'a' && pos <= 'z') ||(pos >= 'A' && pos <= 'Z')){
- return pos;
- }
- else{
- return '?';
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////
- int min_2d(const int size, const int array[][size]){
- int min ;
- if(min == NULL){
- return -1;
- }
- for(int i = 0; i < size; i++){
- for(int j = 0; j < size; j++){
- if(min > array[j][i])
- min = array[j][i];
- }
- }
- return min;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- int is_vowel(const char c){
- if(c == 'a' || c == 'i' || c == 'e' || c == 'o' || c == 'u'){
- return 1;
- }
- if(c == 'A' || c == 'I' || c == 'E' || c == 'O' || c == 'U'){
- return 1;
- }
- else{
- return 0;
- }
- }
- \\\\\\\\\\\\\\\\\\\\\\\\\\\\////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- int is_hex_digit(const char c){
- if(c >= 'A' && c <= 'F'){
- return 1;
- }
- if(c >= '0' && c <= '9'){
- return 1;
- }
- if(c >= 'a' && c <= 'f'){
- return 1;
- }
- return 0;
- }
- int last(const int size, const int array[]){
- int i;
- for(int i = 0; i < size; i++){
- if(i == ' ' || i == '.'){
- return i;
- }
- }
- }
- ///////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- int sum_positives(const int size, const int array[]){
- if(array == NULL){
- return -1;
- }
- int counter = 0;
- for(int i = 0; i < size; i++){
- if(array[i] >= 0){
- counter += array[i];
- }
- }
- return counter;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- int count_zeroes_2d(const int size, int array[][size]){
- if(array == NULL){
- return -1;
- }
- int counter = 0;
- for(int i = 0; i < size; i++){
- for(int j = 0; j < size; j++){
- if(array[i][j] == 0){
- counter++;
- }
- }
- }
- return counter;
- }
- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- int n_fib(const int n){
- int fib = 0;
- int fib1 = 0;
- int fib2 = 1;
- if(n < 1 || n > 575){
- return -1;
- }
- for(int i = 2; i <= n ; i++){
- fib= fib1 + fib2;
- fib1 = fib2;
- fib2 = fib;
- }
- return fib;
- }
- ////////////////////////////////////////////////////////////////////////////////////////
- int longest_row(const int rows, const int cols, char array[rows][cols]){
- int result = 0;
- int longest = 0;
- for(int y = 0; y < rows; y++){
- int len = strlen(array[y]);
- if(result < len){
- result = len;
- longest = y;
- }
- }
- return longest;
- }
- ////////////////////////////////////////////////////////////////////////////////////////
- char last_special(const char string[]){
- if(string == NULL){
- return '?';
- }
- char pos;
- for(int i = 0; i < strlen(string); i++){
- if(string[i] != 'a' && string[i] != 'z' || string[i] != 'A' && string[i] != 'Z' ){
- pos = string[i];
- }
- if(string[i] != '0' && string[i] != '9'){
- pos = string[i];
- }
- }
- return pos;
- }
- ////////////////////////////////////////////////////////////////////////////////////////
- int negative_even(const int number){
- if(number % 2 == 0 && number < 0){
- return 1;
- }
- else{
- return 0;
- }
- }
- \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- void change_whites(char string[]){
- if(string == NULL){
- return;
- }
- for(int i = 0; i < strlen(string); i++){
- if(string[i] == ' ' || string[i] == '\n'){
- string[i] = '.';
- }
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////
- void sort_desc(int array[], const int size){
- if(array == NULL || size < 1){
- return;
- }
- int a;
- for(int i = 0; i < size; i++){
- for(int j = i; j < size; j++){
- if(array[i] < array[j]){
- a = array[i];
- array[i] = array[j];
- array[j] = a;
- }
- }
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////
- int is_won(const char a, const char b, const char c){
- char a1 = tolower(a);
- char b1 = tolower(b);
- char c1 = tolower(c);
- if((a1 == b1) && (b1 == c1) && (a1 == c1)){
- return 1;
- }
- else{
- return 0;
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- int direction_correction(const int degree){
- // int direct = degree;
- if(degree > 0 && degree < 360)
- return degree;
- else if(degree > 360)
- return degree - 360;
- else if(degree < 0)
- return -1;
- }
- ////////////////////////////////////////////////////////////////////////////////////////
- int count_negative_evens(const int size, const int array[]){
- if(array == NULL){
- return -1;
- }
- int counter = 0;
- for(int i = 0; i < size; i++){
- if(array[i] < 0 && array[i] % 2 == 0){
- counter ++;
- }
- }
- return counter;
- }
- ////////////////////////////////////////////////////////////////////////////////////////
- int is_in_array(const int num, const int size, const int array[]){
- if(array == NULL){
- return -1;
- }
- for(int i = 0; i < size; i++){
- if(num == array[i]){
- return 1;
- }
- }
- return 0;
- }
- ////////////////////////////////////////////////////////////////////////////////////////
- int leap_year(const int year){
- if(year < 1 || year > 4443){
- return -1;
- }
- if (year % 4 == 0) {
- if (year % 100 == 0) {
- if (year % 400 == 0)
- return 1;
- else
- return 0;
- } else
- return 1;
- } else
- return 0;
- }
- ///////////////////////////////////////////////////////////////////////////////////
- void digits_sum_sequence(const int size, int array[]){
- array[0] = 1;
- for(int i = 1; i < size; i++){
- int a = i-1;
- array[i] = 0;
- while (a >= 0){
- if(array[a] > 9){
- int cislo= array[a];
- int sum=0;
- while(cislo>0){
- sum+=cislo%10;
- cislo/=10;
- }
- array[i] += sum;
- }
- else array[i] += array[a];
- a--;
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void swap_sign_2d(const int size, int array[2][2]){
- if(array[size][size] == NULL){
- return;
- }
- for(int i = 0; i < size; i++){
- for(int j = 0; j < size; j++){
- if(array[j][i] > 0){
- array[j][i] = (-1)*array[j][i];
- }
- else if(array[j][i] < 0){
- array[j][i] = (-1)*array[j][i];
- }
- else if(array [j][i] == 0){
- array[j][i] = 0;
- }
- // array[j][i] = array[j][i] - 2*array[j][i];
- }
- }
- }
- /////////////////////////////////////////////////////////////////////
- void swap_case_2d(const int rows,const int cols, char strings[][cols]){
- int word = 0;
- for(int y = 0; y < rows; y++){
- for(int x = 0; x < cols; x++){
- if(islower(strings[y][x]))
- strings[y][x]=toupper(strings[y][x]);
- else if(isupper(strings[y][x]))
- strings[y][x]=tolower(strings[y][x]);
- }
- }
- }
- ////////////////////////////////////////////////////////////////////////
- int vowels_count_2d(const int rows, const int cols, char strings[][cols]){
- if(strings == NULL){
- return -1;
- }
- int counter = 0;
- for(int y = 0; y < rows; y++){
- for(int x = 0; x < cols; x++){
- if(strings[y][x] == 'a' || strings[y][x] == 'e' || strings[y][x] == 'i' || strings[y][x] == 'o' || strings[y][x] == 'u' || strings[y][x] == 'y'){
- counter = counter +1;
- }
- else if(strings[y][x] == 'A' || strings[y][x] == 'E' || strings[y][x] == 'I' || strings[y][x] == 'O' || strings[y][x] == 'U' || strings[y][x] == 'Y'){
- counter = counter+1;
- }
- }
- }
- return counter;
- }
- ////////////////////////////////////////////////////////////////////
- int is_in_array_2d(const int num, const int size, int array[][size]){
- for(int y = 0; y < size; y++){
- for(int x = 0;x < size; x++){
- if(array[y][x] == num){
- return 1;
- }
- }
- }
- return 0;
- }
- /////////////////////////////////////////////////////////////////////////////
- int count_whites(const char string[]){
- char text = string;
- int counter = 0;
- int index = 0;
- while(text[index] != '\0'){
- if(text[index] == NULL)
- return -1;
- else if(text[index] == ' ' || text[index] == '\t' || text[index] == '\n'){
- counter += 1;
- index++;
- }
- index++;
- // char str[] = "Geeks";
- }
- return counter;
- }
- /////////////////////////////////////////////////////////////////////////////////
- int binary_num(const int num){
- if(num == 1 || num == 0){
- return 1;
- }
- else if(num < -1000 || num > 1000 ){
- return -1;
- }
- else{
- return 0;
- }
- }
- /////////////////////////////////////////////////////////////////////////////////
- int is_special(const char c){
- if(c >= '0' && c <= '9'){
- return 0;
- }
- else if(c >= 'A' && c <= 'Z'){
- return 0;
- }
- else if(c >= 'a' && c <= 'z'){
- return 0;
- }
- return 1;
- }
- /////////////////////////////////////////////////////////////////////////
- int check_SPZ(const char spz[]){
- for(int i = 0; i < strlen(spz); i++){
- if(strlen(spz) != 7 || spz[0] > 'Z' || spz[0] < 'A' || spz[1] > 'Z' || spz[1] < 'A' ||
- spz[2] > '9' || spz[2] < '0'|| spz[3] > '9' || spz[3] < '0' || spz[4] > '9' || spz[4] < '0'
- || spz[5] > 'Z' || spz[5] < 'A' || spz[6] > 'Z' || spz[6] < 'A'){
- return 0;
- }
- }
- return 1;
- }
- ///////////////////////////////////////////////////////////////////////////////
- void fib_2_array(const int size, int array[]){
- if(array == NULL){
- return;
- }
- array[0] = 1;
- array[1] = 1;
- for(int i = 2; i < size; i++){
- array[i] = array[i - 2] + array [i - 1];
- }
- }
- ///////////////////////////////////////////////////////////////////////////////
- void string_to_upper(char string[]){
- int n=strlen(string);
- for(int i = 0; i < n; i++){
- if(islower(string[i])){
- string[i] = toupper(string[i]);
- }
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- int karel_asleep(const char position){
- if(position == '-'){
- return 1;
- }
- if(position == '|'){
- return 0;
- }
- return -1;
- }
- ////////////////////////////////////////////////////////////////////////////
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int n;
- scanf("%d", &n);
- int array[n];
- int pom;
- for(int i = 0; i < n; i++){
- scanf("%d",&pom);
- array[i] = pom;
- }
- for(int i = 0; i < n; i++){
- for(int j = i; j < n; j++){
- if(array[i] > array[j]){
- pom = array[i];
- array[i] = array[j];
- array[j] = pom;
- }
- }
- printf("Z:%d\n", array[i]);
- }
- if(n % 2 == 0){
- float median = ((float)array[(n - 1) / 2] + (float)array[n / 2]) / 2;
- printf("Median je: %f\n", median);
- }
- else{
- printf("Median je : %d\n", array[n/2]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement