Skip to content

Instantly share code, notes, and snippets.

@hjnowakowski
Last active March 26, 2017 20:48
Show Gist options
  • Save hjnowakowski/dda1293931cb5cba3b79a4fa0a38bd18 to your computer and use it in GitHub Desktop.
Save hjnowakowski/dda1293931cb5cba3b79a4fa0a38bd18 to your computer and use it in GitHub Desktop.
Zadania dla Weroniki
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//Zadanie dla Weroniki Kołodziej
//Henryk Nowakowski
int main( void )
{
int matrix[9][9], matrix2[9][9];
int sum;
int current_row; // żeby wiedzieć od które momentu dodawać w+k(wiersz + kolumna)
int current_col; //
srandom( (unsigned) time(NULL) );
//W każdej komórce losowe [1, 5]
//jak suma komórek > 25 resztę wypełni nr kolumny+wiersza
for (int i = 0; i < 9; i++) {
for(int j = 0; j < 9; j++)
{
matrix[i][j]=random()%5;
sum += matrix[i][j]; //sumowanie wylosowanych liczb
if(sum >= 25){
current_row = i; //zapisanie miejsca, w którym zmienna sum wynosiła już 25 lub więcej
current_col = j;
break;
}
}
if(sum >= 25)
break;
}
printf("\n\nMiejce, w ktorym zsumowane komórki >= 25 to wiersz %d i kolumna %d\n\n", current_row, current_col);
/*
1. Niżej przedstawione pętle nie mają zdeklarowanej zmiennej, bo zostało to już
zrobione
2. Po wykonaniu pętli, current_col zostaje wyzerowana, żeby mogła się wykonać
dla kolejnych wierszy
*/
if(sum >= 25)
{
for( ;current_row < 9;current_row++) {
for( ;current_col < 9; current_col++)
{
matrix[current_row][current_col] = current_row+current_col;
}
current_col=0;
}
}
//WYPISYWANIE TABLICY OK -----------------
for (int i = 0; i < 9; i++) {
for(int j = 0; j<9; j++)
{
printf("%d, ", matrix[i][j]);
}
printf("\n");
}
//----------------------------------------
return ( 0 ) ;
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main( void )
{
int i = 0;
int a[11];
a[0] = 0;
int min = a[0];
int max = a[0];
double avrg;
srandom( (unsigned) time(NULL) );
for (i=0;i<11;i++)
{
a[i]=random( ) % 10+(-5) ;
printf("%d. %d\n",i, a[i]);
if (a[i] > max)
{
max = a[i];
}
else if (a[i] < min)
{
min = a[i];
}
}
printf("Min: %d\n", min);
printf("Max: %d\n", max);
for (i = 0; i < 11; i++) {
avrg += a[i];
}
printf("\n\nSrednia bez podzielenia %lf", avrg);
printf("\n\nSrednia: %lf \n", avrg/11);
for (i = 0; i < 11; i++) {
if(a[i]>(avrg/11))
printf("%d\n", a[i]);
}
return ( 0 ) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment