Last active
July 1, 2021 18:49
-
-
Save pizycki/5cb6aabcba59ef3f81fcd9517ccbed98 to your computer and use it in GitHub Desktop.
Kolo 2 Tiarek
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <math.h> | |
#include <stdio.h> | |
double a(int n) | |
{ | |
return (n * (pow(n, 2) - 25.5)) / (2 * n + 1.5); | |
} | |
int main() | |
{ | |
double a_n; | |
int m = 10; | |
int lessThanZero = 0; | |
for(int n = 1; n <= m; n++) | |
{ | |
a_n = a(n); | |
if(a_n < 0) | |
{ | |
lessThanZero++; | |
} | |
printf("n: %d,\ta_n: %f\n", n, a_n); | |
} | |
printf("Ilosc wyrazow ciagu an mniejszych od 0 to: %d", lessThanZero); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#define N 10 | |
int rnd(int lower, int upper) { | |
return (rand() % (upper - lower + 1)) + lower; | |
} | |
void print_arr(int arr[]){ | |
for(int i = 0; i < N; i++) | |
{ | |
printf("%d ", arr[i]); | |
} | |
} | |
int main() | |
{ | |
int arr[N]; | |
srand(time(0)); | |
// ------------------- | |
printf("\nGlowny Podpunkt\n"); | |
for(int i = 0; i < N; i++) | |
{ | |
arr[i] = 2*i+2; | |
} | |
print_arr(arr); | |
// ------------------- | |
printf("\nPodpunkt 1)\n"); | |
for(int i = 0; i < N; i++) | |
{ | |
arr[i] = rnd(-4, 4); | |
} | |
print_arr(arr); | |
// ------------------- | |
printf("\nPodpunkt 2)\n"); | |
int g = 0; | |
int l = 0; | |
// ------------------- | |
for(int i = 0; i < N; i++) | |
if(arr[i] > 0) | |
g += arr[i]; | |
else if(arr[i] < 0) | |
l += arr[i]; | |
else | |
continue; | |
printf("\nSuma liczb w tablicy wiekszych od 0 to: %d\n", g); | |
printf("\nSuma liczb w tablicy mniejszych od 0 to: %d\n", l); | |
// ------------------- | |
printf("\nPodpunkt 3)\n"); | |
printf("\nParzyste i nieparzyste liczby w tablicy to:\n"); | |
for(int i = 0; i < N; i++) | |
if(arr[i] % 2 == 0) | |
printf("%d ", arr[i]); | |
printf("\n"); | |
for(int i = 0; i < N; i++) | |
if(arr[i] % 2 != 0) | |
printf("%d ", arr[i]); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdbool.h> | |
#define N 100 | |
int main() | |
{ | |
int inputs[N]; // wprowadzone liczby | |
int n; // zaakceptowana liczba | |
int inputsCount = 0; | |
do | |
{ | |
printf("Podaj liczbe n gdzie 2 <= n <=4:\n"); | |
scanf("%i", &n); | |
inputs[inputsCount] = n; | |
inputsCount++; | |
} while(!(n >= 2 && n <= 4)); | |
printf("Twoja liczba to %d", n); | |
// ------------------- | |
printf("\nPodpunkt 1)\n"); | |
int a; | |
int counter = 0; | |
for(int i = 0; i < inputsCount; i++) | |
{ | |
a = inputs[i]; | |
if (abs(a) == n) | |
{ | |
counter++; | |
} | |
} | |
printf("Ilosc wprowadzonych liczb rownych -%d lub %d to: %d", n, n, counter); | |
// ------------------- | |
printf("\nPodpunkt 2)\n"); | |
for(int i = 0; i <= inputsCount; i++) | |
{ | |
if (i % 2 == 0) | |
{ | |
inputs[i] = inputs[i] * 2; | |
} | |
else | |
{ | |
inputs[i] = inputs[i] * 3; | |
} | |
} | |
printf("\nWprowadzone liczby po dwukrotnym lub trzykrotnym zwiekszeniu:\n"); | |
for(int i = 0; i < inputsCount; i++) | |
printf("%d ", inputs[i]); | |
// ------------------- | |
printf("\nPodpunkt 3)\n"); | |
int uniqueInputs[inputsCount]; | |
int uniqueInputsCount = 0; | |
for(int i = 0; i < inputsCount; i++) | |
{ | |
a = inputs[i]; | |
if(a >= -4 || a <= 4) | |
{ | |
if(uniqueInputsCount == 0) | |
{ | |
uniqueInputs[i] = a; | |
} | |
else | |
{ | |
bool unique = true; | |
int b; | |
for(int j = 0; j < uniqueInputsCount; j++) | |
{ | |
b = uniqueInputs[j]; | |
if(b == a) | |
{ | |
unique = false; | |
} | |
} | |
if(unique) | |
{ | |
uniqueInputs[i] = a; | |
} | |
} | |
uniqueInputsCount++; | |
} | |
} | |
for(int i = 0; i < uniqueInputsCount; i++) | |
printf("%d ", uniqueInputs[i]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment