Snippets Collections
#include<stdio.h>
typedef struct student{
    int roll;
    char name[100];
    int marks[3];
}st;
void takeinput(st candidate[]){
     for(int i=0;i<5;i++){
        printf("\nFor student %d\n",i+1);
        printf("Enter the following details\n");
        printf("roll:");
        scanf("%d",&candidate[i].roll);
        printf("name:");
        scanf("%s",candidate[i].name);
        for(int j=0;j<3;j++){
            printf("marks in subject %d:",j+1);
            scanf("%d",&candidate[i].marks[j]);
        }
     }
}
void printinput(st candidate[]){
    printf("The details of all the students are as follows\n");
    for(int i=0;i<5;i++){
        printf("\nroll no:%d\nname:%s\n",candidate[i].roll,candidate[i].name);
        for(int j=0;j<3;j++){
            printf("marks in subject %d:%d\n",j+1,candidate[i].marks[j]);
        }
    }
}
void average_st_mks(st candidate[]){
    printf("Enter the serial number(1-5) of the student whose average marks to be known\n");
    int no;
    scanf("%d",&no);
    int sum=0;
    for(int i=0;i<3;i++) sum+=candidate[no-1].marks[i];
    float avg=(float)sum/3;
    printf("The average marks candidate bearing roll:%d is %.2f\n",candidate[no-1].roll,avg);
}
void average_subj_mks(st candidates[]){
    printf("Enter the serial number(1-3) of the subject whose average is to be known\n");
    int subject_number;
    scanf("%d",&subject_number);
    int sum=0;
    for(int i=0;i<5;i++){
        sum+=candidates[i].marks[subject_number-1];
    }
    float avg=(float)sum/5;
    printf("The average score of students in subject no:%d is %.2f\n",subject_number,avg);
}
void swap(st *candidate){
    printf("Enter the serial number(1-5) of student whose subject marks are to be swapped\n");
    int i;
    scanf("%d",&i);
    printf("Enter the serial number(1-3) of two subjects whose marks to be swapped\n");
    int a,b;
    scanf("%d%d",&a,&b);
    int temp=candidate[i-1].marks[a-1];
    candidate[i-1].marks[a-1]=candidate[i-1].marks[b-1];
    candidate[i-1].marks[b-1]=temp;
}
void print_mks_student(st candidate[]){
    printf("Enter the serial number(1-5) of the student you want to print marks\n");
    int n;
    scanf("%d",&n);
    for(int i=0;i<3;i++){
        printf("subject %d: %d mks\n",i+1,candidate[n-1].marks[i]);
    }
}
void upp_to_low(st candidate[]){
    printf("Enter the serial number(1-5) of student you want to convert name to lowercase\n");
    int n;
    scanf("%d",&n);
    int i=0;
    do{
        char ch=candidate[n-1].name[i];
        if(ch>=65 && ch<=90) candidate[n-1].name[i]=ch+32;
        i++;
    }while(candidate[n-1].name[i]!='\0');
    printf("student name changed to %s\n",candidate[n-1].name);
}
int main(){
    st candidate[5];
    int flag=1;
    char choice;
    do{
        printf("\nEnter the choice from the menu as per mentioned in the question paper\n");
        printf("The choice should be between a-g(lowercase)\nEnter any other character to stop the program\n");
        scanf(" %c",&choice);
        switch(choice){
        case 'a':takeinput(candidate);
        break;
        case 'b':printinput(candidate); 
        break;
        case 'c':average_st_mks(candidate);
        break;
        case 'd':average_subj_mks(candidate);
        break;
        case 'e':swap(candidate);
        break;
        case 'f':print_mks_student(candidate);
        break;
        case 'g':upp_to_low(candidate);
        break;
        default: flag=0;
        }
    }while(flag==1);
    return 0;
}
class int_ptr_wrapper
{
public:
    int_ptr_wrapper(int value = 0) :
    mInt(new int(value))
    {}

    // note! needs copy-constructor and copy-assignment operator!

    ~int_ptr_wrapper()
    {
        delete mInt;
    }

private:
    int* mInt;
};
class Wrapper
{
 private:
  CLib *lib;

