# exercitii_ziua1

unknown
plain_text
2 years ago
2.1 kB
1
Indexable
Never
#include<stdio.h>
enum valori { alfa = 0, beta = 1, gama = 2, delta = 3, epsilon = 4 };
int Leds = 0xAB; //10101011

int ex_switch(int n); //exercitiu 3
int ex_elseif(int n); //exercitiu 3
int ex_factorialFor(int n); // exercitiu 4
int ex_factorialWhile(int n);
void printbits(int input);

#define MASK_LED2AND6_ON 0x44u // | 01000100
#define PRINT_BITS 7

int main()
{
int n = 0;
scanf_s("%d", &n);

//printf("%d", ex_switch(n));
//printf(" %d", ex_elseif(n));
//printf(" %d", ex_factorialFor(n));
//printf(" %d", ex_factorialWhile(n));

Leds |= MASK_LED2AND6_ON;    // set bit
Leds &= MASK_LED3AND4_OFF; // clear bit

//Leds |= 1 << x;    // set bit
//Leds &= ~(1 << x); // clear bit

printbits(Leds);
return 0;
}

int ex_switch(int n)
{
switch (n)
{
case alfa:
{
return (n + n);
break;
}
case beta:
{
return (n * n);
break;
}
case gama:
{
return (n * n);
break;
}
case delta:
{
return (n + n + n * n);
break;
}
case epsilon:
{
return (n + n * n * n);
break;
}
default:
{
//do nothing
}
}
}

int ex_elseif(int n)
{
if (n == alfa) {
return (n + n);
}
else if (n == beta) {
return (n * n);
}
else if (n == gama) {
return(n * n);
}
else if (n == delta) {
return (n + n + n * n);
}
else if (n == epsilon) {
return (n + n * n * n);
}
else {
//do nothing
}
}

int ex_factorialFor(int n)
{
int factorial = 1, i = 0;
for (i = 1; i <= n; i++)
{
factorial *= i;
}

return factorial;
}

int ex_factorialWhile(int n)
{
int factorial = 1;
while (n != 0)
{
factorial *= n;
n--;

}

return factorial;
}

void printbits(int input) {