Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

New Homework #884

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions 2015-2016/G/07/02/task1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>

void minmax(int *, int, int *, int *);

int main()
{
int arr[500], size, min, max, counter;
int sum;

scanf("%d", &size);
if(size > 0 && size < 500){
for(counter = 0; counter < size; counter++){
scanf("%d", &arr[counter]);
}
}

minmax (arr, size, &min, &max);

sum = max + min;

printf("%d\n", sum);

return 0;
}

void minmax(int *arr, int size, int *min, int *max)
{
int i;

for(i = 0; i < size; i++){
if(arr[i] > *max){
*max = arr[i];
}
if(arr[i] < *min){
*min = arr[i];
}
}
}
37 changes: 37 additions & 0 deletions 2015-2016/G/07/02/task2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdio.h>
#include <string.h>

char* find(char *, char);

int main()
{
char haystack[400], needle;
char *i = 0;

scanf("%[^\n]s",haystack);
getchar();
scanf("%c",&needle);

if(find(haystack ,needle) == NULL){
printf("-1\n");
}
else{
i = find(haystack ,needle);
printf("%d\n",(int)(i - haystack));
}

return 0;
}

char* find(char *haystack, char needle)
{
int counter = 0;

while(haystack[counter] != '\0'){
if(haystack[counter] == needle){
return &haystack[counter];
}
counter ++;
}
return NULL;
}
33 changes: 33 additions & 0 deletions 2015-2016/G/07/Homework-08/task2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main()
{
int i;
int sum = 0;
char msg[200];
int box ;
scanf("%[^\n]s", msg);
box = strlen(msg);
for (i = 0; i < box; i++)
{
if(msg[i] == 'a'||msg[i] == 'd'||msg[i] == 'g'||msg[i] == 'j'||msg[i] == 'm'||msg[i] == 'p'||msg[i] == 't'||msg[i] == 'w'||msg[i] == ' '){
sum = sum + 1;
}
if(msg[i] == 'b'||msg[i] == 'e'||msg[i] == 'h'||msg[i] == 'k'||msg[i] == 'n'||msg[i] == 'q'||msg[i] == 'u'||msg[i] == 'x'){
sum = sum + 2;
}
if(msg[i] == 'c'||msg[i] == 'f'||msg[i] == 'i'||msg[i] == 'l'||msg[i] == 'o'||msg[i] == 'r'||msg[i] == 'v'||msg[i] == 'y'){
sum = sum + 3;
}
if (msg[i] == 'z'||msg[i] == 's')
{
sum = sum + 4;
}
}

printf("%d", sum);
return 0;
}
38 changes: 38 additions & 0 deletions 2015-2016/G/07/Homework-08/task3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>

int main()
{
int raindeers, i, a, j;
int num[200];

printf("Incert the number of the raindeers.\n");
scanf("%d",&raindeers);
while(raindeers % 2 == 0){
printf("Incert correct number of raindeers.\n");
scanf("%d",&raindeers);
}
for (i = 0; i < raindeers; ++i)
{
scanf("%d",&num[i]);
}

for (i = 0; i < raindeers; ++i)
{
for (j = 0; j < raindeers; ++j)
{
if(num[i] == num[j]){
a = 1;
}
else{
a = 0;
}
}
if(a == 0){
printf("%d\n", num[i]);
break;
}
}

return 0;
}

34 changes: 34 additions & 0 deletions 2015-2016/G/07/Homework-09/task1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdio.h>

int main()
{
int a, b, i, helper[32];
scanf("%d", &a);
scanf("%d", &b);

for(i = 1; i > 0;){
if(a < 0 || a > 7)
{
printf("enter a valid a\n");
scanf("%d", &a);
}
}
for(i = 1; i > 0;){
if(b < 0 || b > 200)
{
printf("enter a valid b\n");
scanf("%d", &b);
}
}

for(i = 32; i != 0 ; i--)
{
helper[i] = b % 2;
b /= 2;
}

printf("%d\n", helper[a]);

return 0;
}

44 changes: 44 additions & 0 deletions 2015-2016/G/07/Homework-09/task2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <stdio.h>

int main()
{
int n, v, p, i, help[32], sum, j, a;
scanf("%d", &n);
scanf("%d", &v);
for(i = 1; i > 0;){
if(v != 0 && v != 1)
{
printf("enter a valid V\n");
scanf("%d", &v);
}
}
scanf("%d", &p);
for(i = 1; i > 0;){
if(p < 0 || p > 7)
{
printf("enter a valid P\n");
scanf("%d", &p);
}
}
for(i = 32; i != 0 ; i--)
{
help[i] = n % 2;
n /= 2;
}
help[p] = v;
sum = 0;
j = 32;
for (i = 32; i < 0; --i)
{
a = 1;
while(j > i)
{
a = 2 * a;
j--;
}
sum = a * help[i] + sum;
}
printf("%d\n", sum);

return 0;
}
33 changes: 33 additions & 0 deletions 2015-2016/G/07/big_homework/task2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main()
{
int i;
int sum = 0;
char msg[200];
int box ;
scanf("%[^\n]s", msg);
box = strlen(msg);
for (i = 0; i < box; i++)
{
if(msg[i] == 'a'||msg[i] == 'd'||msg[i] == 'g'||msg[i] == 'j'||msg[i] == 'm'||msg[i] == 'p'||msg[i] == 't'||msg[i] == 'w'||msg[i] == ' '){
sum = sum + 1;
}
if(msg[i] == 'b'||msg[i] == 'e'||msg[i] == 'h'||msg[i] == 'k'||msg[i] == 'n'||msg[i] == 'q'||msg[i] == 'u'||msg[i] == 'x'){
sum = sum + 2;
}
if(msg[i] == 'c'||msg[i] == 'f'||msg[i] == 'i'||msg[i] == 'l'||msg[i] == 'o'||msg[i] == 'r'||msg[i] == 'v'||msg[i] == 'y'){
sum = sum + 3;
}
if (msg[i] == 'z'||msg[i] == 's')
{
sum = sum + 4;
}
}

printf("%d", sum);
return 0;
}
38 changes: 38 additions & 0 deletions 2015-2016/G/07/big_homework/task3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdio.h>

int main()
{
int raindeers, i, a, j;
int num[200];

printf("Incert the number of the raindeers.\n");
scanf("%d",&raindeers);
while(raindeers % 2 == 0){
printf("Incert correct number of raindeers.\n");
scanf("%d",&raindeers);
}
for (i = 0; i < raindeers; ++i)
{
scanf("%d",&num[i]);
}

for (i = 0; i < raindeers; ++i)
{
for (j = 0; j < raindeers; ++j)
{
if(num[i] == num[j]){
a = 1;
}
else{
a = 0;
}
}
if(a == 0){
printf("%d\n", num[i]);
break;
}
}

return 0;
}