 public:
  Wrapper() { lib = lib_init(); } // Lib initialisieren
  ~Wrapper() { lib_cleanup(&init); } // Lib freigeben

  std::string DoSomething() 
  { 
    char *cstr = lib_get_str(); // String anfordern (malloc!)

    std::string s = str;  // in std::string kopieren

    lib_free_str(cstr); // String freigeben (free)

    return s; // std::string zurückgeben. Alles easy.
  }
};
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>

//1.
double opA(int, int,int);
double opB(int,int,int);
double opC(int,int,int);
double opD(int,int,int);

int main() {
	int x = 0, y = 0, z = 0;
	char op = '\0';
	double rez = 0.0;

	printf("Unesi tri broja:\t");
	scanf(" %d %d %d", &x, &y, &z);


	printf("Unesi slovo operacije:\t");
	scanf(" %c", &op);

	switch (op) {
	case 'a':
		rez = opA(x, y, z);
		break;
	case 'b':
		rez = opB(x, y, z);
		break;
	case 'c':
		rez = opC(x, y, z);
		break;
	case 'd':
		rez = opD(x, y, z);
		break;

	default:
		printf("Kriva operacija!\n");
		rez = -DBL_MAX;
	}
	if (rez != -DBL_MAX) {
		printf("Rezultat je %lf.\n", rez);

	}
}

double opA(int x, int y, int z) {
	return x+y+z;
}

double opB(int x, int y, int z) {
	return x * y * z;
}
double opC(int x, int y, int z) {
	if (y == 0) {
		return -DBL_MAX;
	}
	return (x / y) + z;
}
double opD(int x, int y, int z) {
	double temp = 0.0;
	if (y == 0) {
		printf("Y ne smije bit 0!\n");
		return -DBL_MAX;
	}
	temp=(x / y - z);
	if (temp < 0) {
		printf("Sadrzaj u korijenu ne smije bit manji od 0!\n");
		return -DBL_MAX;
	}
	return sqrt(temp);
}

//2.
int X = 0;
void funkcija(int);
int main() {
	int Y = 0;
	
	printf("Unesi X i Y!\n");
	scanf(" %d %d", &X, &Y);
	funkcija(Y);
	return 0;
}
void funkcija(int par) {
	printf("X = %d\t Y = %d\t", X, par);
}
//3.
int dohvatiFaktorijelu(int);

int main() {
	int x = 0;
	int fact = 0;
	
	printf("Unesi x!\n");
	scanf(" %d", &x);

	fact=dohvatiFaktorijelu(x);
	printf("Faktorijela broja %d je %lf.\n", x, fact);
	return 0;
}
int dohvatiFaktorijelu(int x) {
	double rez = 1;
	int i = 1;

	for (i = 2; i <= x; i++) {
		rez *= i;
	}
	return rez;
}
//4.
double dohvatiEuler(int, int);
double dohvatiFaktorijelu(int);

int main() {
	int numOfRep = 10;
	int x = 0;
	double euler = 0;
	
	printf("Unesi x:\t");
	scanf(" %d", &x);

	euler=dohvatiEuler(x, 5);
	printf("e(%d) = %lf\n", x, euler);

	euler = dohvatiEuler(x, 10);
	printf("e(%d) = %lf\n", x, euler);

	euler = dohvatiEuler(x, 50);
	printf("e(%d) = %lf\n", x, euler);

	printf("exp(%d) = %lf\n", x, exp(x));
	return 0;
}
double dohvatiEuler(int x, int numOfRep) {
	double rez = 0;
	int i = 0;

	for (i = 0; i <= numOfRep; i++) {
		rez += pow(x,i)/dohvatiFaktorijelu(i);
	}
	return rez;
}
double dohvatiFaktorijelu(int n) {
	int i = 0;
	double rez = 1;

	for (i = 2; i <= n; i++) {
		rez *= i;
	}
	return rez;
}
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#define MAT_SIZE 3
#define NAME_LEN 129
#define ARR_LEN 5

//1.
int main() {
	int A[MAT_SIZE][MAT_SIZE] = { 0 };
	int B[MAT_SIZE][MAT_SIZE] = { 0 };
	int i = 0, j = 0;

	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%dx%d:\t", i + 1, j + 1);
			scanf(" %d", &A[i][j]);
		}
	}

	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			B[i][j] = 5 * A[i][j];
		}
	}

	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%d ", B[i][j]);
		}
	}
	printf("\n");
}

//2.
int main() {
	int A[MAT_SIZE][MAT_SIZE] = { 0 };
	int B[MAT_SIZE][MAT_SIZE] = { 0 };
	int i = 0, j = 0;

	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%dx%d:\t", i + 1, j + 1);
			scanf(" %d", &A[i][j]);
		}
	}

	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			B[i][j] = 5 * A[j][i];
		}
	}

	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%d ", B[i][j]);
		}
	}
	printf("\n");
}
//3.
int main() {
	int A[MAT_SIZE][MAT_SIZE] = { 0 };
	int B[MAT_SIZE][MAT_SIZE] = { 0 };
	int C[MAT_SIZE][MAT_SIZE] = { 0 };
	int D[MAT_SIZE][MAT_SIZE] = { 0 };

	int i = 0, j = 0, temp = 0, x = 0;

	printf("Matrica A:\n");
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%dx%d:\t", i + 1, j + 1);
			scanf(" %d", &A[i][j]);
		}
	}
	printf("Matrica B:\n");
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%dx%d:\t", i + 1, j + 1);
			scanf(" %d", &B[i][j]);
		}
	}
	printf("Matrica C:\n");
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%d ", C[i][j]);
		}
	}
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			temp = 0;
			for (x = 0; x < MAT_SIZE; x++) {
				temp += (A[i][x] * B[x][j]);
			}
			D[i][j] = temp;
		}
	}

	printf("Matrica D:\n");
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%d ", D[i][j]);
		}
	}
	printf("\n");
}
//4.
int main() {
	char names[ARR_LEN][NAME_LEN] = { "\0" };
	int i = 0, j = 0, temp = 0, firstIndex = 0, lastIndex = 0;
	char first[NAME_LEN] = { "\0" };
	char last[NAME_LEN] = { "\0" };

	for (i = 0; i < ARR_LEN; i++) {
		printf("Unesi ime osobe broj %d:\t", i + 1);
		scanf(" %s", names[i]);
	}

	firstIndex = 0;
	strcpy(first, names[0]);
	for (i = 1; i < ARR_LEN; i++) {
		if (_strcmpi(first, names[i]) > 0) {
			firstIndex = i;
			strcpy(first, names[i]);
		}
	}
	lastIndex = 0;
	strcpy(last, names[0]);
	for (i = 1; i < ARR_LEN; i++) {
		if (_strcmpi(last, names[i]) < 0) {
			lastIndex = i;
			strcpy(last, names[i]);
		}
	}
	printf("Prva osoba po abecedi je na indexu %d, ime je %s.\n", firstIndex, first);
	printf("Zadnja osoba po abecedi je na indexu %d, ime je %s.\n", lastIndex, last);
	
	for (i = 0; i < ARR_LEN - 1; i++) {
		for (j = i + 1; j < ARR_LEN; j++) {
			if (_strcmpi(names[i], names[j]) > 0) {
				strcpy(temp, names[i]);
				strcpy(names[i], names[j]);
				strcpy(names[j], temp);
			}
		}
	}
	printf("Sortirana imena:\n");
	for (i = 0; i < ARR_LEN; i++) {
		printf("%s\n", names[i]);
	}
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#define STR_LEN 129
#define MAX_HEX_COUNT 30
#define _CRT_SECURE_NO_WARNINGS
#define MAT_SIZE 3

//1.
int main() {
	int A[MAT_SIZE][MAT_SIZE] = { 0 };
	int B[MAT_SIZE][MAT_SIZE] = { 0 };
	int i = 0, j = 0;

	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%dx%d:\t", i + 1, j + 1);
			scanf(" %d", &A[i][j]);
		}
	}
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			B[i][j] = 5 * A[i][j];
		}
	}
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%d ", B[i][j]);
		}
		printf("\n");
	}
}

//2.
int main() {
	int A[MAT_SIZE][MAT_SIZE] = { 0 };
	int B[MAT_SIZE][MAT_SIZE] = { 0 };
	int i = 0, j = 0;

	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%dx%d:\t", i + 1, j + 1);
			scanf(" %d", &A[i][j]);
		}
	}
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			B[i][j] = A[j][i];
		}
	}
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%d ", B[i][j]);
		}
		printf("\n");
	}
}

//3.
int main() {
	int A[MAT_SIZE][MAT_SIZE] = { 0 };
	int B[MAT_SIZE][MAT_SIZE] = { 0 };
	int C[MAT_SIZE][MAT_SIZE] = { 0 };
	int D[MAT_SIZE][MAT_SIZE] = { 0 };
	int i = 0, j = 0, temp=0, x=0;

	printf("Matrica A:\n");
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%dx%d:\t", i + 1, j + 1);
			scanf(" %d", &A[i][j]);
		}
	}
	printf("Matrica B:\n");
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%dx%d:\t", i + 1, j + 1);
			scanf(" %d", &B[i][j]);
		}
	}
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			C[i][j] = A[i][j] + B[i][j];
		}
	}
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			temp=0;
			for (x = 0; x < MAT_SIZE; x++) {
				temp += (A[i][x] * B[x][j]);
			}
			D[i][j] = temp;
		}
	}
	printf("Matrica D:\n");
	for (i = 0; i < MAT_SIZE; i++) {
		for (j = 0; j < MAT_SIZE; j++) {
			printf("%d ", D[i][j]);
		}
		printf("\n");
	}
}

//4.


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#define STR_LEN 129
#define MAX_HEX_COUNT 30
#define _CRT_SECURE_NO_WARNINGS

//1.
int main()
{
	char znak = '\0';

	printf("Unesi znak:\t\n ESC za prekid.\n");
		do {
			znak = _getche();
		} while (znak != 27);
}
//2.
int main()
{
	char original[STR_LEN] = "\0", copy[STR_LEN] = "\0";
	int i = 0, j=0;

	printf("Unesi tekst:\n");
	scanf(" %s", original);

	for (i = 0; i < strlen(original); i++) {
		if (!isdigit(original[i])) {
			copy[j] = original[i];
			j++;
		}
	}
	copy[j] = '\0';
	printf("%s", copy);
}
//3.
int main()
{
	char txt[STR_LEN] = "\0";
	int i = 0, j = 0;
	char upper = '\0';

	printf("Unesi tekst:\t");
	scanf(" %s", txt);
	//a)
	for (i = 0; i < strlen(txt); i++) {
		if (isalpha(txt[i])) {
			txt[j++] = txt[i];
		}
	}
	txt[j] = '\0';
	printf("Nakon prve operacije: %s\n", txt);
	//b
	j = 0;
	for (i = 0; i < strlen(txt); i++) {
		switch (toupper(txt[i])) {
		case 'A':
		case 'E':
		case 'I':
		case 'O':
		case 'U':
			break;
		default:
			txt[j++] = txt[i];
		}
	}
	txt[j] = '\0';
	printf("Nakon druge operacije: %s\n", txt);
//c
	for (i = 0; i < strlen(txt); i++) {
		if (isupper(txt[i])) {
			txt[i] = tolower(txt[i]);
		}
		else {
			txt[i] = toupper(txt[i]);
		}
	}
	printf("Nakon trece operacije: %s\n", txt);
}

//4.
int main() {
	int decVal = 0, i=0, temp=0;
	char revhexVal[MAX_HEX_COUNT] = "\0", hexMap[]="0123456789ABCDEF";

	printf("Unesi dekadski broj:\t");
	scanf(" %d", &decVal);

	while (decVal != 0) {
		revhexVal[i++] = hexMap[decVal % 16];
		decVal /= 16;
	}
	i--;
	printf("Hex broj:\n");
	while (i >= 0) {
		printf("%c\n", revhexVal[i--]);
	}
}
//1.
int main()
{
	int value[2] = { 0 };
	char op = '\0';
	double result = 0.0;
	
	printf("Unesi prvi broj:\n");
	scanf(" %d", &value[0]);
	printf("Unesi drugi broj:\n");
	scanf(" %d", &value[1]);
	printf("Odaberi operaciju:\n + -> zbrajanje\n - -> oduzimanje\n * -> mnozenje\n / -> dijeljenje\n");
	scanf(" %c", &op);
 
	switch (op) {
	case '+':
		result = value[0] + value[1];
		break;
	case '-':
		result = value[0] + value[1];
		break;
	case '*':
		result = value[0] * value[1];
		break;
	case '/':
		if (value[1] == 0) {
			printf("Nije moguce dijelit s nulom!\n");
			result = INT_MIN;
		}
		else {
			result = (double)value[0] / value[1];
		}
		break;
	default:
		printf("Pogresan unos!\n");
		result = INT_MIN;
	}
	printf("------------\n");
	printf("Izvrsena operacija: %c\n", op);
	printf("Konacan rezultat: %lf\n", result);
}
//2.
int main()
{
	int ocjene[20] = { 0 }, i = 0;
	int histogram[5] = { 0 };
 
	printf("Potrebno je unijeti 20 ocjena.\n");
	for (i = 0; i < 20; i++) {
		printf("Ocjena broj %d.\t", i + 1);
		scanf(" %d", &ocjene[i]);
		if (ocjene[i] < 1 || ocjene[i] > 5) {
			printf("Neispravan unos!\n");
			i--;
		}
	}
	for (i = 0; i < 20; i++) {
		histogram[ocjene[i] - 1]++;
	}
	printf("------------\n");
	for (i = 0; i < 5; i++) {
		printf("Broj ocjena %d: %d\n", i + 1, histogram[i]);
	}
}
//3.
int main()
{
	int niz[10] = { 0 };
	int i=0, j = 0;
	int min = 0, max = 0;
	int temp = 0;
 
	printf("Unesi 10 brojeva:\n");
	for (i = 0; i < 10; i++) {
		printf("Broj %d:\t", i + 1);
		scanf(" %d", &niz[i]);
	}
	min = niz[0];
	max = niz[0];
	for (i = 1; i < 10; i++) {
		if (niz[i] < min) {
			min = niz[i];
		}
		if (niz[i] > max) {
			max = niz[i];
		}
	}
	for (i = 0; i < 9; i++) {
		for (j = i + 1; j < 10; j++) {
			if (niz[i] > niz[j]) {
				temp = niz[i];
				niz[i] = niz[j];
				niz[j] = temp;
			}
		}
	}
	printf("--------------\n");
	printf("Minimalni broj: %d\n Maksimalni broj: %d\n", min, max);
	for (i = 1; i < 10; i++) {
		printf("%d\n", niz[i]);
	}
}
int main()
{
	int arr[5] = { 0 };
	int i = 0, j = 0, temp = 0;

	printf("Unesi 5 brojeva:\n");
	for (i = 0; i < 5; i++) {
		scanf(" %d", &arr[i]);
	}
	for (i = 0; i < 4; i++) {
		for (j = i + 1; j < 5; j++) {
			if (arr[i] > arr[j]) {
				temp = arr[i];
				arr[i] = arr[j];
				arr[j] = temp;
			}
		}
	}
	printf("------------\n");
	for (i = 0; i < 5; i++) {
		printf("%d\n", arr[i]);
	}
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define _CRT_SECURE_NO_WARNINGS

//1.
int main()
{
	float broj;
	printf("Unesite realan broj:\t");
	scanf("%f", &broj);

	if ((broj - (int)broj) >= 0.5)
		printf("%d", (int)broj + 1);
	else if ((broj - (int)broj) <= -0.5)
		printf("%d", (int)broj - 1);
	else
		printf("%d", int(broj));

}
//3.
int main()
{
	int broj, temp = 0;
	for (int i = 0; i < 10; i++)
	{
		printf("Unesi %d. broj.\n", i + 1);
		scanf("%d", &broj);
		printf("\n");
		if (broj % 3 == 0)
			temp++;
	}

	printf("%d unesena/ih brojeva djeljivo je s 3.\n", temp);
}
//4.
int main()
{
	char slovo; int br_H = 0, br_ms = 0;
	for (int i = 0; i < 10; i++)
	{
		printf("Unesi slovo:\t");
		scanf(" %c", &slovo);
		printf("\n");
		if (slovo == 'H')
			br_H++;
		if (slovo >= 'a' && slovo <= 'z')
			br_ms++;
	}

	printf("Slovo H uneseno je %d puta.\n", br_H);
	printf("Malo slovo uneseno je %d puta.\n", br_ms);
}
//5.
int main()
{
	int pass = 0, score = 0,cnt=0, i = 0; float avg = 0.0f;
	for (i = 0; i < 5; i++) {
		printf("Broj bodova:\t");
		scanf(" %d", &score);
		if (score < 0 || score > 100) {
			i--;
			continue;
		}
		if (score >= 50) {
			cnt++;
		}
		pass += score;
	}
		printf("Broj prolaznika: %d\n", cnt);
		avg = pass / 5.0f;
		printf("Prosjecan broj bodova: %f", avg);
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define _CRT_SECURE_NO_WARNINGS
//1.
int main() {
	int cnt = 0, sum = 0, num = 0; float aritm = 0.0;
 
	do {
		printf("Unesi broj\t");
		scanf("%d", &num);
		if (num == 0) {
			break;
		}
		cnt++;
		sum += num;
	} while (1);
	aritm = (float)sum / cnt;
	printf("Aritmeticka sredina je %f.\n", aritm);
}
//2.
int main()
{
	int br = 0, rem = 0;
	printf("Unesi broj:\t");
	scanf(" %d", &br);
	if (br < 0) {
		printf("- ");
		br *= -1;
	}
	do {
		rem = br % 10;
		printf("%d ", rem);
		br /= 10;
	} while (br != 0);
}
//3.
int main()
{
	int rnd = 0, guess = 0, cnt = 0;
 
	srand((unsigned)time(NULL));
	rnd = rand();
	do {
		printf("Unesi broj:\t");
		scanf(" %d", &guess);
		cnt++;
		if (guess < rnd) {
			printf("Random broj je veci od unesenog!\n");
		}
		else if (guess > rnd) {
			printf("Random broj je manji od unesenog!\n");
		}
 
	} while (rnd != guess);
	printf("BINGO!\n");
	printf("Potrebno je bilo %d pokusaja.\n", cnt);
}

//4.
int main()
{
	int temp;
	for (int i = 1; i <= 100; i++)
	{
		temp = 1;
		for (int j = 2; j < i; j++)
		{
			if ((i % j) == 0)
				temp = 0;
		}
		if (temp)
			printf("%d ", i);
	}
}
#include <stdio.h>

int main(){
  char str[20];
  
  fgets(str, 20, stdin); // read from stdin
  puts(str); // print read content out to stdout
  
  // open the file
  FILE *f = fopen("file.txt" , "r"); 
  
  // if there was an error
  if(f == NULL){
    perror("Error opening file"); // print error
    return(-1); 
  }
  // if there was no error
  else{ 
    fgets(str, 20, f); // read from file
    puts(str); // print read content out to stdout
  }
  
  fclose(f); // close file
  
  return(0);
}
#include "SevSeg.h"
SevSeg sevseg;

int LEDRa = 33;
int LEDGa = 32;

int LEDRb = 23;
int LEDGb = 22;

int LEDRc = 50;
int LEDGc = 51;

int LEDRd = 42;
int LEDGd = 43;

int IRa1 = 44;
int IRa2 = 52;

int IRb1 = 49;
int IRb2 = 48;

int IRc1 = 35;
int IRc2 = 37;

int IRd1 = 47;
int IRd2 = 46;

int RoadATraffic[] = {0, 0};
int RoadBTraffic[] = {0, 0};
int RoadCTraffic[] = {0, 0};
int RoadDTraffic[] = {0, 0};

char jam[] = {'a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', 'a', 'b', 'c', 'd'};

void setup() {
  pinMode (LEDRa, OUTPUT);
  pinMode (LEDGa, OUTPUT);

  pinMode (LEDRb, OUTPUT);
  pinMode (LEDGb, OUTPUT);

  pinMode (LEDRc, OUTPUT);
  pinMode (LEDGc, OUTPUT);

  pinMode (LEDRd, OUTPUT);
  pinMode (LEDGd, OUTPUT);

  pinMode (IRa1, INPUT);
  pinMode (IRa2, INPUT);

  pinMode (IRb1, INPUT);
  pinMode (IRb2, INPUT);

  pinMode (IRc1, INPUT);
  pinMode (IRc2, INPUT);

  pinMode (IRd1, INPUT);
  pinMode (IRd2, INPUT);

  byte numDigits = 2;
  byte digitPins[] = {11, 10};
  byte segmentPins[] = {9, 8, 6, 3, 4, 7, 2, 5};
  bool resistorsOnSegments = true;

  byte hardwareConfig = COMMON_CATHODE;
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
  sevseg.setBrightness(90);

  Serial.begin(9600); // open the serial port at 9600 bps:
}

static int counter = 5;
int jam_ind = 0;
int current_route = 0;

void loop() {
    //display();
    RoadATraffic[0] = (digitalRead (IRa1) != 1) ? ( 1 ) : ( 0 );
    RoadATraffic[1] = (digitalRead (IRa2) != 1) ? ( 1 ) : ( 0 );

    RoadBTraffic[0] = (digitalRead (IRb1) != 1) ? ( 1 ) : ( 0 );
    RoadBTraffic[1] = (digitalRead (IRb2) != 1) ? ( 1 ) : ( 0 );

    RoadCTraffic[0] = (digitalRead (IRc1) != 1) ? ( 1 ) : ( 0 );
    RoadCTraffic[1] = (digitalRead (IRc2) != 1) ? ( 1 ) : ( 0 );

    RoadDTraffic[0] = (digitalRead (IRd1) != 1) ? ( 1 ) : ( 0 );
    RoadDTraffic[1] = (digitalRead (IRd2) != 1) ? ( 1 ) : ( 0 );

    int sum1 = RoadATraffic[0] + RoadATraffic[1];
    int sum2 = RoadBTraffic[0] + RoadBTraffic[1];
    int sum3 = RoadCTraffic[0] + RoadCTraffic[1];
    int sum4 = RoadDTraffic[0] + RoadDTraffic[1];

    Serial.print(current_route);
    Serial.print('\n');
    Serial.print(jam_ind);
    Serial.print('\n');
    Serial.print('\n');

    change_route(jam[current_route]);
    display();
      
    if (sum1 >= sum2 && sum1 >= sum3 && sum1 >= sum4) {     // Road A Jam
      if (jam[current_route] == 'a' && counter == 1) {
        increase_jam_ind();
        jam[jam_ind] = 'a';
      } else if (jam[current_route] != 'a' && jam[jam_ind] != 'a') {
        increase_jam_ind();
        jam[jam_ind] = 'a';
      }
    }

    if (sum2 >= sum1 && sum2 >= sum3 && sum2 >= sum4) { // Road B Jam
      if (jam[current_route] == 'b' && counter == 1) {
        increase_jam_ind();
        jam[jam_ind] = 'b';
      } else if (jam[current_route] != 'b' && jam[jam_ind] != 'b') {
        increase_jam_ind();
        jam[jam_ind] = 'b';
      }
    }
    
    if (sum3 >= sum1 && sum3 >= sum2 && sum3 >= sum4) { // Road C Jam
      if (jam[current_route] == 'c' && counter == 1) {
        increase_jam_ind();
        jam[jam_ind] = 'c';
      } else if (jam[current_route] != 'c' && jam[jam_ind] != 'c') {
        increase_jam_ind();
        jam[jam_ind] = 'c';
      }
    }
      
    if (sum4 >= sum1 && sum4 >= sum2 && sum4 >= sum3) { // Road D Jam
      if (jam[current_route] == 'd' && counter == 1) {
        increase_jam_ind();
        jam[jam_ind] = 'd';
      } else if (jam[current_route] != 'd' && jam[jam_ind] != 'd') {
        increase_jam_ind();
        jam[jam_ind] = 'd';
      }
    }  
}

void display() {
  for (int h = 1; h<10000; h++){
    sevseg.setNumber(counter);
    sevseg.refreshDisplay();  
  }
  if (counter <= 0) {
    counter = 5;
    current_route++;
  }

  if (current_route > 15) { 
    current_route = 0;
  }
  
  counter--;
}

void change_route(char route) {
  switch (route) {
    case 'a':
      digitalWrite(LEDGa, HIGH);
      digitalWrite(LEDRa, LOW);
    
      digitalWrite(LEDGb, LOW);
      digitalWrite(LEDRb, HIGH);
    
      digitalWrite(LEDGc, LOW);
      digitalWrite(LEDRc, HIGH);
    
      digitalWrite(LEDGd, LOW);
      digitalWrite(LEDRd, HIGH);
      break;

    case 'b':
      digitalWrite(LEDGa, LOW);
      digitalWrite(LEDRa, HIGH);
    
      digitalWrite(LEDGb, HIGH);
      digitalWrite(LEDRb, LOW);
    
      digitalWrite(LEDGc, LOW);
      digitalWrite(LEDRc, HIGH);
    
      digitalWrite(LEDGd, LOW);
      digitalWrite(LEDRd, HIGH);
      break;

    case 'c':
      digitalWrite(LEDGa, LOW);
      digitalWrite(LEDRa, HIGH);
    
      digitalWrite(LEDGb, LOW);
      digitalWrite(LEDRb, HIGH);
    
      digitalWrite(LEDGc, HIGH);
      digitalWrite(LEDRc, LOW);
    
      digitalWrite(LEDGd, LOW);
      digitalWrite(LEDRd, HIGH);
      break;

    case 'd':
      digitalWrite(LEDGa, LOW);
      digitalWrite(LEDRa, HIGH);
    
      digitalWrite(LEDGb, LOW);
      digitalWrite(LEDRb, HIGH);
    
      digitalWrite(LEDGc, LOW);
      digitalWrite(LEDRc, HIGH);
    
      digitalWrite(LEDGd, HIGH);
      digitalWrite(LEDRd, LOW);
      break;
  }
}

void increase_jam_ind() {
  jam_ind++;
  if (jam_ind > 15) {
    jam_ind = 0;
  }
}
#include <linux/limits.h>

char current_path[PATH_MAX];
star

Sat Jul 24 2021 11:05:40 GMT+0000 (UTC)

#c
star

Wed May 26 2021 22:05:48 GMT+0000 (UTC) https://stackoverflow.com/questions/5307169/what-is-the-meaning-of-a-c-wrapper-class

#c #c++ #wrapper
star

Wed May 26 2021 20:58:04 GMT+0000 (UTC) https://www.c-plusplus.net/forum/topic/270976/was-ist-ein-wrapper

#c #c++ #wrapper
star

Mon May 17 2021 13:41:09 GMT+0000 (UTC)

#c
star

Tue May 11 2021 15:22:29 GMT+0000 (UTC)

#c
star

Fri Apr 23 2021 10:47:55 GMT+0000 (UTC)

#c
star

Thu Apr 15 2021 18:12:30 GMT+0000 (UTC)

#c
star

Sun Apr 11 2021 18:16:25 GMT+0000 (UTC)

#c
star

Sun Apr 11 2021 15:56:01 GMT+0000 (UTC) https://www.tutorialspoint.com/data_structures_algorithms/bubble_sort_algorithm.htm

#c
star

Sun Apr 11 2021 15:52:44 GMT+0000 (UTC)

#c
star

Sun Apr 11 2021 15:46:46 GMT+0000 (UTC)

#c
star

Wed Dec 09 2020 05:39:08 GMT+0000 (UTC) https://rud.is/b/2020/02/06/prying-r-script-files-away-from-xcode-et-al-on-macos/

#c
star

Sun Oct 04 2020 21:07:26 GMT+0000 (UTC) https://www.educative.io/edpresso/how-to-use-the-fgets-function-in-c

#c
star

Sun Sep 27 2020 09:35:30 GMT+0000 (UTC)

#c
star

Wed Jun 24 2020 08:57:25 GMT+0000 (UTC) https://stackoverflow.com/questions/9449241/where-is-path-max-defined-in-linux

#c

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension