Snippets Collections
#include<stdio.h>
//Author : Khadiza Sultana
void dectohex(int n){
    if(n == 0) return;
    dectohex(n / 16);
    int rem = n % 16;
    if(rem < 10) printf("%d", rem);
    else printf("%c", rem - 10 + 'A');
}
int main(){
    printf("Enter a number : ");
    scanf("%d", &num);
    printf("Hexadecimal representation of %d : ", num);
    dectohex(num);
    printf("\n");
    return 0;
}
// Author : Khadiza Sultana
#include<stdbool.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

#define NUM_SUITS 4
#define NUM_RANKS 13

int main(){
    bool in_hand[NUM_SUITS][NUM_RANKS] = {false};
    int num_cards, rank, suit;
    const char rank_code[] = {'2', '3', '4', '5', '6', '7', '8', '9', 't', 'j', 'q', 'k', 'a'};
    const char suit_code[] = {'c', 'd', 'h', 's'};
    srand((unsigned) time(NULL));
    printf("Enter number of cards in hand : ");
    scanf("%d", &num_cards);
    printf("Your hand : ");
    while(num_cards > 0){
        suit = rand() % NUM_SUITS;
        rank = rand() % NUM_RANKS;
        if(! in_hand[suit][rank]){
            in_hand[suit][rank] = true;
            num_cards--;
            printf("%c%c ", rank_code[rank], suit_code[suit]);
        }
    }
    printf("\n");
    return 0;
}
// Author : Khadiza Sultana
#include<stdio.h>
#include<stdbool.h>
int main(){
    bool digit_seen[10] = {false};
    int digit;
    long n;
    printf("Enter a number : ");
    scanf("%ld", &n);
    while(n > 0){
        digit = n % 10;
        if(digit_seen[digit])
           break;
        digit_seen[digit] = true;
        n /= 10;
    }
    if(n > 0){
        printf("Repeated digit \n");
    }
    else{
        printf("No repeated digit \n");
    }
    return 0;
}
#include<stdio.h>
int main(){
    // Author : Khadiza Sultana
    int n = 4;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < (i + 1); j++)
        printf("* ");
        for(int j = 0; j < 2 * (n - i - 1); j++)
        printf("  ");
        for(int j = 0; j < (i + 1); j++)
        printf("* ");
        printf("\n");
    }
    for(int i = 0; i < n; i++){
        for(int j = n; j > i; j--)
        printf("* ");
        for(int j = 0; j < 2 * i; j++)
        printf("  ");
        for(int j = n; j > i; j--)
        printf("* ");
        printf("\n");
    }
    return 0;
}
Task-6
Implement OBST using dynamic programming
Algorithm:
Algorithm OBST(p, q, n)
// Given n distinct identifiers a1 < a2 < ··· < an and probabilities
// p[i], 1 ≤ i ≤ n, and q[i], 0 ≤ i ≤ n, this algorithm computes
// the cost c[i, j] of optimal binary search tree for identifiers
// a_i, ..., a_j. It also computes r[i, j], the root of t[i, j].
// w[i, j] is the weight of t[i, j].
{
  for i := 0 to n do
  { 
    // Initialize.
    w[i, i] := q[i]; r[i, i] := 0; c[i, i] := 0.0;
    // Optimal trees with one node
    w[i, i + 1] := q[i] + q[i + 1] + p[i + 1];
    c[i, i + 1] := w[i, i + 1]; r[i, i + 1] := i + 1;
  }
  
  for m := 2 to n do // Find optimal trees with m nodes.
    for i := 0 to n - m do
    {
      j := i + m;
      w[i, j] := w[i, j - 1] + p[j] + q[j];
      c[i, j] := ∞; // Solve 5.12 using Knuth's result.
      k := Find(c, r, i, j);
      // A value of k in the range [r[i, j - 1], r[i + 1, j]] that minimizes c[i, k - 1] + c[k, j];
      c[i, j] := w[i, j] + c[i, k - 1] + c[k, j];
      r[i, j] := k;
    }
  write (c[0, n], w[0, n], r[0, n]);
}

Algorithm Find(c, r, i, j)
{
  min := ∞;
  for m := r[i, j - 1] to r[i + 1, j] do
    if (c[i, m - 1] + c[m, j] < min) then
    {
      min := c[i, m - 1] + c[m, j];
      l_i := m;
    }
  return l_i;
}

Program:
#include <stdio.h>
#define MAX 10
#define INF 300000

void main() {
    char ele[MAX][MAX];
    int w[MAX][MAX], c[MAX][MAX], r[MAX][MAX];
    int p[MAX], q[MAX];
    int temp, min, min1;
    int i, j, k, b, n;

    // Input number of elements
    printf("Enter the number of elements: ");
    scanf("%d", &n);

    // Input probabilities for elements p[i]
    for (i = 1; i <= n; i++) {
        printf("Enter the element P(%d): ", i);
        scanf("%d", &p[i]);
    }
    printf("\n");

    // Input probabilities for dummy keys q[i]
    for (i = 0; i <= n; i++) {
        printf("Enter the element q(%d): ", i);
        scanf("%d", &q[i]);
    }
    printf("\n");

    printf("W \t\t C \t\t R\n");

    // Initialization of w, c, and r matrices for single elements
    for (i = 0; i <= n; i++) {
        for (j = 0; j <= n; j++) {
            if (i == j) {
                w[i][i] = q[i];
                c[i][i] = 0;
                r[i][i] = 0;
                printf("w[%d][%d] : %d \t c[%d][%d]: %d \t r[%d][%d] : %d\n", i, j, w[i][j], i, j, c[i][j], i, j, r[i][j]);
            }
        }
    }
    printf("\n");

    // Fill w, c, and r matrices for ranges [i, j]
    for (b = 0; b < n; b++) {
        for (i = 0, j = b + 1; j <= n; i++, j++) {
            if (i != j && i < j) {
                // Calculate w[i][j]
                w[i][j] = w[i][j - 1] + p[j] + q[j];
                min = INF;

                // Find minimum cost and root for this subproblem
                for (k = i + 1; k <= j; k++) {
                    min1 = c[i][k - 1] + c[k][j] + w[i][j];
                    if (min > min1) {
                        min = min1;
                        temp = k;
                    }
                }

                // Store minimum cost and root for this range
                c[i][j] = min;
                r[i][j] = temp;
            }
            // Print w[i][j], c[i][j], and r[i][j]
            printf("w[%d][%d] : %d \t c[%d][%d]: %d \t r[%d][%d] : %d\n", i, j, w[i][j], i, j, c[i][j], i, j, r[i][j]);
        }
        printf("\n");
    }

    // Print minimum cost for the entire tree
    printf("Minimum cost: %d\n", c[0][n]);
}
Output:
/tmp/VsdNZE6fYV.o
Enter the number of elements: 4
Enter the element P(1): 3
Enter the element P(2): 3
Enter the element P(3): 1
Enter the element P(4): 1

Enter the element q(0): 2
Enter the element q(1): 3
Enter the element q(2): 1
Enter the element q(3): 1
Enter the element q(4): 1

W 		 C 		 R
w[0][0] : 2 	 c[0][0]: 0 	 r[0][0] : 0
w[1][1] : 3 	 c[1][1]: 0 	 r[1][1] : 0
w[2][2] : 1 	 c[2][2]: 0 	 r[2][2] : 0
w[3][3] : 1 	 c[3][3]: 0 	 r[3][3] : 0
w[4][4] : 1 	 c[4][4]: 0 	 r[4][4] : 0

w[0][1] : 8 	 c[0][1]: 8 	 r[0][1] : 1
w[1][2] : 7 	 c[1][2]: 7 	 r[1][2] : 2
w[2][3] : 3 	 c[2][3]: 3 	 r[2][3] : 3
w[3][4] : 3 	 c[3][4]: 3 	 r[3][4] : 4

w[0][2] : 12 	 c[0][2]: 19 	 r[0][2] : 1
w[1][3] : 9 	 c[1][3]: 12 	 r[1][3] : 2
w[2][4] : 5 	 c[2][4]: 8 	 r[2][4] : 3

w[0][3] : 14 	 c[0][3]: 25 	 r[0][3] : 2
w[1][4] : 11 	 c[1][4]: 19 	 r[1][4] : 2

w[0][4] : 16 	 c[0][4]: 32 	 r[0][4] : 2

Minimum cost: 32


=== Code Exited With Errors ===
Task-5
Implement Dijkstra's algorithm to compute the shortest path through a graph.
Algorithm:
Algorithm ShortestPaths(v, cost, dist, n)
// dist[j], 1 ≤ j ≤ n, is set to the length of the shortest
// path from vertex v to vertex j in a digraph G with n
// vertices. dist[v] is set to zero. G is represented by its
// cost adjacency matrix cost[1 : n, 1 : n].
{
  for i := 1 to n do
  { // Initialize S.
    S[i] := false; dist[i] := cost[v, i];
  }
  S[v] := true; dist[v] := 0.0; // Put v in S.
  for num := 2 to n − 1 do
  {
    // Determine n − 1 paths from v.
    Choose u from among those vertices not
    in S such that dist[u] is minimum;
    S[u] := true; // Put u in S.
    for (each w adjacent to u with S[w] = false) do
    // Update distances.
    if (dist[w] > dist[u] + cost[u, w]) then
      dist[w] := dist[u] + cost[u, w];
  }
}
Program:
#include <stdio.h> 
#include <limits.h>
#define M 8

int n;

void spath(int graph[n][n], int u) {
    int dist[M];
    int s[M] = {0};
    for (int i = 0; i < n; i++) {
        dist[i] = INT_MAX;
    }
    dist[u] = 0;
    for (int i = 0; i < n - 1; i++) {
        int v;
        int min = INT_MAX;
        for (int j = 0; j < n; j++) {
            if (dist[j] < min && s[j] == 0) {
                min = dist[j];
                v = j;
            }
        }
        s[v] = 1;
        for (int j = 0; j < n; j++) {
            if (graph[v][j] != 0 && s[j] == 0) {
                if (dist[j] > dist[v] + graph[v][j]) {
                    dist[j] = dist[v] + graph[v][j];
                }
            }
        }
    }
    for (int i = 0; i < n; i++) {
        printf("%d ", dist[i]);
    }
    printf("\n");
}

int main() {
    printf("Enter the number of vertices (up to %d): ", M);
    scanf("%d", &n);

    int graph[M][M];
    printf("Enter the adjacency matrix (use 0 for no direct path):\n");
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            scanf("%d", &graph[i][j]);
        }
    }

    int startNode;
    printf("Enter the starting node (0 to %d): ", n - 1);
    scanf("%d", &startNode);

    spath(graph, startNode);
    return 0;
}
Output:
/tmp/q6mNdkXwgB.o
Enter the number of vertices (up to 8): 8
Enter the adjacency matrix (use 0 for no direct path):
0 0 0 0 0 0 0 0
300 0 0 0 0 0 0 0
1000 800 0 0 0 0 0 0
0 0 1200 0 0 0 0 0
0 0 0 1500 0 250 0 0
0 0 0 1000 0 0 900 1400
0 0 0 0 0 0 0 1000
1700 0 0 0 0 0 0 0
Enter the starting node (0 to 7): 4
3350 3250 2450 1250 0 250 1150 1650 


=== Code Execution Successful ===
Task-4
Implement Fractional Knapsack Algorithm
Algorithm:
Algorithm Sort(p, w, n){
  int r[n], index[n];
  int p[n], w[n];
  
  for i := 1 to n
    r[i] := p[i] / w[i];
  
  for i := n to n do{
    j := i;
    for k := i + 1 to n do
      if (r[k] <= r[j]) then 
	j := k;
    if(j!-i){
     index[i] := j;
     t := r[i];
     r[i] := r[j];
     r[j] := t;
    }
  }
  
  for i := 1 to n
  {
    p[i] := p[index[i]];
    w[i] := w[index[i]];
  }
}
Program:
#include <stdio.h>

void knapsack(int n, float weight[], float profit[], float capacity) {
    float tp = 0;
    int i, u;
    u = capacity;
    for (i = 0; i < n; i++) {
        if (weight[i] > u)
            break;
        else {
            tp = tp + profit[i];
            u = u - weight[i];
        }
    }
    if (i < n)
        tp = tp + (u / weight[i] * profit[i]);
    printf("\nMaximum profit is:- %f", tp);
}

int main() {
    float weight[20], profit[20], capacity;
    int num, i, j;
    float ratio[20], temp;

    printf("\nEnter the no. of objects:- ");
    scanf("%d", &num);

    printf("\nEnter the wts and profits of each object:-\n");
    for (i = 0; i < num; i++) {
        scanf("%f %f", &weight[i], &profit[i]);
    }

    printf("\nEnter the capacity of knapsack:- ");
    scanf("%f", &capacity);

    // Calculate profit/weight ratio
    for (i = 0; i < num; i++) {
        ratio[i] = profit[i] / weight[i];
    }

    // Sort items by profit/weight ratio in descending order
    for (i = 0; i < num; i++) {
        for (j = i + 1; j < num; j++) {
            if (ratio[i] < ratio[j]) {
                // Swap ratios
                temp = ratio[j];
                ratio[j] = ratio[i];
                ratio[i] = temp;

                // Swap weights and profits to keep arrays aligned
                temp = weight[j];
                weight[j] = weight[i];
                weight[i] = temp;

                temp = profit[j];
                profit[j] = profit[i];
                profit[i] = temp;
            }
        }
    }

    knapsack(num, weight, profit, capacity);
    return 0;
}
Output:
Enter the no. of objects:- 5
Enter the wts and profits of each object:-
4 12
1 2
2 2
1 1
4 10
Enter the capacity of knapsack:- 15
Maximum profit is:- 17.333334

=== Code Execution Successful ===
Task-1
a) Implement Merge sort algorithm and plot its time complexity with reference to the size of the input.
Algorithm:
Algorithm MergeSort(low, high)
// a[low : high] is a global array to be sorted.
// Small(P) is true if there is only one element
// to sort. In this case the list is already sorted.
{
    if (low < high) then     // If there are more than one element
    {
        // Divide P into subproblems.
        // Find where to split the set.
        mid := ⌊(low + high) / 2⌋;
        // Solve the subproblems.
        MergeSort(low, mid);
        MergeSort(mid + 1, high);
        // Combine the solutions.
        Merge(low, mid, high);
    }
}
Algorithm Merge(low, mid, high)
// a[low : high] is a global array containing two sorted
// subsets in a[low : mid] and in a[mid + 1 : high]. The goal
// is to merge these two sets into a single set residing
// in a[low : high]. b[ ] is an auxiliary global array.
{
  h := low; i := low; j := mid + 1;
  while ((h ≤ mid) and (j ≤ high)) do
  {
    if (a[h] ≤ a[j]) then
    {
      b[i] := a[h]; h := h + 1;
    }
    else
    {
      b[i] := a[j]; j := j + 1;
    }
    i := i + 1;
  }
  if (h > mid) then
    for k := j to high do
    {
      b[i] := a[k]; i := i + 1;
    }
  else
    for k := h to mid do
    {
      b[i] := a[k]; i := i + 1;
    }
  for k := low to high do a[k] := b[k];
}

Program:
#include <stdio.h>
#include <time.h>
void merge(int a[],int i1,int j1,int i2,int j2) {
	int i,j,k=0;
	i=i1;
	j=i2;
	int temp[100];
	while(i<=j1 && j<=j2) {
		if(a[i]<a[j])
			temp[k++]=a[i++];
		else
			temp[k++]=a[j++];
	}
	while(i<=j1)
		temp[k++]=a[i++];
	while(j<=j2)
		temp[k++]=a[j++];
	for(i=i1,j=0; i<=j2; i++,j++)
		a[i]=temp[j];
}
void partition(int a[],int l,int h) {
	if(l<h) {
		int mid=(l+h)/2;
		partition(a,l,mid);
		partition(a,mid+1,h);
		merge(a,l,mid,mid+1,h);
	}
}
int main() {
	int n;
	printf("enter the size of array: ");
	scanf("%d",&n);
	int a[n];
	for(int i=0; i<n; i++)
		a[i] = n - i;
	clock_t t = clock();
	partition(a,0,n-1);
	t = clock() - t;
	printf("Time taken: %f \n",((float)t*1000)/CLOCKS_PER_SEC);
	for(int i=0; i<n; i++)
		printf("%d ",a[i]);
	return 0;
}
Output:
enter the size of array: 5
Time taken: 0.002000 
1 2 3 4 5 

=== Code Execution Successful ===
b) Implement Quick sort algorithm and plot its time complexity regarding asymptotic notations (Best, average, and worst).
Algorithm:
Algorithm QuickSort(p, q)
// Sorts the elements a[p], ..., a[q] which reside in the global
// array a[1 : n] into ascending order; a[n + 1] is considered to
// be defined and must be ≥ all the elements in a[1 : n].
{
    if (p < q) then     // If there are more than one element
    {
        // divide P into two subproblems.
        j := Partition(a, p, q + 1);
        // j is the position of the partitioning element.
        // Solve the subproblems.
        QuickSort(p, j - 1);
        QuickSort(j + 1, q);
        // There is no need for combining solutions.
    }
}
Algorithm Partition(a, m, p)
// Within a[m], a[m + 1], ..., a[p − 1] the elements are
// rearranged in such a manner that if initially t = a[m],
// then after completion a[q] = t for some q between m
// and p − 1, a[k] ≤ t for m ≤ k < q, and a[k] ≥ t
// for q < k < p. q is returned. Set a[p] = ∞.
{
  v := a[m]; i := m; j := p;
  repeat
  {
    repeat
      i := i + 1;
    until (a[i] ≥ v);
    
    repeat
      j := j − 1;
    until (a[j] ≤ v);
    
    if (i < j) then Interchange(a, i, j);
  } until (i ≥ j);
  
  a[m] := a[j]; a[j] := v; return j;
}

Algorithm Interchange(a, i, j)
// Exchange a[i] with a[j].
{
  p := a[i];
  a[i] := a[j]; a[j] := p;
}

Program:
#include <stdio.h>
#include <time.h>

void quicksort(int number[25], int first, int last) {
    int i, j, pivot, temp;
    if (first < last) {
        pivot = first;
        i = first;
        j = last;
        while (i < j) {
            while (number[i] <= number[pivot] && i < last)
                i++;
            while (number[j] > number[pivot])
                j--;
            if (i < j) {
                temp = number[i];
                number[i] = number[j];
                number[j] = temp;
            }
        }
        temp = number[pivot];
        number[pivot] = number[j];
        number[j] = temp;
        quicksort(number, first, j - 1);
        quicksort(number, j + 1, last);
    }
}

int main() {
    int i, count, number[25];
    printf("SIZE OF ARRAY?: ");
    scanf("%d", &count);

    printf("Enter array elements: ");
    for (i = 0; i < count; i++) {
        scanf("%d", &number[i]);
    }

    clock_t t = clock(); // Start time
    quicksort(number, 0, count - 1);
    t = clock() - t; // End time

    printf("Time taken: %f ms\n", ((float)t * 1000) / CLOCKS_PER_SEC);
    printf("Sorted elements:");
    for (i = 0; i < count; i++) {
        printf(" %d", number[i]);
    }
    printf("\n");

    return 0;
}
Output:

SIZE OF ARRAY?: 5
Enter array elements: 5 4 3 2 1
Time taken: 0.002000 ms
Sorted elements: 1 2 3 4 5


=== Code Execution Successful ===
#include<stdio.h>
// Author- Khadiza Sultana
// Date- 10/8/2024
// Prints the Calendar of a month 
int main()
{
    int n, i, day; // n stores the number of days in the month, i used as a loop counter, day stores the starting day of the week(from 1 to 7, where 1= Sunday, 7= saturday)
    printf("Enter number of days in month:");
    scanf("%d", &n);
    printf("Enter starting day of the week (1=Sun, 7=Sat): ");
    scanf("%d", &day);
    for(i = 1; i < day; ++i) // This loop is responsible for printing spaces before the first day of the month.
    // If day == 1, no spaces are printed before thr month starts on sunday.
    // If day == 4, the loop runs three times and prints three spaces to align the first day under Wednesday
    {
        printf("   "); // three spacesto allign the days even when there's two digit days the days will be aligned 
    }
    for(i = 1; i <= n; i++, day++) // Prints the actual days of the month.
    // the day++ inside the for loop increments the day variable with each iteration, so the program knows when to start a new line after printing Saturday
    {
        printf("%2d ", i);
        if(day == 7)
        {
            day = 0;
            printf("\n");
        }
    }

    return 0;
}
#include<stdio.h>
// Author- Khadiza Sultana
// Date- 10/8/2024
// printing all even squares from 1 to n
#include<math.h> // includin math.h library for the pow function. We can simply write i*i instead

int main() { 
    int n;
    printf("Enter a number: ");
    scanf("%d", &n);
    
    int i = 1;
    while(pow(i,2)<= n) // checking if i^2 is equal to n or not. If yes then the loop is stoped. If no then continue
    {
        int square = pow(i,2); // storing the squares of the numbers
        if(square % 2 == 0) // checking if the squares are even or not
        {
            printf("%d\n", square);
        }
        i++; // incrementing i
    }
    
    return 0;
}
#include<stdio.h>
// Author- Khadiza Sultana
// 10/8/2024
// Takes a fraction and prints the lowest form of the fraction

int main() {
    int a, b, x, y, gcd; // Take two integers as input
    printf("Enter the fraction (a/b): ");
    scanf("%d/%d", &a, &b);

    x = a;
    y = b;

    // Using Euclidean algorithm to find the GCD of a and b
    while (y != 0) {
        int remainder = x % y;
        x = y;
        y = remainder;
    }

    // x now contains the GCD
    gcd = x;

    // Dividing both numerator and denominator by GCD to get the reduced fraction
    a = a / gcd;
    b = b / gcd;

    printf("In lowest terms: %d/%d\n", a, b);
    
    return 0;
}
#include<stdio.h>
// Author- Khadiza Sultana
// 10/8/2024
// Determing GCD of two integers using loop
int main()
{
    int a, b; // take two integers as input
    printf("Enter the integers:");
    scanf("%d %d", &a, &b);
    while (b!=0)
    {
      int remainder = a % b; //1. Determining the remainder of a/b
      a = b; //2. storing b into a
      b = remainder;//3. storing remainder into b
    }
    printf("The GCD of the two integers is: %d", a); // 'a' holds the GCD after the loop
    return 0;
}
#include<stdio.h>
// Author- Khadiza Sultana
// 10/8/2024
//Finding the largest number with the help of loop
int main()
{
    double number = 0, largest = 0; // initialization is done
    for(;;)
    {
        printf("Enter the number:");
        scanf("%lf", &number);
       
        if(number <= 0)
           break; // when zero or negative number then the infinite loop is broke

        if(number > largest)
           largest = number; // storing the largest number after comparing
    }
    printf("\nThe largest number is %g\n", largest);
   
    return 0;
}
// Online C compiler to run C program online
#include <stdio.h>

int main() {
    int limit,i,j,tmp;
    int a[1000];
    printf("enter the size of an array\n");
    scanf("%d",&limit);
    printf("enter the value of array\n");
    for(i=0;i<limit;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<limit-1;i++){
        for(j=i+1;j<limit;j++){
            if(a[i]>a[j]){
                tmp=a[i];
                a[i]=a[j];
                a[j]=tmp;
            }
        }
    }
    printf("sorted array\n");
    for(i=0;i<limit;i++){
        printf("%d,\t",a[i]);
    }
    
    
    
    return 0;
}
#include <stdio.h>

int main(void) {
	// your code goes here
	int t;
	scanf("%d",&t);
	while(t--)
	{
	    int x;
	    scanf("%d",&x);
	    if(x+3<=10)
	    {
	        printf(" yes \n");
	    }
	    else
	    {
	        printf(" no \n");
	    }
	}
	return 0;
}
#include <stdio.h>
#include <string.h>

struct Product
{
    char name [20];
    char brand [20];
    float price ;
    int quantity;

};

void print_product(struct Product a_product);

int main(void)
{
    struct Product a_product[3];
    
    sprintf(a_product[0].name,"Xbox One S");
    sprintf(a_product[0].brand,"Microsoft");
    a_product[0].price= 395.50;
    a_product[0].quantity = 35;
    
    sprintf(a_product[1].name,"PlayStation 4 Pro");
    sprintf(a_product[1].brand,"Sony");
    a_product[1].price= 538.00;
    a_product[1].quantity = 71;
    
    sprintf(a_product[2].name,"Switch");
    sprintf(a_product[2].brand,"Nintendo");
    a_product[2].price= 529.95;
    a_product[2].quantity = 8;
    
    for(int i = 0; i < 3; i++)
    {
        print_product(a_product[i]);
    }
	return 0;
}

void print_product(struct Product a_product)
{
	printf("Item name: %s\n", a_product.name);
	printf("Brand:     %s\n", a_product.brand);
	printf("Price:     $%.2f\n", a_product.price);
	printf("Quantity:  %d\n\n", a_product.quantity);
}
#include <stdio.h>
#include <math.h>

struct Circle
{
	float radius;
	float x_position;
	float y_position;
	
};

float distance_between(struct Circle c1, struct Circle c2);

int main(void)
{
	struct Circle c1;
	struct Circle c2;

    float r1 = 0;
    float r2 = 0;
    scanf("%f", &r1);
    scanf("%f", &r2);
	c1.radius = r1;
	c2.radius = r2;
	c1.x_position = 11;
	c1.y_position = 22;
	c2.x_position = 4;
	c2.y_position = 6;

	float distance = distance_between(c1, c2);
	printf("distance between two circle is %f.", distance);

	return 0;
}

float distance_between(struct Circle c1, struct Circle c2)
{
    float distance;
    distance = sqrt( pow((c1.x_position - c2.x_position),2) + pow((c1.y_position - c2.y_position),2)) - c1.radius - c2.radius;
    return distance;
}

#include <stdio.h>

struct SoftDrink
{
    char name[17];
    int size;
    int energy;
    float caffeine;
    int intake;

};

void print_soft_drink(struct SoftDrink* drink);

int main(void)
{
    struct SoftDrink drink = { "Life Modulus",250,529,80.50,500};
    
    print_soft_drink(&drink);
    
    return 0;
    
}

void print_soft_drink(struct SoftDrink *drink)
{   
    printf("A soft drink...\n\n");
    printf("Name: %s\n",drink->name);
    printf("Serving size: %d mL\n",drink->size);
    printf("Energy content: %d kJ\n",drink->energy);
    printf("Caffeine content: %f mg\n",drink->caffeine);
    printf("Maximum daily intake: %d mL\n",drink->intake);

}
#include <stdio.h>

char to_lower(char letter);

int main(void)
{
	char input;

	printf("Please input a letter: \n");

	scanf("%c", &input);

	printf("%c's lowercase is %c\n", input, to_lower(input));

	return 0;
}

char to_lower(char letter)
{
     if (letter >= 'A' && letter <= 'Z') {
        return letter + 32; // Convert to lowercase by adding 32
    } else {
        return '\0'; // Return null character if not uppercase
    }
}
#include <stdio.h>

int get_length(char *cstring) 
{
    int length = 0;
    while (cstring[length] != '\0') 
    {
        length++;
    }
    return length;
}

int main(void) {
    char *text[] = { "Steffan", "Pascal", "Jade" };

    printf("%s is %d chars.\n", text[0], get_length(text[0]));
    printf("%s is %d chars.\n", text[1], get_length(text[1]));
    printf("%s is %d chars.\n", text[2], get_length(text[2]));
    
    // Do not change the following code
    char user_input[64];
    scanf("%63[^\n]", user_input);
    printf("%s is %d chars.\n", user_input, get_length(user_input));
    
    return 0;
}
#include <stdio.h>

struct Character_Counts
{
	int vowels;
	int consonants;
	int uppercase;
	int lowercase;
	int spaces;
	int digits;
};
//add 
int is_vowel(char ch) {
    char lower_ch = (ch >= 'A' && ch <= 'Z') ? ch + 32 : ch;  // Convert to lowercase if uppercase
    return (lower_ch == 'a' || lower_ch == 'e' || lower_ch == 'i' || lower_ch == 'o' || lower_ch == 'u');
}

int is_alpha(char ch) {
    return ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'));
}

int is_upper(char ch) {
    return (ch >= 'A' && ch <= 'Z');
}

int is_lower(char ch) {
    return (ch >= 'a' && ch <= 'z');
}

int is_digit(char ch) {
    return (ch >= '0' && ch <= '9');
}

struct Character_Counts analyse_text(char text[])
{
    struct Character_Counts counts = {0, 0, 0, 0, 0, 0};
    char *ptr = text;

    while (*ptr != '\0') {
        char ch = *ptr;
        if (is_alpha(ch)) {
            if (is_upper(ch)) {
                counts.uppercase++;
            }
            if (is_lower(ch)) {
                counts.lowercase++;
            }
            if (is_vowel(ch)) {
                counts.vowels++;
            } else {
                counts.consonants++;
            }
        } else if (is_digit(ch)) {
            counts.digits++;
        } else if (ch == ' ') {
            counts.spaces++;
        }
        ptr++;
    }

    return counts;
}


void print_counts(struct Character_Counts data)
{
    printf("Vowels = %d\n", data.vowels);
    printf("Consonants = %d\n", data.consonants);
    printf("Uppercase = %d\n", data.uppercase);
    printf("Lowercase = %d\n", data.lowercase);
    printf("Spaces = %d\n", data.spaces);
    printf("Digits = %d\n", data.digits);
}

int main(void)
{
	char buffer[80];
	printf("> ");
	scanf("%79[^\n]", buffer);
	struct Character_Counts results = analyse_text(buffer);
	print_counts(results);
	return 0;
}
#include <stdio.h>

void divide(int dividend, int divisor, int* p_quotient, int* p_remainder);

int main(void)
{
	int numerator = 0;
	printf("Dividend? ");
	scanf("%d", &numerator);
	int denominator = 0;
	printf("\nDivisor?");
	scanf("%d", &denominator);
	int quotient;
	int remainder;
	// TODO: Call divide...
	divide(numerator, denominator, &quotient, &remainder);
	printf("\nQuotient is %d\n", quotient);
	printf("Remainder is %d\n", remainder);
	return 0;
}

// TODO: Define divide function:
void divide(int dividend, int divisor, int* p_quotient, int* p_remainder) 
{
    *p_quotient = dividend / divisor;
    *p_remainder = dividend % divisor;
}
#include <stdio.h>

void print_assessments(int learning_outcome);

int main()
{
    int learning_outcome;
    
    scanf("%d",&learning_outcome);
    printf("Learning Outcome?\n");
    print_assessments(learning_outcome);
    
}

void print_assessments(int learning_outcome)
{
    if(learning_outcome == 0 || learning_outcome > 10)
    {
        printf("Invalid Learning Outcome.");
    }
    if(learning_outcome >=1 && learning_outcome <= 10)
    {
        printf("\nReporting Journal\n");
    }
    if(learning_outcome >=1 && learning_outcome <= 6)
    {
        printf("Practical Test 1\n");
    }
    if(learning_outcome >=1 && learning_outcome <= 8)
    {
        printf("Practical Test 2\n");
    }
    if(learning_outcome >=1 && learning_outcome <= 9)
    {
        printf("Practical Test 3\n");
    }
    if(learning_outcome >=1 && learning_outcome <= 10)
    {
        printf("Final Practical Exam\n");
    }
    
}
#include <stdio.h>

int calculate_pizza_share(int number_of_people);

int main(void)
{
    int number_of_people;

    // Prompt the user for input
    printf("How many people? \n");
    scanf("%d", &number_of_people);

    // Calculate the pizza share
    int slices_per_person = calculate_pizza_share(number_of_people);

    // Output the result
    if (slices_per_person == -1) 
    {
        printf("Error\n");
    } 

	else 
    {
        printf("%d people get %d slice(s) each.\n", number_of_people, slices_per_person);
    }

    return 0;
}

int calculate_pizza_share(int number_of_people)
{
    if (number_of_people <= 0) 
    {
        return -1; // Error for non-positive number of people
        
    }

    int total_slices = 8; // Total slices in a pizza

    return total_slices / number_of_people;
}
#include <stdio.h>

// Function declarations
void draw_top_bottom_border(char corner_char, char horizontal_char, int width);
void draw_vertical_sides(char vertical_char, int width, int height);
void draw_ascii_box(char horizontal_char, char vertical_char, char corner_char, int width, int height);

// Function to draw the top and bottom borders
void draw_top_bottom_border(char corner_char, char horizontal_char, int width) 
{
    printf("%c", corner_char);
    for (int i = 0; i < width - 2; i++) 
    {
        printf("%c", horizontal_char);
    }
    printf("%c\n", corner_char);
}

// Function to draw the vertical sides
void draw_vertical_sides(char vertical_char, int width, int height) 
{
    for (int i = 0; i < height - 2; i++) 
    {
        printf("%c", vertical_char);
        for (int j = 0; j < width - 2; j++) 
        {
            printf(" ");
        }
        printf("%c\n", vertical_char);
    }
}

// Function to draw the ASCII box
void draw_ascii_box(char horizontal_char, char vertical_char, char corner_char, int width, int height) {

    
    // Draw top border
    draw_top_bottom_border(corner_char, horizontal_char, width);
    
    // Draw vertical sides
    draw_vertical_sides(vertical_char, width, height);
    
    // Draw bottom border
    draw_top_bottom_border(corner_char, horizontal_char, width);
}

// Main function to get user inputs and test the draw_ascii_box function
int main() {
    char horizontal_char;
    char vertical_char;
    char corner_char;
    int width;
    int height;

    // Get user inputs
    
    scanf(" %c", &horizontal_char);

    scanf(" %c", &vertical_char);

    scanf(" %c", &corner_char);

    scanf("%d", &width);

    scanf("%d", &height);

    // Draw the ASCII box based on user inputs
    draw_ascii_box(horizontal_char, vertical_char, corner_char, width, height);

    return 0;
}
#include <stdio.h>

// Define the structure Triangle
struct Triangle 
{
    int height;
    char inner_symbol;
};

// Function to print the inverted triangle
void print_inverted(struct Triangle inverted_triangle) {
    int height = inverted_triangle.height;
    char symbol = inverted_triangle.inner_symbol;

    // Print the top line
    for (int i = 0; i < 2 * height; i++) 
    {
        printf("_");
    }
    printf("\n");

    // Print the inverted triangle
    for (int i = 0; i < height; i++) 
    {
        // Print leading spaces
        for (int j = 0; j < i; j++) 
        {
            printf(" ");
        }
        
        // Print the left side of the triangle
        printf("\\");
        
        // Print the inner symbols
        for (int j = 0; j < 2 * (height - i - 1); j++) 
        {
            printf("%c", symbol);
        }
        
        // Print the right side of the triangle
        printf("/\n");
    }
}

int main() 
{
    struct Triangle my_triangle;
    
    // Query the user for the desired inverted triangle height and symbol
    printf("Inverted triangle's height?\n");
    scanf("%d", &my_triangle.height);
    
    printf("Inverted triangle's symbol?\n");
    scanf(" %c", &my_triangle.inner_symbol);
    
    // Call the print_inverted function
    print_inverted(my_triangle);
    
    return 0;
}
#include <stdio.h>

// Define the structure Triangle
struct Triangle {
    int height;
    char inner_symbol;
};

// Function to print the inverted triangle
void print_inverted(struct Triangle inverted_triangle) {
    int height = inverted_triangle.height;
    char symbol = inverted_triangle.inner_symbol;

    // Print the top line
    for (int i = 0; i < 2 * height; i++) {
        printf("_");
    }
    printf("\n");

    // Print the inverted triangle
    for (int i = 0; i < height; i++) {
        // Print leading spaces
        for (int j = 0; j < i; j++) {
            printf(" ");
        }
        
        // Print the left side of the triangle
        printf("\\");
        
        // Print the inner symbols
        for (int j = 0; j < 2 * (height - i - 1); j++) {
            printf("%c", symbol);
        }
        
        // Print the right side of the triangle
        printf("/\n");
    }
}

int main() 
{
    struct Triangle my_triangle;
    
    // Query the user for the desired inverted triangle height and symbol
    printf("Inverted triangle's height?\n");
    scanf("%d", &my_triangle.height);
    
    printf("Inverted triangle's symbol?\n");
    scanf(" %c", &my_triangle.inner_symbol);
    
    // Call the print_inverted function
    print_inverted(my_triangle);
    
    return 0;
}
#include <stdio.h>

float dot_product(float v1[3], float v2[3]) //add this
{
    return (v1[0] * v2[0]) + (v1[1] * v2[1]) + (v1[2] * v2[2]);
}

int main(void)
{
	float vec_a[3];
	float vec_b[3];

	vec_a[0] = 1.5f;
	vec_a[1] = 2.5f;
	vec_a[2] = 3.5f;
	vec_b[0] = 4.0f;
	vec_b[1] = 5.0f;
	vec_b[2] = 6.0f;

	printf("%f\n", dot_product(vec_a, vec_b));

	return 0;
}
#include<stdio.h>

char convert_percent_to_grade(float input)
{
    if(input>=80.0f)
    {
        return 'A';
    }
    else if(input>=60.0f && input <80.0f)
    {
        return 'B';
    }
    else if(input>=50.0f && input < 60.0f)
    {
        return 'C';
    }
    else 
    {
        return 'D';
    }

}

int main()
{
    float input;
    
    printf("What's the percentage:\n");
    scanf("%f",&input);
    
    char output = convert_percent_to_grade(input);
    
    printf("%.2f%% is %c Grade",input,output);
    
    
}
#include <stdio.h>
#include <math.h>

struct Point3D
{
    float x;
    float y;
    float z;
};

float compute_distance3d(struct Point3D p1, struct Point3D p2);

int main(void)
{
    struct Point3D p1;
    struct Point3D p2;

    // Initialize the structures with test values
    p1.x = 1.0;
    p1.y = 2.0;
    p1.z = 3.0;

    p2.x = 4.0;
    p2.y = 5.0;
    p2.z = 6.0;

    // Calculate the distance between the test values
    float distance = compute_distance3d(p1, p2);

    // Query user for input coordinates
    printf("Enter coordinates for Point1 (x y z): ");
    scanf("%f %f %f", &p1.x, &p1.y, &p1.z);

    printf("Enter coordinates for Point2 (x y z): ");
    scanf("%f %f %f", &p2.x, &p2.y, &p2.z);

    // Calculate and print the distance based on user input
    distance = compute_distance3d(p1, p2);
    printf("Distance between the two points is %f.\n", distance);

    return 0;
}

float compute_distance3d(struct Point3D p1, struct Point3D p2)
{
    return sqrt(pow(p2.x - p1.x, 2) + pow(p2.y - p1.y, 2) + pow(p2.z - p1.z, 2));
}
#include <stdio.h>
#include <string.h>

struct Student
{
    char name [50]; //declare as character array with space for 50 characters
    float lecture_attendance;
    float lab_attendance;
};

int main(void)
{
    struct Student student;
    
    sprintf(student.name,"Jane Doe"); //use sprintf to format and store the string into the name array of the student structure.
    student.lecture_attendance = 0.33f;
    student.lab_attendance = 1.00f;
    printf("Successful!!!");
    return 0;
}
#include <stdio.h>

struct Movie
{
    char title [50];
    int minutes;
    float tomatometer;
};

void print_movie(struct Movie a_super_hero);

int main(void)
{
    struct Movie movie;

	sprintf(movie.title, "Batman Returns");
	movie.minutes = 126;
	movie.tomatometer = 0.81f;

	print_movie(movie);
	
	return 0;
}

void print_movie(struct Movie a_movie)
{
    printf("Movie title:        %s\n",a_movie.title);
    printf("Runtime in minutes: %d\n",a_movie.minutes);
    printf("Tomatometer Score:  %.2f",a_movie.tomatometer);
}
#include <stdio.h>

enum Monster_Type
{
    ZOMBIE, WEREWOLF, VAMPIRE, MUMMY, CHANGELING
};

struct Monster
{
    char type [20];
    int age; 
    int power; 
    float speed;
    int stamina;
};

struct Monster create_monster(enum Monster_Type type);

void print_monster(struct Monster monster);

int main(void)
{
	struct Monster monster1 = create_monster(CHANGELING);
	print_monster(monster1);

	struct Monster monster2 = create_monster(MUMMY);
	print_monster(monster2);

	struct Monster monster3 = create_monster(WEREWOLF);
	print_monster(monster3);

	struct Monster monster4 = create_monster(VAMPIRE);
	print_monster(monster4);

	struct Monster monster5 = create_monster(ZOMBIE);
	print_monster(monster5);

	return 0;
}

// TODO: Define functions here:
struct Monster create_monster(enum Monster_Type type)
{   
    struct Monster monster;
    
    if(type == CHANGELING)
    {
        sprintf(monster.type,"Changeling");
        monster.age = 21;
        monster.power = 86;
        monster.speed = 6.77;
        monster.stamina = 4057;
    }
    if(type == MUMMY)
    {
        sprintf(monster.type,"Mummy");
        monster.age = 3793;
        monster.power = 97;
        monster.speed = 0.37;
        monster.stamina = 492;
    }
    if(type == WEREWOLF)
    {
        sprintf(monster.type,"Werewolf");
        monster.age = 70;
        monster.power = 144;
        monster.speed = 20.53;
        monster.stamina = 4628;
    }
    if(type==VAMPIRE)
    {
        sprintf(monster.type,"Vampire");
        monster.age = 89;
        monster.power = 260;
        monster.speed = 10.08;
        monster.stamina = 3926;
    }

    if(type==ZOMBIE)
    {
        sprintf(monster.type,"Zombie");
        monster.age = -1;
        monster.power = 1;
        monster.speed = 0.30;
        monster.stamina = 173;
    }
    return monster;
}

void print_monster(struct Monster monster)
{
    printf("Monster Type: %s\n",monster.type);
	printf("         Age: %d years\n",monster.age);
	printf("       Power: %d \n",monster.power);
	printf("       Speed: %.2f \n",monster.speed);
	printf("     Stamina: %d \n",monster.stamina);
}
#include <stdio.h>

struct Student
{
    char first_name [20];
    char last_name [20];
    int stream_code ;
};

struct Student query_student(void)
{
	// TODO: Declare a local Student variable.
    struct Student student;

	printf("Input first name: \n");
	// TODO: Scan for user input...
	scanf("%s",student.first_name);
    

	printf("Input last name: \n");
	// TODO: Scan for user input...
    scanf("%s",student.last_name);

	printf("Input stream code: \n");
	// TODO: Scan for user input...
    scanf("%d",&student.stream_code);

	// TODO: Return the local Student variable.
	return student;

}

int main(void)
{
    struct Student query;

	query = query_student();

	printf("%s ", query.first_name);
	printf("%s ", query.last_name);
	printf("is in stream %d.", query.stream_code);

	return 0;
}
#include <stdio.h>
 // TODO: Declare a Quadratic_Solution enumerated type here:
enum Quadratic_Solution
{
    TWO_COMPLEX,
    ONE_REAL,
    TWO_REAL
};
enum Quadratic_Solution get_solution_type(float a, float b, float c);
void print_solution_type(enum Quadratic_Solution qs);

int main(void) 
{
  float a_coefficent = 0.0f;
  float b_coefficent = 0.0f;
  float c_constant = 0.0f;
  printf("y = ax^2 + bx + c\n");
  printf("a? \n");
  scanf("%f", & a_coefficent);
  printf("b? \n");
  scanf("%f", & b_coefficent);
  printf("c? \n");
  scanf("%f", & c_constant);
  enum Quadratic_Solution result = get_solution_type(a_coefficent,
    b_coefficent,
    c_constant);
  print_solution_type(result);
  return 0;
}
// TODO: Define the get_solution_type function here:
enum Quadratic_Solution get_solution_type(float a, float b, float c)
{
    float result = b * b - 4 * a * c;
    if(result>0)
    {
        return TWO_REAL;   
    }
    else if(result==0)
    {
        return ONE_REAL;
    }
    else
    {
        return TWO_COMPLEX;
    }
}
// TODO: Define the print_solution_type function here:
void print_solution_type(enum Quadratic_Solution qs)
{
    switch(qs)
    {
        case TWO_COMPLEX:
        {
            printf("Two complex solutions.\n");
            break;
        }
        case ONE_REAL:
        {
            printf("One real solution.\n");
            break;
        }
        case TWO_REAL:
        {
            printf("Two real solutions.\n");
            break;
        }
    }
}
#include <stdio.h>

enum Contains_Result
{
 ABSENT,
 PRESENT
};

enum Contains_Result contains(char* cstring, char find);

int main(void)
{
    char buffer1[] = "Hello Programming 1 Students";
    char buffer2[] = "Learn to program using arrays and pointers!";
    int found_d = contains(buffer1, 'd');
 
    if (found_d == PRESENT)
    {
        printf("buffer1 contains d\n");
    }
    else
    {
        printf("buffer1 does not contain d\n");
    }
 
    found_d = contains(buffer2, 'd');
 
    if (found_d == PRESENT)
    {
        printf("buffer2 contains d\n");
    }
    else
    {
        printf("buffer2 does not contain d\n");
    }
 
 	// The following function tests your code.
	// Do not modify the following code.
	test();
	
    return 0;
}

enum Contains_Result contains(char* cstring, char find)
{
 // TODO: Insert your code here...
 while (*cstring != '\0')
    {
        if (*cstring == find)
        {
            return PRESENT;
        }
        cstring++;
    }
    return ABSENT;
}
#include <stdio.h>

void draw_inverted_triangle(int height) {
    for (int i = 0; i < height; ++i) {
        // Print leading spaces
        for (int j = 0; j < i; ++j) {
            putchar(' ');
        }

        // Print backslash
        putchar('\\');

        // Print inner spaces
        for (int j = 0; j < 2 * (height - i - 1); ++j) {
            putchar(' ');
        }

        // Print forward slash
        putchar('/');

        // Move to the next line
        putchar('\n');
    }
}

int main() {
    int height;

    // Get the height from the user
    printf("enter height: \n");
    scanf("%d", &height);

    // Print the top line of underscores
    for (int i = 0; i < 2 * height; ++i) {
        putchar('_');
    }
    putchar('\n');

    // Draw the inverted triangle
    draw_inverted_triangle(height);

    return 0;
}
#include <stdio.h>

enum Day
{
    MONDAY,
    TUESDAY,
    WEDNESDAY,
    THURSDAY,
    FRIDAY,
    SATURDAY,
    SUNDAY
};

    
void print_day_category(enum Day day)
{
    if((day==MONDAY)||(day==TUESDAY)||(day==WEDNESDAY)||(day==THURSDAY)||(day==FRIDAY))
    {
        printf("Weekday\n");
    }
    else
    {
        printf("Weekend\n");
    }
}
void print_day_name(enum Day day)
{
    
    
        if(day==MONDAY)
        {
            printf("Monday");
            
        }
        if(day==TUESDAY)
        {
            printf("Tuesday");
           
        }
        if(day==WEDNESDAY)
        {
            printf("Wednesday");
           
        }
        if(day==THURSDAY)
        {
            printf("Thursday");
           
        }
        if(day==FRIDAY)
        {
            printf("Friday");
            
        }
        if(day==SATURDAY)
        {
            printf("Saturday");
            
        }
        if(day==SUNDAY)
        {
            printf("Sunday");
            
        }

}

int main(void)
{
    //keep this
	for (int i = 0; i < 70; i++)
	{
		print_day_name(i%7);
		printf(" is a ");
		print_day_category(i%7);
		printf("\n");
	}
	return 0;
}
#include <stdio.h>

enum Day
{
    MONDAY,
    TUESDAY,
    WEDNESDAY,
    THURSDAY,
    FRIDAY,
    SATURDAY,
    SUNDAY
};

    
void print_day_category(enum Day day)
{
    if((day==MONDAY)||(day==TUESDAY)||(day==WEDNESDAY)||(day==THURSDAY)||(day==FRIDAY))
    {
        printf("Weekday\n");
    }
    else
    {
        printf("Weekend\n");
    }
}
void print_day_name(enum Day day)
{
    
    
        if(day==MONDAY)
        {
            printf("Monday");
            
        }
        if(day==TUESDAY)
        {
            printf("Tuesday");
           
        }
        if(day==WEDNESDAY)
        {
            printf("Wednesday");
           
        }
        if(day==THURSDAY)
        {
            printf("Thursday");
           
        }
        if(day==FRIDAY)
        {
            printf("Friday");
            
        }
        if(day==SATURDAY)
        {
            printf("Saturday");
            
        }
        if(day==SUNDAY)
        {
            printf("Sunday");
            
        }

}

int main(void)
{
    //keep this
	for (int i = 0; i < 70; i++)
	{
		print_day_name(i%7);
		printf(" is a ");
		print_day_category(i%7);
		printf("\n");
	}
	return 0;
}
#include <stdio.h>

void print_array(int *p_array, int num_elements);
void zero_out_array(int *p_array, int num_elements);
int main(void)
{
	int main_array[] = { 15, 24, 33, 42, 51 };

	// TODO: Insert code here...
	int num_elements = sizeof(main_array)/sizeof(main_array[0]);
	
	print_array(main_array,num_elements);
    zero_out_array(main_array,num_elements);
    print_array(main_array,num_elements);
	return 0;
}

void print_array(int *p_array, int num_elements)
{
	printf("print_array called:\n");
	// TODO: Insert code here...
	for(int i = 0; i < num_elements; i++)
	{
	    printf("%d ",p_array[i]);
	}
	printf("\n\n");
}

void zero_out_array(int *p_array, int num_elements)
{
	printf("zero_out_array called:\n\n");
	// TODO: Insert code here...
	for(int i = 0; i < num_elements; i++)
	{
	    *(p_array+i) = 0;
	}
}
#include <stdio.h>

int find_min_index(int* numbers, int length);

int main(void)
{
    int array1[] = { 1, 3, 5, 7, 9, 11 };
    int array2[] = { 2, -4, 6, -8, 10, -12, 14, -16, 4 };
    int array3[] = { 6, 4, 1, 4, 5, 3, 2 };
 
    printf("Min's index in array1 is: %d\n", find_min_index(array1, 6));
    printf("Min's index in array2 is: %d\n", find_min_index(array2, 9));
    printf("Min's index in array3 is: %d\n", find_min_index(array3, 7));
 
    return 0;
}

int find_min_index(int* numbers, int length)
{
    // TODO: Insert your code here!
    
    int min_index = 0;
    
    for(int i = 0; i < length; i++)
    {
        if( numbers[i] < numbers[min_index] )
        {
            min_index = i;
        }
    }
    return min_index;
}
#include <stdio.h>

int count_odds(int* data_array, int size);

int main(void)
{
	int data_array_1[] = { 1, 3, 5, 7, 9, 11 };
	int data_array_2[] = { 2, -4, 6, -8, 10, -12, 14, -16 };
	int data_array_3[] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };

	int result_1 = count_odds(data_array_1, 6);
	printf("data_array_1 has %d odd numbers.\n", result_1);
	
	int result_2 = count_odds(data_array_2, 8);
	printf("data_array_2 has %d odd numbers.\n", result_2);
	
	int result_3 = count_odds(data_array_3, 11);
	printf("data_array_3 has %d odd numbers.\n", result_3);
	
	return 0;
}

// TODO: Insert your function definition here!
int count_odds(int* data_array, int size)
{
    int count = 0;
    
    
    for(int i =0; i < size ;i++)
    {
        if(data_array[i] > 0 && data_array[i] % 2 != 0)
        {
            count++;
        }
    }
    return count;
}
#include <stdio.h>

void cube(float* number);

int main(void)
{
	float x = 0.0f;

	printf("> ");
	scanf("%f", &x);

	// TODO: Call cube with x by reference...
	cube(&x);
	
	printf("x holds %f\n\n", x);

	return 0;
}

// TODO: Define cube function:
void cube(float* number)
{
    *number = (*number)*(*number)*(*number);
    
}
#include <stdio.h>
#include <math.h>

void compute_trig(float deg, float* sin_angle, float* cos_angle);

int main(void)
{
    float sin_result = 0.0f;
    float cos_result = 0.0f;
    float angle = 0.0f;
 
    printf("Angle? \n");
    scanf("%f", &angle);
    // TODO: Call compute_trig
    compute_trig(angle,&sin_result,&cos_result);
    
    printf("sin(%f) is %f\n", angle, sin_result);
    printf("cos(%f) is %f\n", angle, cos_result);
 
    return 0;
}

void compute_trig(float deg, float* sin_angle, float* cos_angle)
{
    float pi = 3.14159f;
    float radians = deg * pi / 180.0f;
    // TODO: Compute sine angle...
    *sin_angle = sinf(radians);
    
    // TODO: Compute cosine angle...
    *cos_angle = cosf(radians);
}
#include <stdio.h>

void increment(int* int_pointer);

int main(void)
{
	int x = 0;
	printf("> \n");
	scanf("%d", &x);
	// TODO: Call increment with x by reference
	increment(&x);
	printf("x holds %d\n\n", x);
	// TODO: Call increment with x by reference
	increment(&x);
	printf("x holds %d\n\n", x);
	// TODO: Call increment with x by reference
	increment(&x);
	printf("x holds %d\n\n", x);
	return 0;
}

// TODO: Define increment function:
void increment(int* int_pointer)
{
     (*int_pointer) ++;
    
}
#include <stdio.h>

struct Softdrink
{
	char name [16];
	int size;
	int energy;
	float caffeine;
	int max_daily;
};

void print_soft_drink(struct Softdrink a_soft_drink);

int main(void)
{
    struct Softdrink life_mod;

	sprintf(life_mod.name, "Life Modulus");
	life_mod.size = 250;
	life_mod.energy = 529;
	life_mod.caffeine = 80.5f;
	life_mod.max_daily = 500;

	print_soft_drink(life_mod);
	
	return 0;
}

void print_soft_drink(struct Softdrink a_soft_drink)
{
    
	printf("A soft drink...\n\n");
	printf("Name: %s\n",a_soft_drink.name);
	printf("Serving size: %d mL\n",a_soft_drink.size);
	printf("Energy content: %d kJ\n",a_soft_drink.energy);
	printf("Caffeine content: %f mg\n",a_soft_drink.caffeine);
	printf("Maximum daily intake: %d mL\n",a_soft_drink.max_daily);
}
#include <stdio.h>

// TODO: Declare Colour structure:
struct Colour
{
    unsigned char red;
    unsigned char green;
    unsigned char blue;
};

// TODO: Declare functions:
//struct Colour create_colour(...
struct Colour create_colour(unsigned char red, unsigned char green, unsigned char blue);
//void print_colour(...
void print_colour(struct Colour a_colour);

int main(void)
{
	print_colour(create_colour(255, 0, 0)); // RED
	print_colour(create_colour(0, 255, 0)); // GREEN
	print_colour(create_colour(0, 0, 255)); // BLUE
	print_colour(create_colour(255, 255, 0)); // YELLOW
	print_colour(create_colour(255, 0, 127)); // PINK

	return 0;
}

// TODO: Define functions:
struct Colour create_colour(unsigned char red, unsigned char green, unsigned char blue)
{
	struct Colour colour;
	colour.red = red;
	colour.green = green;
	colour.blue = blue;
	
	return colour;
}

void print_colour(struct Colour a_colour)
{
    printf("RGB: %u, %u, %u\n",a_colour.red,a_colour.green,a_colour.blue);
}
#include <stdio.h>

// Function to print the top part of the decorative box
void print_top() {
    printf("/\\/\\/\\/\\/\\\n");
}

// Function to print the bottom part of the decorative box
void print_bottom() {
    printf("\\/\\/\\/\\/\\/\n");
}

// Function to print the middle part of the decorative box
void print_middle(int how_many) {
    for (int i = 0; i < how_many; i++) {
        printf("\\        /\n");
        printf("/        \\\n");
    }
}

// Main function to demonstrate the functionality
int main() {
    int how_many;

    // Prompt the user for the number of middle parts
    printf("How many middle parts? \n");
    scanf("%d", &how_many);

    // Print the top part
    print_top();
    
    // Print the middle part specified number of times
    print_middle(how_many);
    
    // Print the bottom part
    print_bottom();
    
    return 0;
}
#include <stdio.h>

void print_ascii_rectangle(char symbol, int width, int height)
{
    for(int i =0;i<height;i++)
    {
        for(int j=0;j<width;j++)
        {
            printf("%c",symbol);
        }
        printf("\n");
    }
}

int main()
{
    char symbol;
    int width;
    int height;
    printf("Please enter an ASCII symbol:\n");
    scanf(" %c",&symbol);
    
    printf("Please enter the width:\n");
    scanf("%d",&width);
    printf("Please enter the height:\n");
    scanf("%d",&height);
    print_ascii_rectangle(symbol,width,height);
}
#include <stdio.h>

void print_quadratic(int a, int b, int c)
{
    if(a!=0)
    {
        printf("%dx^2 ",a);
    }
    if(b!=0)
    {
        if(b>0)
        {
            printf("+ %dx ",b);
        }
        else
        {
            printf("- %dx ",-b);
        }
    }
    if(c!=0)
    {
        if(c>0)
        {
            printf("+ %d ",c);
        }
        else
        {
            printf("- %d ",-c);
        }
    }
    
}

int main (void)
{
    printf("Enter a:\n");
    printf("Enter b:\n");
    printf("Enter c:\n");
    int a,b,c;
    
    scanf("%d%d%d",&a,&b,&c);
    print_quadratic(a,b,c);
    
}

#include <stdio.h>
struct Banking_Account
{
 char name[32];
 int pin;
 float balance;
};
void print_banking_details(struct Banking_Account account);
int main(void)
{
 struct Banking_Account accounts[3];
 sprintf(accounts[0].name, "Steffan Hooper");
 accounts[0].pin = 7373;
 accounts[0].balance = 1250.0f;
 sprintf(accounts[1].name, "Xinyu Hu");
 accounts[1].pin = 1234;
 accounts[1].balance = 2150.0f;
 sprintf(accounts[2].name, "Jade Abbott");
 accounts[2].pin = 7777;
 accounts[2].balance = 2250.0f;
 print_banking_details(accounts[2]);
 printf("\n");
 print_banking_details(accounts[1]);
 printf("\n");
 print_banking_details(accounts[0]);
 printf("\n");
 return 0;
}
void print_banking_details(struct Banking_Account account)
{
 printf("Account Name: %s\n", account.name);
 printf("Account Balance: $%.2f\n", account.balance);
 printf("Account Pin: %d\n", account.pin);
}
#include <stdio.h>

int is_hex_digit(char input)
{
    if((input>='0'&&input<='9')||(input>='a'&&input<='z')||(input>='A'&&input<='F'))
    {
        return 1;
    }
    else
    {
        return 0;
    }
    
}

int main(void)
{
    char input;
    printf("> ");
    scanf(" %c",&input);
    
    int output = is_hex_digit(input);
    
    printf("%d",output);
    
    return 0;
}
#include <stdio.h>

int identify_minimum_value(int input_1, int input_2)
{
    int minimum_value;
    
    if(input_1<input_2)
    {
        minimum_value = input_1;
    }
    else
    {
        minimum_value = input_2;
    }
    
    return minimum_value;
}

int main (void)
{
    int input_1;
    int input_2;
    printf("Please input number 1:\n");
    scanf("%d",&input_1);
    printf("Please input number 2:\n");
    scanf("%d",&input_2);
   int minimum_value = identify_minimum_value(input_1,input_2);
    
    printf("The minimum number of %d and %d is %d",input_1,input_2,minimum_value);
    return 0;
}
#include <stdio.h>

void draw_inverted_triangle(int height) {
    for (int i = 0; i < height; ++i) {
        // Print leading spaces
        for (int j = 0; j < i; ++j) {
            putchar(' ');
        }

        // Print backslash
        putchar('\\');

        // Print inner spaces
        for (int j = 0; j < 2 * (height - i - 1); ++j) {
            putchar(' ');
        }

        // Print forward slash
        putchar('/');

        // Move to the next line
        putchar('\n');
    }
}

int main() {
    int height;

    // Get the height from the user
    printf("enter height: \n");
    scanf("%d", &height);

    // Print the top line of underscores
    for (int i = 0; i < 2 * height; ++i) {
        putchar('_');
    }
    putchar('\n');

    // Draw the inverted triangle
    draw_inverted_triangle(height);

    return 0;
}
#include <stdio.h>
#include <string.h>

enum Password_Strength
{
    TOO_WEAK,
    STRONG_ENOUGH
};

enum Password_Strength is_secure_password(char* password);

int main(void)
{
    char test_password[32];
 
    do
    {
        printf("Choose a password: \n");
        scanf("%31s", test_password);
    }
    while (is_secure_password(test_password) == TOO_WEAK);
 
    printf("%s is secure enough!\n", test_password);
 
    return 0;
}

    int is_upper(char ch)
{
    return (ch >= 'A' && ch <= 'Z');
}

int is_lower(char ch)
{
    return (ch >= 'a' && ch <= 'z');
}

int is_digit(char ch)
{
    return (ch >= '0' && ch <= '9');
}
enum Password_Strength is_secure_password(char* password)
{
    int length = strlen(password);
    int upper_count = 0;
    int lower_count = 0;
    int digit_count = 0;

    if (length < 8 || length > 12) // Minimum length requirement
    {
        return TOO_WEAK;
    }



    for (int i = 0; i < length; i++)
    {
        if (is_upper(password[i]))
            upper_count++;
        else if (is_lower(password[i]))
            lower_count++;
        else if (is_digit(password[i]))
            digit_count++;
    }

    if (upper_count >= 2 && lower_count >= 2 && digit_count >= 1)
    {
        return STRONG_ENOUGH;
    }
    else
    {
        return TOO_WEAK;
    }
 

}
#include <stdio.h>

void print_quadratic(int a, int b, int c) 
{
    printf("%dx^2 ", a);
    if (b >= 0) {
        printf("+ %dx ", b);
    } else {
        printf("- %dx ", -b);
    }
    if (c >= 0) {
        printf("+ %d", c);
    } else {
        printf("- %d", -c);
    }
    printf("\n");
}


int main() 
{
    int a, b, c;

    printf("Enter a: \n");
    scanf("%d", &a);
    printf("Enter b: \n");
    scanf("%d", &b);
    printf("Enter c: \n");
    scanf("%d", &c);

    print_quadratic(a, b, c);

    return 0;
}
#include <stdio.h>
#include <ctype.h>

int main() {
    char c;
    int a=0, e=0, i=0, o=0, u=0;
    puts("Enter a stream of characters:");
    
    while((c=getchar())!='\n')
    {
    switch(c)
    {
    case 'a':
    case 'A':a++; break;
    case'e':
    case'E':e++; break;
    case 'i':
    case 'I':i++; break;
    case 'o':
    case 'O':o++; break;
    case 'u':
    case 'U':u++; break;
    }
    
    }

    printf("A=%d\n", a);
    printf("E=%d\n", e);
    printf("I=%d\n", i);
    printf("O=%d\n", o);
    printf("U=%d\n", u);
    return 0;
}
#include <stdio.h>
#include <ctype.h>

int main() {
    char c;
    int vowels=0, consonant=0;
    puts("Stream of Characters:");
    
    while((c=getchar())!='\n')
    {
    if(isalpha(c))
    {
        if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
        vowels++;
        else
        consonant++;
    }
    
    

    }
    printf("Vowels: %d\n", vowels);
    printf("Consonant: %d", consonant);
    
    return 0;
}
#include <stdio.h>
#include <ctype.h>

int main()
{
    char c;
    puts("Enter a stream of characters:");
    
while((c=getchar())!='\n')
{
    if(isalpha(c))
    putchar(c);
}
    return 0;
}
#include <stdio.h>
#include <string.h>

int main() {
  char str1[] = "abcd", str2[] = "abCd", str3[] = "abcd";
  int result;

  // comparing strings str1 and str2
  result = strcmp(str1, str2);
  printf("strcmp(str1, str2) = %d\n", result);

  // comparing strings str1 and str3
  result = strcmp(str1, str3);
  printf("strcmp(str1, str3) = %d\n", result);

  return 0;
}
#include <stdio.h>
#include <string.h>

int main() {
  char str1[] = "abcd", str2[] = "abCd", str3[] = "abcd";
  int result;

  // comparing strings str1 and str2
  result = strcmp(str1, str2);
  printf("strcmp(str1, str2) = %d\n", result);

  // comparing strings str1 and str3
  result = strcmp(str1, str3);
  printf("strcmp(str1, str3) = %d\n", result);

  return 0;
}
#include <stdio.h>

int main() {
    
    int size = 5;
    
    //printf(">\n");
    //scanf("%d",&size);
    
    for(int h = 0; h < size; h++)
    {
        for(int i = size - h; i>=0; i--) //5-1-2-3-4 print spaces...
        {
            printf(" ");
        }
        
        for(int w = 0; w < h*2+1; w++) //column
        {
            printf("*");
        }
        printf("\n");

    } //first half of the triangle ends
    
    for(int h = size -2; h >= 0; h--) //second half,upside down triangle begins
    {
        for(int i = size - h; i >= 0; i--) //printing space
        {
            printf(" ");
        }
        
        for(int w = 0 ;w < h*2+1; w++)
        {
            printf("*");
        }
        printf("\n");
    }
   return 0;
}
    
#include <stdio.h>

int main() {
    int num, count_pos = 0, count_neg = 0;

    // Prompting the user to input a whole number
    printf("Enter a whole number: \n");
    scanf("%d", &num);

    // Loop for positive numbers
    for (int i = 1; i <= num; i++) {
        if (i % 7 == 0) {
            count_pos++;
        }
    }

    // Loop for negative numbers
    for (int i = -1; i >= num; i--) {
        if (i % 7 == 0) {
            count_neg++;
        }
    }

    // Adding the counts together
    int total_count = count_pos + count_neg;
    
    if(num<=0)
    {
        total_count = total_count +1;
    }
    // Displaying the count to the user
    printf("%d numbers between 1 and %d are \ndivisible by seven with no remainder.\n", total_count, num);

    return 0;
}
#include <stdio.h>

int main() {
    int num, sum = 0, count = 0;

    printf("Number (-1 to stop)? \n");
    while (1) {
        scanf("%d", &num);
        if (num == -1) {
            if (count == 0) {
                printf("No numbers input.\n");
                return 0;
            } else {
                break;
            }
        }
        sum += num;
        count++;
        printf("Number (-1 to stop)? \n");
    }

    int average = (int)sum / count;

    if (count == 1) {
        printf("\nThe average of the 1 number input is %d\n", average);
    } else {
        printf("\nThe average of the %d numbers input is %d\n", count, average);
    }

    return 0;
}
#include <stdio.h>
#include <ctype.h>

int main() {
    char c;
printf("Enter a stream of characters:");
    while((c=getchar())!= '\n')
{
    
    if(isalpha(c))
    {
    if((c=='a')||(c=='e')||(c=='i')||(c=='o')||(c=='u')||(c=='A')||(c=='E')||(c=='I')||(c=='O')||(c=='U'))
    putchar(toupper(c));
    else
    putchar(tolower(c));
    }
}

    return 0;
}
#include <stdio.h>

int byte2bits(int x);
int bits2byte(int x);

int main() {
    int choice, answer, byte, bit; 
    
    printf("[1] Byte to Bits [8] Bits to Byte [0] Exit\n");
    printf("Enter Choice:");
    scanf("%d", &choice);
    
    switch(choice)
{
    case 1:printf("Enter the number of byte:");
            scanf("%d", &byte);
            answer=byte2bits(byte);
            printf("%d byte/s = %d bit/s", byte, answer);
            
    break;
    case 8:printf("Enter the number of bits:");
            scanf("%d", &bit);
            answer=bits2byte(bit);
            printf("%d bit/s = %d byte/s", bit, answer);
            
    break;
    case 0:printf("\n\nExited Succesfully!");
    break;
}
}
int byte2bits(int x)
{
return(x*8);
}
int bits2byte(int x)
{
return(x/8);
}
#include <stdio.h>

float area(float r);

int main() {
    float radius, AOC;
    printf("--Area of Circle--\n");
    printf("Enter the radius of the circle:");
    scanf("%f", &radius);
    
    AOC=area(radius);
    printf("The area of the circle is %.2f", AOC);

}
float area(float r)
{
return(3.14159265359*r*r);
}
#include <stdio.h>
float convert(float x);


int main() {
    float inch, centimeter;
    printf("--Inch to Centimeter Convertion--\n");
    printf("Enter a number: ");
    scanf("%f", &inch);
    
    centimeter=convert(inch);
    printf("%.2f\' is equivalent to %.2f cm", inch, centimeter);
    
    return 0;
}

float convert(float x)
{
    return(x*2.54);
}
#include <stdio.h>
#include <ctype.h>

int main() {
    char c;
//Write a program that will accept a series of characters, display the vowels int
// small letters and display the consonants in capital letters

    while((c=getchar())!='\n')
    {
        if(c=='a')||(c=='e')||(c=='i')||(c=='o')||(c=='u')||(c=='A')||(c=='E')||(c=='I')||(c=='O')||(c=='U')
        putchar(tolower(c));
        
        else
        putchar(toupper(c));
    }
    
    return 0;
}
#include <stdio.h>
#include <ctype.h>

int main() {
    char c;
    while ((c=getchar()) != '\n')
    {
        if (isalpha(c))
            putchar(c);
        else if (isdigit(c))
    {
            putchar(c);
            putchar(c);
    }
        else
    {
            putchar(c);
            putchar(c);
            putchar(c);
    }
    }
    
    return 0;
}
#include <stdio.h>
#include <ctype.h>

int main() {
    char c1;
    printf("Enter a character:");
    c1=getchar();
    printf("%c", toupper(c1));



    return 0;
}
#include <stdio.h>

int main() {
    char c1;
    printf("Enter a character:");
    c1=getchar();
    putchar(c1);

    return 0;
}
#include <stdio.h>

int main() {
    printf("AP SERIES CREATOR\n\");
    printf("Please Enter The values, To Create Your AP Series \n");
    
    int n;
    printf("Enter The Value Of N'th Term : ");
    scanf("%d",&n);
    
    int m;
    printf("Enter The Starting Number of AP : ");
    scanf("%d",&m); 
    
    int p;
    printf("Enter The Defferance Between Two Numbers Of AP : ");
    scanf("%d",&p);
    
     printf("Your AP Series Is : \n");
    for(int i=m;i<=(2*n-1);i=i+p){
        printf("%d\t",i);
    }
    return 0;
}
#include<stdio.h>

int main ()
{
    char word[128];
    int i = 0;
    
    printf("Enter a word to encrypt:\n");
    scanf(" %s",word);
    
    while(word[i]!='\0')
    {
        if(word[i]=='Z')
        {
            word[i] -=26;
        }
        else if(word[i]=='z')
        {
            word[i] -=26;
        }
        word[i] ++;
        
         // Handle edge cases
        
        
        i++;
    }
    
    printf("Encrypted: %s",word);
    
return 0;
}
#include <stdio.h>

int main ()
{
    char name[21];
    
    printf("Please enter your name:\n");
    scanf("%20[^\n]",name);
    
    for(int i =0;name[i];i++)
    {
        if(name[i] >= 'a'&& name[i] <='z')
        {
            name[i] -= 32;
        }
    }
    printf("%s",name);
    
    return 0;
}
#include <stdio.h>
#include <string.h>

int main() {
    char word1[100], word2[100];
    int freq1[26] = {0}, freq2[26] = {0};

    // Prompt user to enter the first word
    printf("Word 1: \n");
    scanf("%s", word1);

    // Prompt user to enter the second word
    printf("Word 2: \n\n");
    scanf("%s", word2);

    // Count frequency of each letter in word1
    for (int i = 0; i < strlen(word1); i++) {
        if ((word1[i] >= 'a' && word1[i] <= 'z') || (word1[i] >= 'A' && word1[i] <= 'Z')) {
            if (word1[i] >= 'A' && word1[i] <= 'Z') {
                freq1[word1[i] - 'A']++;
            } else {
                freq1[word1[i] - 'a']++;
            }
        }
    }

    // Count frequency of each letter in word2
    for (int i = 0; i < strlen(word2); i++) {
        if ((word2[i] >= 'a' && word2[i] <= 'z') || (word2[i] >= 'A' && word2[i] <= 'Z')) {
            if (word2[i] >= 'A' && word2[i] <= 'Z') {
                freq2[word2[i] - 'A']++;
            } else {
                freq2[word2[i] - 'a']++;
            }
        }
    }

    // Compare the frequency arrays
    int match = 1;
    for (int i = 0; i < 26; i++) {
        if (freq1[i] != freq2[i]) {
            match = 0;
            break;
        }
    }

    // Print the result
    if (match) {
        printf("YES! %s and %s\n", word1, word2);
    } else {
        printf("NO!\n");
    }

    return 0;
}

#include <stdio.h>

int main() {
    
    float cp,sp;
    
    printf("Enter The Cost Price : ");
    scanf("%f",&cp);
    
    printf("Enter The Selling Price : ");
    scanf("%f",&sp);
    
    float p,l;
    p=(sp-cp);
    l=(cp-sp);
    
    if(cp>sp){
        printf("\nLoss = %f",l);
    }
    if(sp>cp){
        printf("\nProfit = %f ",p);
    }
   if(sp==cp){
        printf("\nNo Loss , No Profit");
    }
    return 0;
}
#include <stdio.h>

int main() {
    
    int a;
    
    printf("Enter The Value Of Integer : ");
    scanf("%d",&a);
    
    int b; 
    b = a*(-1);
    
    if(a>0){
        printf("\n %d Is The Absolute Value Of That Integer.",a);
    }
    if(a<0){
        printf("\n %d Is The Absolute Value Of That Integer.",b);
    }
    return 0;
}
/**
 * C program to find all roots of a quadratic equation
 */

#include <stdio.h>
#include <math.h> /* Used for sqrt() */

int main()
{
    float a, b, c;
    float root1, root2, imaginary;
    float discriminant;
    
    printf("Enter values of a, b, c of quadratic equation (aX^2 + bX + c): ");
    scanf("%f%f%f", &a, &b, &c);
    
    /* Find discriminant of the equation */
    discriminant = (b * b) - (4 * a * c);
    
   
    /* Find the nature of discriminant */
    if(discriminant > 0)
    {
        root1 = (-b + sqrt(discriminant)) / (2*a);
        root2 = (-b - sqrt(discriminant)) / (2*a);

        printf("Two distinct and real roots exists: %.2f and %.2f", root1, root2);
    }
    else if(discriminant == 0)
    {
        root1 = root2 = -b / (2 * a);

        printf("Two equal and real roots exists: %.2f and %.2f", root1, root2);
    }
    else if(discriminant < 0)
    {
        root1 = root2 = -b / (2 * a);
        imaginary = sqrt(-discriminant) / (2 * a);

        printf("Two distinct complex roots exists: %.2f + i%.2f and %.2f - i%.2f", 
                root1, imaginary, root2, imaginary);
    }

    return 0;
}
/**
 * C program to count minimum number of notes in an amount
 */
 
#include <stdio.h>

int main()
{
    int amount;
    int note500, note100, note50, note20, note10, note5, note2, note1;
    
    /* Initialize all notes to 0 */
    note500 = note100 = note50 = note20 = note10 = note5 = note2 = note1 = 0;


    /* Input amount from user */
    printf("Enter amount: ");
    scanf("%d", &amount);


    if(amount >= 500)
    {
        note500 = amount/500;
        amount -= note500 * 500;
    }
    if(amount >= 100)
    {
        note100 = amount/100;
        amount -= note100 * 100;
    }
    if(amount >= 50)
    {
        note50 = amount/50;
        amount -= note50 * 50;
    }
    if(amount >= 20)
    {
        note20 = amount/20;
        amount -= note20 * 20;
    }
    if(amount >= 10)
    {
        note10 = amount/10;
        amount -= note10 * 10;
    }
    if(amount >= 5)
    {
        note5 = amount/5;
        amount -= note5 * 5;
    }
    if(amount >= 2)
    {
        note2 = amount /2;
        amount -= note2 * 2;
    }
    if(amount >= 1)
    {
        note1 = amount;
    }

    /* Print required notes */
    printf("Total number of notes = \n");
    printf("500 = %d\n", note500);
    printf("100 = %d\n", note100);
    printf("50 = %d\n", note50);
    printf("20 = %d\n", note20);
    printf("10 = %d\n", note10);
    printf("5 = %d\n", note5);
    printf("2 = %d\n", note2);
    printf("1 = %d\n", note1);

    return 0;
}
#include <stdio.h>

int main()
{
    int month;

    /* Input month number from user */
    printf("Enter month number (1-12): ");
    scanf("%d", &month);


    if(month == 1)
    {
        printf("31 days");
    }
    else if(month == 2)
    {
        printf("28 or 29 days");
    }
    else if(month == 3)
    {
        printf("31 days");
    }
    else if(month == 4)
    {
        printf("30 days");
    }
    else if(month == 5)
    {
        printf("31 days");
    }
    else if(month == 6)
    {
        printf("30 days");
    }
    else if(month == 7)
    {
        printf("31 days");
    }
    else if(month == 8)
    {
        printf("31 days");
    }
    else if(month == 9)
    {
        printf("30 days");
    }
    else if(month == 10)
    {
        printf("31 days");
    }
    else if(month == 11)
    {
        printf("30 days");
    }
    else if(month == 12)
    {
        printf("31 days");
    }
    else
    {
        printf("Invalid input! Please enter month number between (1-12).");
    }

    return 0;
#include <stdio.h>

int main()
{
    char ch;

  
    printf("Enter any character: ");
    scanf("%c", &ch);


    
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || 
       ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
    {
        printf("\n'%c' is Vowel.", ch);
    }
    else if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
    {
        
        printf("\n'%c' is Consonant.", ch);
    }
    else 
    {
       
        printf("\n'%c' is not an alphabet.", ch);
    }

    return 0;
}
#include <stdio.h>

int main() {
    
    int a;
    
    printf("Enter A Year : ");
    scanf("%d",&a);
    
    if(a%4==0){
        printf("\n %d Is A Leap Year",a);
    }
    else{
        printf("\n %d Is Not A Leap Year",a);
    }
    
    return 0;
}
#include <stdio.h>

int main()
{
    int start;
    int end;
    int step_size;
    
    printf("Count down start?\n");
    scanf("%d",&start);
    printf("Count down end?\n");
    scanf("%d",&end);
    printf("Step size?\n");
    scanf("%d",&step_size);

// Perform count down
    printf("%d", start);
    for (int i = start - step_size; i >= end; i -= step_size)
    {
        printf(", %d", i);
    }
    
    
    
    
    return 0;
}
#include <stdio.h>

int main(void)
{
    int number;
    int result = 1;

    // Prompt the user to input a non-negative whole number
    printf("Enter a non-negative whole number: ");
    scanf("%d", &number);

    // Check if the input is negative
    if (number < 0)
    {
        printf("\nBad Input! %d is negative...\n", number);
        return 1; // Terminate the program with an error code
    }

    // Compute the factorial
    for (int i = number; i >= 1; i--)
    {
        result *= i;
    }

    // Display the factorial result
    printf("\n%d! is %d\n", number, result);

    return 0;
}
#include <stdio.h>

int main()
{
    int start;
    int stop;
    int step;
    int iteration;
    
    printf("Starting number:\n");
    scanf("%d",&start);
    printf("Stopping number:\n");
    scanf("%d",&stop);
    printf("Step size:\n");
    scanf("%d",&step);
    
    printf("Using a for loop:\n");
    printf("\nStarting at %d...\n\n",start);
    
    for(int i = start; i<=stop;i+=step)
    {
        printf("In loop: %d...\n",i);
        iteration++;
    }
    
    
    printf("\nStopping at %d...\n",stop);
    printf("\nThis loop did %d iterations.\n",iteration);
    
    
    printf("\n");
    printf("\n");


    return 0;
}
#include <stdio.h>

int main()
{
    char rank;
    char suit;
    char valid_rank[100];
    char valid_suit[100];

    printf("Suit (d/h/s/c):\n");
    scanf(" %c", &suit);

    printf("Rank (A/2/3/4/5/6/7/8/9/T/J/Q/K):\n");
    scanf(" %c", &rank);

    switch(rank)
    {
        case 'A':
            sprintf(valid_rank, "A of");
            break;

        case '2':
            sprintf(valid_rank, "Two of");
            break;

        case '3':
            sprintf(valid_rank, "Three of");
            break;

        case '4':
            sprintf(valid_rank, "Four of");
            break;

        case '5':
            sprintf(valid_rank, "Five of");
            break;

        case '6':
            sprintf(valid_rank, "Six of");
            break;

        case '7':
            sprintf(valid_rank, "Seven of");
            break;

        case '8':
            sprintf(valid_rank, "Eight of");
            break;

        case '9':
            sprintf(valid_rank, "Nine of");
            break;

        case 'T':
            sprintf(valid_rank, "Ten of");
            break;

        case 'J':
            sprintf(valid_rank, "Jack of");
            break;

        case 'Q':
            sprintf(valid_rank, "Queen of");
            break;

        case 'K':
            sprintf(valid_rank, "King of");
            break;

        default:
            printf("Invalid Rank\n");
            return 1;
    }

    switch(suit)
    {
        case 'd':
            sprintf(valid_suit, " Diamonds");
            break;

        case 'h':
            sprintf(valid_suit, " Heart");
            break;

        case 's':
            sprintf(valid_suit, " Spades");
            break;

        case 'c':
            sprintf(valid_suit, " Clubs");
            break;

        default:
            printf("Invalid Suit\n");
            return 1;
    }

    printf("%s%s\n", valid_rank, valid_suit);

    return 0;
}
#include <stdio.h>

int main(void)
{
    int element[100];
    int number_element;
    
    
    printf("Input total number of elements required:\n");
    scanf("%d",&number_element);
    
    for(int i = 0; i < number_element; i++)
    {
       printf("Input element [%d]:\n",i); 
    }
    
    printf("\nBefore insertion:\n"); 
    
    for(int i = 0; i < number_element; i++)
    {
        scanf("%d",&element[i]);
        printf("Element [%d] is %d\n",i,element[i]); 
    }
    
    int new_value;
    int position;
    
    printf("\nInput a new value to insert:\n");
    scanf("%d",&new_value);
    printf("Input where to insert the value %d:\n",new_value);
    scanf("%d",&position);
    
    // Shift elements to make space for new value
    for(int i = number_element; i>position;i--)
    {
        element[i] = element[i-1];
    }
    
    // Insert new value at specified position
    element[position] = new_value;
    number_element ++;

    printf("After insertion:\n");

    for(int i = 0; i < number_element; i++)
    {
        scanf("%d",&element[i]);
        printf("Element [%d] is %d\n",i,element[i]);

        
    }
	return 0;
}
#include <stdio.h>

int main(void)
{
	int number;
	//uncomment to make it pass:
    printf("Input an odd number between 0 and 8: \n");
	scanf("%d", &number);
	switch (number)
	{
		case 1:
			{
				printf("User input ONE\n");
				break;
			}

		case 3:
			{
				printf("User input THREE\n");
				break;
			}

		case 5:
			{
				printf("User input FIVE\n");
				break;
			}

		case 7:
			{
				printf("User input SEVEN\n");
				break;
			}

		default:
			{
				printf("User input does not match ");
				printf("the requirements!\n\n");
				printf("Should be 1, 3, 5, or 7.\n");
				break;
			}
	}

	return 0;
}
#include <stdio.h>
#include <stdlib.h>
// function to calculate current age
void age(int present_date, int present_month, int present_year, int birth_date, int birth_month, int birth_year) {
   int month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
   if (birth_date > present_date) {
      present_date = present_date + month[birth_month - 1];
      present_month = present_month - 1;
   }
   if (birth_month > present_month) {
      present_year = present_year - 1;
      present_month = present_month + 12;
   }
   int final_date = present_date - birth_date;
   int final_month = present_month - birth_month;
   int final_year = present_year - birth_year;
   printf("\nYour Present Age Is : %d Years %d Months %d Days", final_year, final_month, final_date);
}
int main() {
   int present_date;
   printf("Present Date : ");
   scanf("%d",&present_date);
   
   int present_month;
    printf("Present Month : ");
   scanf("%d",&present_month);
   
   int present_year;
    printf("Present Year : ");
   scanf("%d",&present_year);
   
   int birth_date ;
    printf("\nBirth Date : ");
   scanf("%d",&birth_date);
   
   int birth_month;
    printf("Birth Month : ");
   scanf("%d",&birth_month);
   
   int birth_year ;
    printf("Birth Year : ");
   scanf("%d",&birth_year);
   
   age(present_date, present_month, present_year, birth_date, birth_month, birth_year);
   return 0;
}
#include <stdio.h>

int main() {
   
   int a,b,c,d,e;
    printf("Enter 1st number : ");
    scanf("%d",&a);
    
    printf("Enter 2nd number : ");
    scanf("%d",&b);
    
    printf("Enter 3rd number : ");
    scanf("%d",&c);
    
    printf("Enter 4th number : ");
    scanf("%d",&d);
    
    printf("Enter 5th number : ");
    scanf("%d",&e);
    
    
    if (a>b && a>c && a>d && a>e)
    {
        printf("\n%d is Greatest Integer Number among all of those numbers .",a);
    }
    
    if (b>a && b>c && b>d && b>e)
    {
        printf("\n%d is Greatest Integer Number among all of those numbers .",b);
    }
    
    
    if (c>a && c>b && c>d && c>e)
    {
        printf("\n%d is Greatest Integer Number among all of those numbers .",c);
    }
    
    
    if (d>a && d>b && d>c && d>e)
    {
        printf("\n%d is Greatest Integer Number among all of those numbers .",d);
    }
    
    if (e>a && e>b && e>c && e>d)
    {
        printf("\n%d is Greatest Integer Number among all of those numbers .",e);
    }


    return 0;
}
#include<stdio.h>
int main(){
    float Radius;
    printf("Enter Radius : ");
    scanf("%f",&Radius);

    float Area = (3.141592653589793238462643383279502884197*Radius*Radius);
    printf ("The Area of the circle is : %f " , Area);

    return 0;
}
#include <stdio.h>
 
int main(){
 
  
 
  float x,y;
 
  
 
  printf("Enter value of x = ");
 
  scanf ("%f",&x);
 
  
 
  printf("Enter value of y = ");
 
  scanf ("%f",&y);
 
  
 
  float a;
 
  a=x+y;
 
  printf("\nsum is = %f ",a);
 
  
 
  float b;
 
  b=x-y;
 
  printf("\n(x-y) subtration is = %f ",b);
 
  float f;
 
  f=y-x;
 
  printf("\n(y-x) subtration is = %f",f);
 
  
 
  float c;
 
  c=x/y;
 
  printf("\n(x/y) divsion is = %f",c);
 
  
 
  float d;
 
  d=y/x;
 
  printf("\n(y/x) dvision is = %f",d);
 
  
 
  float e;
 
  e=x*y;
 
  printf("\nmultiplction is = %f",e);
 
  
 
   return 0;
 
}
#include <stdio.h>
 
int main() {
    
    float Principal,Rate,Time;
    
    printf("Enter Principal = ");
    scanf("%f",&Principal);
    
    printf("Enter Rate of Interest = ");
    scanf("%f",&Rate);
    
    printf("Enter Time Zone = ");
    scanf("%f",&Time);
    
    float Simple_Interest = (Principal*Rate*Time)/100;
    printf("Your SIMPLE INTEREST is = %f",Simple_Interest);
 
    return 0;
}
#include <stdio.h>

//Sum
float sum(float x, float y);
float difference(float x, float y);
float product(float x, float y);
float quotient(float x, float y);


int main()
{
    float n1, n2;
    float S, D, P, Q;
    char symbol;
    
    printf("Enter two numbers:\n");
    scanf("%f", &n1);
    scanf("  %f", &n2);
    
    printf("[+]Sum [-]Difference [*]Product [/]Quotient [x]Exit\n");
    
    printf("Enter Choice:");
    scanf("%s", &symbol);
    switch(symbol)
    {
    case'+':S=sum(n1, n2);printf("Sum:%.2f", S);
    break;
    case'-':D=difference(n1, n2);printf("Difference:%.2f", D);
    break;
    case'*':P=product(n1, n2);printf("Product:%.2f", P);
    break;
    case'/':Q=quotient(n1, n2);printf("Quotient:%.2f", Q);
    break;
    case'x':printf("Exit!");
    break;
    }

}

float sum(float x, float y)
{
return (x+y);
}
float difference(float x, float y)
{
return (x-y);
}
float product(float x, float y)
{
return (x*y);
}
float quotient(float x, float y)
{
return (x/y);
}
#include <stdio.h>

float sum( float n1, float n2);
int main()
{
    float m, n, total;
    printf("Enter first number:");
    scanf("%f", &m);
    printf("Enter second number:");
    scanf("%f", &n);
    total=sum(m ,n);
    
printf("The sum of the two numbers is %.2f", total);
    
    
}
float sum(float n1, float n2)
{
return (n1+n2);
}
    
    
void ComponentGraphics::UpdateBackground(GLFWwindow* window, Shader shader, ComponentCamera* camera, glm::vec3 difference)
{
    if (camera->getlockParallax() == false)
    {
        if (difference[0] > 0.0001f) //right
        {
            posX -= backgroundSpeed;
        }
        if (difference[0] < -0.0001f) //left
        {
           posX += backgroundSpeed;
        }
    }
    //96.0f / 50.0f, 84.0f / 50.0f
    float CurrentCameraX = camera->getCameraPosition().x;
    UpdateGraphics(0.0001, window, shader, camera, ConvertTo4x4Affine(AffineScaleMatrix(96.0f / 50.0f, 84.0f / 50.0f) * AffineTranslationMatrix(posX, posY)), "NoCamX");
}

void ComponentGraphics::setBackgroundSpeedFromFile(Stream stream)
{
    backgroundSpeed = StreamReadFloat(stream);
}

void ComponentGraphics::setBackgroundSpeed(float speed)
{
   backgroundSpeed = speed;
}

void ComponentGraphics::setPosFromFile(Stream stream)
{
    posX = StreamReadFloat(stream);
    posY = StreamReadFloat(stream);
}
//------------------------------------------------------------------------------
/*!
\file	ComponentCamera.cpp
\main author: Mary (m.khuu) Camera movement : Riti 
\par	Copyright © 2021 DigiPen (USA) Corporation.
\brief
\reference http://www.opengl-tutorial.org/beginners-tutorials/tutorial-6-keyboard-and-mouse/
*/
//------------------------------------------------------------------------------
#pragma once

//------------------------------------------------------------------------------
// Includes:
//------------------------------------------------------------------------------
#include "ComponentCamera.h"

ComponentCamera::ComponentCamera(void)
{
	ModelMatrix = mat4(0.0f);
	ViewMatrix = mat4(1.0f);
	ProjectionMatrix = mat4(0.0f);
	MVPmatrix = mat4(0.0f);

	position = glm::vec3(0.0f, 0.0f, 1.0f);

	cameraBoundariesMax = glm::vec3(0.0f, 0.0f, 1.0f);
	cameraBoundariesMin = glm::vec3(0.0f, 0.0f, 1.0f);
	cameraSize = glm::vec3(0.0f, 0.0f, 1.0f);
	cameraSpeed = glm::vec3(0.45f, 0.35f, 0.0f);

	horizontalAngle = 3.14f;
	verticalAngle = 0.0f;

	lockParallax = 0;

	lastTime = 0;
}

glm::mat4 ComponentCamera::cameraInput(GLFWwindow* window)
{
	double currentTime = glfwGetTime();
	float deltaTime = float(currentTime - lastTime);

	// Direction : Spherical coordinates to Cartesian coordinates conversion
	glm::vec3 direction(
		cos(verticalAngle) * sin(horizontalAngle),
		sin(verticalAngle),
		cos(verticalAngle) * cos(horizontalAngle)
	);

	// Right vector
	glm::vec3 right = glm::vec3(
		sin(horizontalAngle - 3.14f / 2.0f),
		0,
		cos(horizontalAngle - 3.14f / 2.0f)
	);

	// Up vector
	glm::vec3 up = glm::cross(right, direction);


	//vertical movements currently move diagonally
	if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS)
	{
		position += deltaTime * cameraSpeed[1];
		position -= right * deltaTime * cameraSpeed[1];
	}
	if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS)
	{
		position -= deltaTime * cameraSpeed[1];
		position += right * deltaTime * cameraSpeed[1];
	}

	if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS)
	{
		position += right * deltaTime * cameraSpeed[0];
	}
	if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS)
	{
		position -= right * deltaTime * cameraSpeed[0];
	}

	ProjectionMatrix = glm::ortho((-cameraSize.x / 2), (cameraSize.x / 2), -(cameraSize.y / 2), (cameraSize.y / 2), 0.0f, 100.0f);

	ViewMatrix = glm::lookAt(position, position + direction, up);
	ModelMatrix = glm::mat4(1.0f);

	lastTime = currentTime;
	MVPmatrix = (ProjectionMatrix * ViewMatrix * ModelMatrix);
	return MVPmatrix; //returns MVP matrix
}

glm::mat4 ComponentCamera::tieCameraToPlayer(GLFWwindow* window, glm::vec3 playerPos)
{
	setlockParallax(false);
	glm::vec3 direction(
		cos(verticalAngle) * sin(horizontalAngle),
		sin(verticalAngle),
		cos(verticalAngle) * cos(horizontalAngle)
	);

	glm::vec3 right = glm::vec3(
		sin(horizontalAngle - 3.14f / 2.0f),
		0,
		cos(horizontalAngle - 3.14f / 2.0f)
	);

	glm::vec3 up = glm::cross(right, direction);

	ProjectionMatrix = glm::ortho((-cameraSize.x / 2), (cameraSize.x / 2), -(cameraSize.y / 2), (cameraSize.y / 2), 0.0f, 100.0f);

	vec3 CamPos = getCameraPosition();
	CamPos.x = playerPos.x;
	CamPos.y = playerPos.y;

	if (CamPos.x  - (cameraSize.x / 2) < cameraBoundariesMin[0])
	{
		CamPos.x = cameraBoundariesMin[0] + (cameraSize.x / 2);
	}
	if (CamPos.x + (cameraSize.x / 2) > cameraBoundariesMax[0])
	{
		CamPos.x = cameraBoundariesMax[0] -(cameraSize.x / 2);
	}
	if (CamPos.y < cameraBoundariesMin[1])
	{
		CamPos.y = cameraBoundariesMin[1];
	}


	//uncommented to always lock the center of camera to player
	//when player goes up
	
	if (CamPos.y > cameraBoundariesMax[1])
	{
		CamPos.y = cameraBoundariesMax[1];
	}


	setCameraPosition(CamPos);
	ViewMatrix = glm::lookAt(position, position + direction, up);

	ModelMatrix = glm::mat4(1.0f);

	MVPmatrix = (ProjectionMatrix * ViewMatrix * ModelMatrix);
	return MVPmatrix; //returns MVP matrix
}

void ComponentCamera::UpdateCamera(GLFWwindow* window, Shader shader, glm::vec3 position)
{
	shader.use();
	if (position != glm::vec3(0))
	{
		GLuint MatrixID = glGetUniformLocation(shader.ID, "transformation");
		//glm::matddddd4 MVP = cameraInput(window);
		glm::mat4 MVP = tieCameraToPlayer(window, position);
		glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
	}
}

glm::mat4 ComponentCamera::getModelMatrix()
{
	return ModelMatrix;
}

glm::mat4 ComponentCamera::getViewMatrix()
{
	return ViewMatrix;
}

glm::mat4 ComponentCamera::getProjectionMatrix()
{
	return ProjectionMatrix;
}

glm::mat4 ComponentCamera::getMVPmatrix()
{
	return MVPmatrix;
}

glm::vec3 ComponentCamera::getCameraBoundariesMin()
{
	return cameraBoundariesMin;
}

glm::vec3 ComponentCamera::getCameraBoundariesMax()
{
	return cameraBoundariesMax;
}

glm::vec3 ComponentCamera::getCameraPosition()
{
	return position;
}

glm::vec3 ComponentCamera::getCameraSize()
{
	return cameraSize;
}

bool ComponentCamera::getlockParallax()
{
	return lockParallax;
}

void ComponentCamera::setCameraBoundariesMin(glm::vec3 boundaries)
{
	cameraBoundariesMin = boundaries;
}

void ComponentCamera::setCameraBoundariesMax(glm::vec3 boundaries)
{
	cameraBoundariesMax = boundaries;
}

void ComponentCamera::setCameraPosition(glm::vec3 P)
{
	position = P;
}

void ComponentCamera::setCameraSize(glm::vec3 S)
{
	cameraSize = S;
}

void ComponentCamera::setCameraSpeed(float speedX, float speedY)
{
	cameraSpeed[0] = speedX;
	cameraSpeed[1] = speedY;
}

void ComponentCamera::setCameraSpeedVec(glm::vec3 speed)
{
	cameraSpeed = speed;
}

void ComponentCamera::setMVPmatrix(glm::mat4 matrix)
{
	MVPmatrix = matrix;
}

void ComponentCamera::setlockParallax(bool value)
{
	lockParallax = value;
}
// ---------------------------------------------------------------------------
// Project Name		:	Nook
// File Name		:	LevelSelect.c
// Author			:	Mary Khuu
// Creation Date	:	19 Mar 2021
// Purpose			:	Level Select
//
// All content © 2021 DigiPen (USA) Corporation, all rights reserved.
// ---------------------------------------------------------------------------

#include "framework.h"
#include "AEEngine.h"
#include "Audio.h"
#include "GameStateManager.h"
#include "Sprite.h"
#include "object_data.h"

#include "LevelSelect.h"

//------------------------------------------------------------------------------
// Private Constants:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Private Structures:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Public Variables:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Private Variables:
//------------------------------------------------------------------------------

static vec2 backgroundSize = { 1670.0f, 564.0f };
static vec2 buttonSize = { 100.0f, 30.0f };
static vec2 textSize = { 150.0f, 50.0f };
static vec2 iconSize = { 30.0f, 30.0f };
static vec2 menuPos = { 0.0f, 200.0f };
static vec2 tutorialPos = { 0.0f, 100.0f };
static vec2 level1Pos = { 0.0f, 0.0f };
static vec2 level2Pos = { 0.0f, -100.0f };
static vec2 level3Pos = { 0.0f, -200.0f };

static signed long mouseX, mouseY;
static float mouseInWorldX, mouseInWorldY;

static AEGfxVertexList* bgMesh;
static AEGfxVertexList* buttonMesh;
static AEGfxVertexList* fontMesh;
static AEGfxVertexList* iconMesh;
static AEGfxVertexList* numMesh;

static AEGfxTexture* bgTexture;
static AEGfxTexture* buttonTexture;
static AEGfxTexture* fontTexture;
static AEGfxTexture* iconTexture;
static AEGfxTexture* numTexture;

static TextureOffset numOffsets[10];
static TextureOffset fontOffsets[30];
static int* currentfontOffset = 0;
static int currfontFrame = 0;
static float* fontTime;

//------------------------------------------------------------------------------
// Private Function Declarations:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Public Functions:
//------------------------------------------------------------------------------

void LevelSelectLoad()
{
    /*mesh for bg*/
    AEGfxMeshStart();

    AEGfxTriAdd(
        -backgroundSize.x, -backgroundSize.y, 0xFF00FF00, 0.0f, 1.0f,
        backgroundSize.x, -backgroundSize.y, 0xFF00FF00, 1.0f, 1.0f,
        -backgroundSize.x, backgroundSize.y, 0xFF00FF00, 0.0f, 0.0f);

    AEGfxTriAdd(
        backgroundSize.x, -backgroundSize.y, 0xFF00FF00, 1.0f, 1.0f,
        backgroundSize.x, backgroundSize.y, 0xFF00FF00, 1.0f, 0.0f,
        -backgroundSize.x, backgroundSize.y, 0xFF00FF00, 0.0f, 0.0f);

    bgMesh = AEGfxMeshEnd();
    AE_ASSERT_MESG(bgMesh, "Failed to create button!");

    bgTexture = AEGfxTextureLoad("Assets/CityscapeGrey.png");
    AE_ASSERT_MESG(bgTexture, "Failed to create pTex!!");

    /*mesh for buttons: green*/
    AEGfxMeshStart();

    AEGfxTriAdd(
        -buttonSize.x, -buttonSize.y, 0xFF00FF00, 0.0f, 1.0f,
        buttonSize.x, -buttonSize.y, 0xFF00FF00, 1.0f, 1.0f,
        -buttonSize.x, buttonSize.y, 0xFF00FF00, 0.0f, 0.0f);

    AEGfxTriAdd(
        buttonSize.x, -buttonSize.y, 0xFF00FF00, 1.0f, 1.0f,
        buttonSize.x, buttonSize.y, 0xFF00FF00, 1.0f, 0.0f,
        -buttonSize.x, buttonSize.y, 0xFF00FF00, 0.0f, 0.0f);

    buttonMesh = AEGfxMeshEnd();
    AE_ASSERT_MESG(buttonMesh, "Failed to create button!");

    buttonTexture = AEGfxTextureLoad("Assets/NookButtonBright.png");
    AE_ASSERT_MESG(buttonTexture, "Failed to create texture!");

    /*mesh for hover icon*/
    iconMesh = createQuadMesh(iconSize.x, iconSize.y, 1.0f, 1.0f, "yarn");

    iconTexture = AEGfxTextureLoad("Assets/TempHover.png");
    AE_ASSERT_MESG(iconTexture, "Failed to create texture!");

    /*mesh for text*/
    fontMesh = createQuadMesh(15.0f, 15.0f, 1.0 / 5, 1.0f / 6, "alphabets");

    fontTexture = AEGfxTextureLoad("Assets/NookFontSheet_alphabet.png");
    AE_ASSERT_MESG(fontTexture, "Failed to create texture!");    

    fontOffsets[0].mX = 0.0f;			    fontOffsets[0].mY = 0.0f / 6;  //A
    fontOffsets[1].mX = 1.0f / 5;		    fontOffsets[1].mY = 0.0f / 6;  //B
    fontOffsets[2].mX = 2.0f / 5;			fontOffsets[2].mY = 0.0f / 6;  //C
    fontOffsets[3].mX = 3.0f / 5;			fontOffsets[3].mY = 0.0f / 6;  //D
    fontOffsets[4].mX = 4.0f / 5;			fontOffsets[4].mY = 0.0f / 6;  //E

    fontOffsets[5].mX = 0.0f;			    fontOffsets[5].mY = 1.0f / 6;  //F
    fontOffsets[6].mX = 1.0f / 5;		    fontOffsets[6].mY = 1.0f / 6;  //G
    fontOffsets[7].mX = 2.0f / 5;			fontOffsets[7].mY = 1.0f / 6;  //H
    fontOffsets[8].mX = 3.0f / 5;			fontOffsets[8].mY = 1.0f / 6;  //I
    fontOffsets[9].mX = 4.0f / 5;			fontOffsets[9].mY = 1.0f / 6;  //J

    fontOffsets[10].mX = 0.0f;			    fontOffsets[10].mY = 2.0f / 6;  //K
    fontOffsets[11].mX = 1.0f / 5;		    fontOffsets[11].mY = 2.0f / 6;  //L
    fontOffsets[12].mX = 2.0f / 5;			fontOffsets[12].mY = 2.0f / 6;  //M
    fontOffsets[13].mX = 3.0f / 5;			fontOffsets[13].mY = 2.0f / 6;  //N
    fontOffsets[14].mX = 4.0f / 5;			fontOffsets[14].mY = 2.0f / 6;  //O

    fontOffsets[15].mX = 0.0f;			    fontOffsets[15].mY = 3.0f / 6;  //P
    fontOffsets[16].mX = 1.0f / 5;		    fontOffsets[16].mY = 3.0f / 6;  //Q
    fontOffsets[17].mX = 2.0f / 5;			fontOffsets[17].mY = 3.0f / 6;  //R
    fontOffsets[18].mX = 3.0f / 5;			fontOffsets[18].mY = 3.0f / 6;  //S
    fontOffsets[19].mX = 4.0f / 5;			fontOffsets[19].mY = 3.0f / 6;  //T

    fontOffsets[20].mX = 0.0f;			    fontOffsets[20].mY = 4.0f / 6;  //U
    fontOffsets[21].mX = 1.0f / 5;		    fontOffsets[21].mY = 4.0f / 6;  //V
    fontOffsets[22].mX = 2.0f / 5;			fontOffsets[22].mY = 4.0f / 6;  //W
    fontOffsets[23].mX = 3.0f / 5;			fontOffsets[23].mY = 4.0f / 6;  //X
    fontOffsets[24].mX = 4.0f / 5;			fontOffsets[24].mY = 4.0f / 6;  //Y


    fontOffsets[25].mX = 0.0f;			    fontOffsets[25].mY = 5.0f / 6;   //Z  
    fontOffsets[26].mX = 1.0f / 5;		    fontOffsets[26].mY = 5.0f / 6;  //blank (1)
    fontOffsets[27].mX = 2.0f / 5;			fontOffsets[27].mY = 5.0f / 6;  //blank (2)
    fontOffsets[28].mX = 3.0f / 5;			fontOffsets[28].mY = 5.0f / 6;  //blank (3)
    fontOffsets[29].mX = 4.0f / 5;			fontOffsets[29].mY = 5.0f / 6;  //blank (4)

    /*mesh for numbers*/
    numMesh = createQuadMesh(15.0f, 15.0f, 1.0 / 3, 1.0f / 4, "numbers");

    numTexture = AEGfxTextureLoad("Assets/NookFontSheet_numbers.png");
    AE_ASSERT_MESG(numTexture, "Failed to create texture!");

    numOffsets[0].mX = 0.0f;			    numOffsets[0].mY = 0.0f / 4;  //0
    numOffsets[1].mX = 1.0f / 3;		    numOffsets[1].mY = 0.0f / 4;  //1
    numOffsets[2].mX = 2.0f / 3;			numOffsets[2].mY = 0.0f / 4;  //2
    
    numOffsets[3].mX = 0.0f;			    numOffsets[3].mY = 1.0f / 4;  //3
    numOffsets[4].mX = 1.0f / 3;			numOffsets[4].mY = 1.0f / 4;  //4
    numOffsets[5].mX = 2.0f / 3;			numOffsets[5].mY = 1.0f / 4;  //5
    
    numOffsets[6].mX = 0.0f;		        numOffsets[6].mY = 2.0f / 4;  //6
    numOffsets[7].mX = 1.0f / 3;			numOffsets[7].mY = 2.0f / 4;  //7
    numOffsets[8].mX = 2.0f / 3;			numOffsets[8].mY = 2.0f / 4;  //8
    
    numOffsets[9].mX = 0.0f / 3;			numOffsets[9].mY = 3.0f / 4;  //9
}

void LevelSelectInit()
{
	AEGfxSetBackgroundColor(1.0f, 1.0f, 1.0f);
	AEGfxSetBlendMode(AE_GFX_BM_BLEND);
}

void LevelSelectUpdate(float dt)
{
    /* Tell the compiler that the 'dt' variable is unused. */
    UNREFERENCED_PARAMETER(dt);

    /*draw background*/
    AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
    AEGfxTextureSet(bgTexture, 0, 0);
    AEGfxSetTransparency(1.0f);
    AEGfxSetPosition(-250.0f, 0.0f);
    AEGfxMeshDraw(bgMesh, AE_GFX_MDM_TRIANGLES);

    //draw menu button
    AEGfxSetPosition(menuPos.x, menuPos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    //draw tutorial button
    AEGfxSetPosition(tutorialPos.x, tutorialPos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);
    

    //draw level1 button
    AEGfxSetPosition(level1Pos.x, level1Pos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    //draw level2 button
    AEGfxSetPosition(level2Pos.x, level2Pos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    //draw level3 button
    AEGfxSetPosition(level3Pos.x, level3Pos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    /*MENU*/
    AEGfxSetPosition(menuPos.x - 45.0f, menuPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[12].mX, fontOffsets[12].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(menuPos.x - 13.0f, menuPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(menuPos.x + 15.0f, menuPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[13].mX, fontOffsets[13].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(menuPos.x + 45.0f, menuPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[20].mX, fontOffsets[20].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    /*MENU - end*/

    /*TUTORIAL*/
    AEGfxSetPosition(tutorialPos.x - 86.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[19].mX, fontOffsets[19].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x - 58.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[20].mX, fontOffsets[20].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x - 30.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[19].mX, fontOffsets[19].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[14].mX, fontOffsets[14].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x + 30.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[17].mX, fontOffsets[17].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x + 46.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[8].mX, fontOffsets[8].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x + 65.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[0].mX, fontOffsets[0].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(tutorialPos.x + 90.0f, tutorialPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    /*TUTORIAL - end*/

    /*LEVEL 1*/
    AEGfxSetPosition(level1Pos.x - 85.0f, level1Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level1Pos.x - 60.0f, level1Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level1Pos.x - 34.0f, level1Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[21].mX, fontOffsets[21].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level1Pos.x - 5.0f, level1Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level1Pos.x + 17.5f, level1Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level1Pos.x + 85.0f, level1Pos.y);
    AEGfxTextureSet(numTexture, numOffsets[1].mX, numOffsets[1].mY, 0.0f); // 1
    AEGfxMeshDraw(numMesh, AE_GFX_MDM_TRIANGLES);

    /*LEVEL 1 - end*/

    /*LEVEL 2*/
    AEGfxSetPosition(level2Pos.x - 85.0f, level2Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level2Pos.x - 60.0f, level2Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level2Pos.x - 34.0f, level2Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[21].mX, fontOffsets[21].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level2Pos.x - 5.0f, level2Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level2Pos.x + 17.5f, level2Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level2Pos.x + 85.0f, level2Pos.y);
    AEGfxTextureSet(numTexture, numOffsets[2].mX, numOffsets[2].mY, 0.0f); // 2
    AEGfxMeshDraw(numMesh, AE_GFX_MDM_TRIANGLES);

    /*LEVEL 2 - end*/

    /*LEVEL 3*/
    AEGfxSetPosition(level3Pos.x - 85.0f, level3Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level3Pos.x - 60.0f, level3Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level3Pos.x - 34.0f, level3Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[21].mX, fontOffsets[21].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level3Pos.x - 5.0f, level3Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level3Pos.x + 17.5f, level3Pos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(level3Pos.x + 85.0f, level3Pos.y);
    AEGfxTextureSet(numTexture, numOffsets[3].mX, numOffsets[3].mY, 0.0f); // 3
    AEGfxMeshDraw(numMesh, AE_GFX_MDM_TRIANGLES);

    /*LEVEL 3 - end*/

    /*get the mouse position*/
    AEInputGetCursorPosition(&mouseX, &mouseY);
    AEGfxConvertScreenCoordinatesToWorld(mouseX, mouseY, &mouseInWorldX, &mouseInWorldY);

    /*if menu is hovered*/
    if ((mouseInWorldX > (menuPos.x - buttonSize.x) && mouseInWorldX < (menuPos.x + buttonSize.x)) &&
        (mouseInWorldY > (menuPos.y - buttonSize.y) && mouseInWorldY < (menuPos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(menuPos.x - 140.0f, menuPos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(Menu);
        }
    }

    /*if tutorial is hovered*/
    if ((mouseInWorldX > (tutorialPos.x - buttonSize.x) && mouseInWorldX < (tutorialPos.x + buttonSize.x)) &&
        (mouseInWorldY > (tutorialPos.y - buttonSize.y) && mouseInWorldY < (tutorialPos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(tutorialPos.x - 140.0f, tutorialPos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(Tutorial);
        }
    }

    /*if level1 is hovered*/
    if ((mouseInWorldX > (level1Pos.x - buttonSize.x) && mouseInWorldX < (level1Pos.x + buttonSize.x)) &&
        (mouseInWorldY > (level1Pos.y - buttonSize.y) && mouseInWorldY < (level1Pos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(level1Pos.x - 140.0f, level1Pos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(Demo);
        }
    }

    /*if level2 is hovered*/
    if ((mouseInWorldX > (level2Pos.x - buttonSize.x) && mouseInWorldX < (level2Pos.x + buttonSize.x)) &&
        (mouseInWorldY > (level2Pos.y - buttonSize.y) && mouseInWorldY < (level2Pos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(level2Pos.x - 140.0f, level2Pos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(Level2);
        }
    }

    /*if level3 is hovered*/
    if ((mouseInWorldX > (level3Pos.x - buttonSize.x) && mouseInWorldX < (level3Pos.x + buttonSize.x)) &&
        (mouseInWorldY > (level3Pos.y - buttonSize.y) && mouseInWorldY < (level3Pos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(level3Pos.x - 140.0f, level3Pos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(Level3);
        }
    }
}

void LevelSelectShutdown()
{
    AudioCleanup();
}

void LevelSelectUnload()
{
    // Unload all textures.
    AEGfxTextureUnload(buttonTexture);
    AEGfxTextureUnload(fontTexture);
    AEGfxTextureUnload(bgTexture);
    AEGfxTextureUnload(iconTexture);
    AEGfxTextureUnload(numTexture);

    // Free all meshes.
    AEGfxMeshFree(buttonMesh);
    AEGfxMeshFree(fontMesh);
    AEGfxMeshFree(bgMesh);
    AEGfxMeshFree(iconMesh);
    AEGfxMeshFree(numMesh);
}

//------------------------------------------------------------------------------
// Private Functions:
//------------------------------------------------------------------------------
//if the last time player moved was left
if (!AEInputCheckCurr("A") && lastPlayerDir == 1 && isWalking == 0)
{
  //flip the sprite
  AEGfxTextureSet(playerIdleTexture, 0.0f, 0.0f);
  AEGfxSetFullTransform(curr->pos.x, curr->pos.y, 0.0f, -(curr->width * tile_dim), curr->height * tile_dim);
  isWalking = 0;
}
/*get the mouse x and y position*/
AEInputGetCursorPosition(&mouseX, &mouseY);
AEGfxConvertScreenCoordinatesToWorld(mouseX, mouseY, &mouseInWorldX, &mouseInWorldY);

/*only draw line if it's the wall and left click/hold on mouse occurs*/
if ((mouseInWorldX > (wallX - xHalfSize) && mouseInWorldX < (wallX + xHalfSize)) &&
    (mouseInWorldY > (wallY - yHalfSize) && mouseInWorldY < (wallY + yHalfSize)) &&
    (AEInputCheckCurr(RI_MOUSE_LEFT_BUTTON_DOWN)))
{
  /*mesh for line, needs to be updated with loop*/
  AEGfxMeshStart();

  AEGfxVertexAdd(playerX + xHalfSize, playerY, 0xFFFF0000, 0.0f, 0.0f);
  AEGfxVertexAdd(mouseInWorldX, mouseInWorldY, 0xFFFF0000, 0.0f, 0.0f);

  meshLine = AEGfxMeshEnd();
  AE_ASSERT_MESG(meshLine, "Failed to create line!");

  /*draw line*/
  AEGfxSetRenderMode(AE_GFX_RM_COLOR);
  AEGfxSetPosition(0.0f, 0.0f);
  AEGfxMeshDraw(meshLine, AE_GFX_MDM_LINES_STRIP);
}
// ---------------------------------------------------------------------------
// Project Name		:	Nook
// File Name		:	Menu.c
// Author			:	Rey Rosario, Mary Khuu
// Creation Date	:	25 Jan 2021
// Purpose			:	Main Menu
//
// All content © 2021 DigiPen (USA) Corporation, all rights reserved.
// ---------------------------------------------------------------------------

#include "framework.h"
#include "AEEngine.h"
#include "Audio.h"
#include "GameStateManager.h"
#include "object_data.h"
#include "Sprite.h"

#include "Menu.h"

//------------------------------------------------------------------------------
// Private Constants:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Private Structures:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Public Variables:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Private Variables:
//------------------------------------------------------------------------------

static vec2 backgroundSize = { 1670.0f, 564.0f };
static vec2 buttonSize = { 100.0f, 30.0f };
static vec2 titleSize = { 150.0f, 50.0f };
static vec2 iconSize = { 30.0f, 30.0f };
static vec2 levelPos = { 0.0f, 0.0f };
static vec2 creditsPos = { 0.0f, -100.0f };
static vec2 exitPos = { 0.0f, -200.0f };
static vec2 titlePos = { 0.0f, 150.0f };

static signed long mouseX, mouseY;
static float mouseInWorldX, mouseInWorldY;

static AEGfxVertexList* buttonMesh;
static AEGfxVertexList* titleMesh;
static AEGfxVertexList* bgMesh;
static AEGfxVertexList* fontMesh;
static AEGfxVertexList* iconMesh;

static AEGfxTexture* bgTexture;
static AEGfxTexture* buttonTexture;
static AEGfxTexture* titleTexture;
static AEGfxTexture* fontTexture;
static AEGfxTexture* iconTexture;

TextureOffset titleOffsets[6];
int* currentTitleOffset = 0;
int currTitleFrame = 0;
float* titleTime;

static TextureOffset fontOffsets[30];
static int* currentfontOffset = 0;
static int currfontFrame = 0;
static float* fontTime;

static float bgMusicTimer;

//------------------------------------------------------------------------------
// Private Function Declarations:
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Public Functions:
//------------------------------------------------------------------------------

void MenuLoad()
{
    /*mesh for bg*/
    AEGfxMeshStart();

    AEGfxTriAdd(
        -backgroundSize.x, -backgroundSize.y, 0xFF00FF00, 0.0f, 1.0f,
        backgroundSize.x, -backgroundSize.y, 0xFF00FF00, 1.0f, 1.0f,
        -backgroundSize.x, backgroundSize.y, 0xFF00FF00, 0.0f, 0.0f);

    AEGfxTriAdd(
        backgroundSize.x, -backgroundSize.y, 0xFF00FF00, 1.0f, 1.0f,
        backgroundSize.x, backgroundSize.y, 0xFF00FF00, 1.0f, 0.0f,
        -backgroundSize.x, backgroundSize.y, 0xFF00FF00, 0.0f, 0.0f);

    bgMesh = AEGfxMeshEnd();
    AE_ASSERT_MESG(bgMesh, "Failed to create button!");

    bgTexture = AEGfxTextureLoad("Assets/CityscapeGrey.png");
    AE_ASSERT_MESG(bgTexture, "Failed to create pTex!!");

    /*mesh for buttons: green*/
    AEGfxMeshStart();

    AEGfxTriAdd(
        -buttonSize.x, -buttonSize.y, 0xFF00FF00, 0.0f, 1.0f,
        buttonSize.x, -buttonSize.y, 0xFF00FF00, 1.0f, 1.0f,
        -buttonSize.x, buttonSize.y, 0xFF00FF00, 0.0f, 0.0f);

    AEGfxTriAdd(
        buttonSize.x, -buttonSize.y, 0xFF00FF00, 1.0f, 1.0f,
        buttonSize.x, buttonSize.y, 0xFF00FF00, 1.0f, 0.0f,
        -buttonSize.x, buttonSize.y, 0xFF00FF00, 0.0f, 0.0f);

    buttonMesh = AEGfxMeshEnd();
    AE_ASSERT_MESG(buttonMesh, "Failed to create button!");

    buttonTexture = AEGfxTextureLoad("Assets/NookButtonBright.png");
    AE_ASSERT_MESG(buttonTexture, "Failed to create texture!");

    /*mesh for text*/
    AEGfxMeshStart();

    AEGfxTriAdd(
        -titleSize.x, -titleSize.y, 0xFF00FF00, 0.0f, 1.0f / 6,
        titleSize.x, -titleSize.y, 0xFF00FF00, 1.0f, 1.0f / 6,
        -titleSize.x, titleSize.y, 0xFF00FF00, 0.0f, 0.0f);

    AEGfxTriAdd(
        titleSize.x, -titleSize.y, 0xFF00FF00, 1.0f, 1.0f / 6,
        titleSize.x, titleSize.y, 0xFF00FF00, 1.0f, 0.0f,
        -titleSize.x, titleSize.y, 0xFF00FF00, 0.0f, 0.0f);

    titleMesh = AEGfxMeshEnd();
    AE_ASSERT_MESG(titleMesh, "Failed to create button!");

    titleTexture = AEGfxTextureLoad("Assets/NookLogo.png");
    AE_ASSERT_MESG(titleTexture, "Failed to create texture!");

    titleOffsets[0].mX = 0.0f;			titleOffsets[0].mY = 0.0f;
    titleOffsets[1].mX = 0.0f;			titleOffsets[1].mY = 1.0f / 6;
    titleOffsets[2].mX = 0.0f;			titleOffsets[2].mY = 2.0f / 6;
    titleOffsets[3].mX = 0.0f;			titleOffsets[3].mY = 3.0f / 6;
    titleOffsets[4].mX = 0.0f;			titleOffsets[4].mY = 4.0f / 6;
    titleOffsets[5].mX = 0.0f;			titleOffsets[5].mY = 5.0f / 6;

    /*mesh for hover icon*/
    iconMesh = createQuadMesh(iconSize.x, iconSize.y, 1.0f, 1.0f, "yarn");
    
    iconTexture = AEGfxTextureLoad("Assets/TempHover.png");
    AE_ASSERT_MESG(iconTexture, "Failed to create texture!");

    /*mesh for text*/
    fontMesh = createQuadMesh(15.0f, 15.0f, 1.0 / 5, 1.0f / 6, "alphabets");

    fontTexture = AEGfxTextureLoad("Assets/NookFontSheet_alphabet.png");
    AE_ASSERT_MESG(fontTexture, "Failed to create texture!");
        
    fontOffsets[0].mX = 0.0f;			    fontOffsets[0].mY = 0.0f / 6;  //A
    fontOffsets[1].mX = 1.0f / 5;		    fontOffsets[1].mY = 0.0f / 6;  //B
    fontOffsets[2].mX = 2.0f / 5;			fontOffsets[2].mY = 0.0f / 6;  //C
    fontOffsets[3].mX = 3.0f / 5;			fontOffsets[3].mY = 0.0f / 6;  //D
    fontOffsets[4].mX = 4.0f / 5;			fontOffsets[4].mY = 0.0f / 6;  //E

    fontOffsets[5].mX = 0.0f;			    fontOffsets[5].mY = 1.0f / 6;  //F
    fontOffsets[6].mX = 1.0f / 5;		    fontOffsets[6].mY = 1.0f / 6;  //G
    fontOffsets[7].mX = 2.0f / 5;			fontOffsets[7].mY = 1.0f / 6;  //H
    fontOffsets[8].mX = 3.0f / 5;			fontOffsets[8].mY = 1.0f / 6;  //I
    fontOffsets[9].mX = 4.0f / 5;			fontOffsets[9].mY = 1.0f / 6;  //J

    fontOffsets[10].mX = 0.0f;			    fontOffsets[10].mY = 2.0f / 6;  //K
    fontOffsets[11].mX = 1.0f / 5;		    fontOffsets[11].mY = 2.0f / 6;  //L
    fontOffsets[12].mX = 2.0f / 5;			fontOffsets[12].mY = 2.0f / 6;  //M
    fontOffsets[13].mX = 3.0f / 5;			fontOffsets[13].mY = 2.0f / 6;  //N
    fontOffsets[14].mX = 4.0f / 5;			fontOffsets[14].mY = 2.0f / 6;  //O

    fontOffsets[15].mX = 0.0f;			    fontOffsets[15].mY = 3.0f / 6;  //P
    fontOffsets[16].mX = 1.0f / 5;		    fontOffsets[16].mY = 3.0f / 6;  //Q
    fontOffsets[17].mX = 2.0f / 5;			fontOffsets[17].mY = 3.0f / 6;  //R
    fontOffsets[18].mX = 3.0f / 5;			fontOffsets[18].mY = 3.0f / 6;  //S
    fontOffsets[19].mX = 4.0f / 5;			fontOffsets[19].mY = 3.0f / 6;  //T

    fontOffsets[20].mX = 0.0f;			    fontOffsets[20].mY = 4.0f / 6;  //U
    fontOffsets[21].mX = 1.0f / 5;		    fontOffsets[21].mY = 4.0f / 6;  //V
    fontOffsets[22].mX = 2.0f / 5;			fontOffsets[22].mY = 4.0f / 6;  //W
    fontOffsets[23].mX = 3.0f / 5;			fontOffsets[23].mY = 4.0f / 6;  //X
    fontOffsets[24].mX = 4.0f / 5;			fontOffsets[24].mY = 4.0f / 6;  //Y


    fontOffsets[25].mX = 0.0f;			    fontOffsets[25].mY = 5.0f / 6;   //Z  
    fontOffsets[26].mX = 1.0f / 5;		    fontOffsets[26].mY = 5.0f / 6;  //blank
    fontOffsets[27].mX = 2.0f / 5;			fontOffsets[27].mY = 5.0f / 6;  //blank
    fontOffsets[28].mX = 3.0f / 5;			fontOffsets[28].mY = 5.0f / 6;  //blank
    fontOffsets[29].mX = 4.0f / 5;			fontOffsets[29].mY = 5.0f / 6;  //blank
}

void MenuInit()
{
	AEGfxSetBackgroundColor(0.0f, 0.0f, 0.0f);
    AEGfxSetBlendMode(AE_GFX_BM_BLEND);

    AudioInit();
    bgMusicTimer = 1638.0f; // Roughly 27 seconds
}

void MenuUpdate(float dt)
{
	/* Tell the compiler that the 'dt' variable is unused. */
	UNREFERENCED_PARAMETER(dt);

    /*play bg music*/
    if (bgMusicTimer == 1638.0f)
    {
        playSoundAdvanced("Assets/Sounds/Level2Track.mp3", 0.1f);
    }
        
    /*reset time for bg music loop*/
    if (bgMusicTimer == 0.0f)
    {
        bgMusicTimer = 1638.0f;
    }
    else
    {
        bgMusicTimer--;
    }

    /*draw background*/
    AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
    AEGfxTextureSet(bgTexture, 0, 0);
    AEGfxSetTransparency(1.0f);
    AEGfxSetPosition(-250.0f, 0.0f);
    AEGfxMeshDraw(bgMesh, AE_GFX_MDM_TRIANGLES);
    
    //draw menu button
    AEGfxSetPosition(levelPos.x, levelPos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxSetTransparency(1.0f);
    AEGfxSetBlendColor(0.0f, 0.0f, 0.0, 0.0f);
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    //draw replay button
    AEGfxSetPosition(creditsPos.x, creditsPos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    //draw exit button
    AEGfxSetPosition(exitPos.x, exitPos.y);
    AEGfxTextureSet(buttonTexture, 0, 0); // no texture
    AEGfxMeshDraw(buttonMesh, AE_GFX_MDM_TRIANGLES);

    /*PLAY*/

    AEGfxSetPosition(levelPos.x - 40.0f, levelPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[15].mX, fontOffsets[15].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(levelPos.x - 15.0f, levelPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[11].mX, fontOffsets[11].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(levelPos.x + 10.0f, levelPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[0].mX, fontOffsets[0].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(levelPos.x + 35.0f, levelPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[24].mX, fontOffsets[24].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    /*PLAY - end*/

    /*CREDITS*/
    AEGfxSetPosition(creditsPos.x - 75.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[2].mX, fontOffsets[2].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(creditsPos.x - 45.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[17].mX, fontOffsets[17].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(creditsPos.x - 20.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[4].mX, fontOffsets[4].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(creditsPos.x + 5.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[3].mX, fontOffsets[3].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(creditsPos.x + 25.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[8].mX, fontOffsets[8].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(creditsPos.x + 47.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[19].mX, fontOffsets[19].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(creditsPos.x + 75.0f, creditsPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[18].mX, fontOffsets[18].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    /*CREDITS - end*/

    /*QUIT*/
    AEGfxSetPosition(exitPos.x - 40.0f, exitPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[16].mX, fontOffsets[16].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(exitPos.x - 7.5f, exitPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[20].mX, fontOffsets[20].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(exitPos.x + 17.5f, exitPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[8].mX, fontOffsets[8].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    AEGfxSetPosition(exitPos.x + 40.0f, exitPos.y);
    AEGfxTextureSet(fontTexture, fontOffsets[19].mX, fontOffsets[19].mY, 0.0f);
    AEGfxMeshDraw(fontMesh, AE_GFX_MDM_TRIANGLES);

    /*QUIT - end*/

    animateFrames(&currentTitleOffset, &titleTime, 0.25f, dt);
    checkEndFrames(&currentTitleOffset, 6);
    currTitleFrame = currentTitleOffset;

    /*draw player*/
    AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
    AEGfxSetPosition(titlePos.x, titlePos.y);
    AEGfxTextureSet(titleTexture, titleOffsets[currTitleFrame].mX, titleOffsets[currTitleFrame].mY);
    AEGfxSetTransparency(1.0f);
    AEGfxMeshDraw(titleMesh, AE_GFX_MDM_TRIANGLES);

    /*get the mouse position*/
    AEInputGetCursorPosition(&mouseX, &mouseY);
    AEGfxConvertScreenCoordinatesToWorld(mouseX, mouseY, &mouseInWorldX, &mouseInWorldY);

    /*if demo level is hovered*/
    if ((mouseInWorldX > (levelPos.x - buttonSize.x) && mouseInWorldX < (levelPos.x + buttonSize.x)) &&
        (mouseInWorldY > (levelPos.y - buttonSize.y) && mouseInWorldY < (levelPos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(levelPos.x - 140.0f, levelPos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(LevelSelect);
        }
    }
    /*if credits is hovered*/
    if ((mouseInWorldX > (creditsPos.x - buttonSize.x) && mouseInWorldX < (creditsPos.x + buttonSize.x)) &&
        (mouseInWorldY > (creditsPos.y - buttonSize.y) && mouseInWorldY < (creditsPos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(creditsPos.x - 140.0f, creditsPos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(Credits);
        }
    }

    /*if exit is hovered*/
    if ((mouseInWorldX > (exitPos.x - buttonSize.x) && mouseInWorldX < (exitPos.x + buttonSize.x)) &&
        (mouseInWorldY > (exitPos.y - buttonSize.y) && mouseInWorldY < (exitPos.y + buttonSize.y)))
    {
        // Hover texture
        AEGfxSetRenderMode(AE_GFX_RM_TEXTURE);
        AEGfxSetPosition(exitPos.x - 140.0f, exitPos.y);
        AEGfxTextureSet(iconTexture, 0.0f, 0.0f);
        AEGfxMeshDraw(iconMesh, AE_GFX_MDM_TRIANGLES);

        if (AEInputCheckTriggered(RI_MOUSE_LEFT_BUTTON_DOWN))
        {
            GameStateManagerSetNextState(GsQuit);
        }
    }
}

void MenuShutdown()
{
    // Do not cleanup audio so music continues into credits and level select
}

void MenuUnload()
{
	// Unload all textures.
    AEGfxTextureUnload(buttonTexture);
    AEGfxTextureUnload(titleTexture);
    AEGfxTextureUnload(bgTexture);
    AEGfxTextureUnload(fontTexture);
    AEGfxTextureUnload(iconTexture);

    // Free all meshes.
    AEGfxMeshFree(buttonMesh);
    AEGfxMeshFree(titleMesh);
    AEGfxMeshFree(bgMesh);
    AEGfxMeshFree(fontMesh);
    AEGfxMeshFree(iconMesh);
}
// ---------------------------------------------------------------------------
// Project Name		:	Nook
// File Name		:	Mesh.c
// Author			:	Mary Khuu
// Creation Date	:	19 Feb 2021
// Purpose			:	Deals with all things needed for sprites
// All content © 2021 DigiPen (USA) Corporation, all rights reserved.
// ---------------------------------------------------------------------------

#include "Sprite.h"


//function to create a quadratic mesh
AEGfxVertexList* createQuadMesh(float halfSizeX, float halfSizeY, float u, float v, const char* meshName)
{
	AEGfxVertexList* mesh;

	AEGfxMeshStart();

	AEGfxTriAdd(
		-halfSizeX, -halfSizeY, 0x00FFFFFF, 0.0f, v,
		 halfSizeX, -halfSizeY, 0x00FFFFFF, u, v,
		-halfSizeX, halfSizeY, 0x00FFFFFF, 0.0f, 0.0f);
	AEGfxTriAdd(
		 halfSizeX, -halfSizeY, 0x00FFFFFF, u, v,
		 halfSizeX, halfSizeY, 0x00FFFFFF, u, 0.0f,
		-halfSizeX, halfSizeY, 0x00FFFFFF, 0.0f, 0.0f);

	mesh = AEGfxMeshEnd();
	AE_WARNING_MESG(mesh, "Failed to create %s!", meshName);

	if (mesh != 0)
	{
		return mesh;
	}
	else
	{
		return 0;
	}
}

//same as above but less parameters, assume halfsize is the same in x and y and u = v
AEGfxVertexList* createEqualQuadMesh(float halfSize, float uv, const char* meshName)
{
	AEGfxVertexList* mesh;

	AEGfxMeshStart();

	AEGfxTriAdd(
		-halfSize, -halfSize, 0x00FFFFFF, 0.0f, uv,
		halfSize, -halfSize, 0x00FFFFFF, uv, uv,
		-halfSize, halfSize, 0x00FFFFFF, 0.0f, 0.0f);
	AEGfxTriAdd(
		halfSize, -halfSize, 0x00FFFFFF, uv, uv,
		halfSize, halfSize, 0x00FFFFFF, uv, 0.0f,
		-halfSize, halfSize, 0x00FFFFFF, 0.0f, 0.0f);

	mesh = AEGfxMeshEnd();
	AE_WARNING_MESG(mesh, "Failed to create %s!", meshName);

	if (mesh != 0)
	{
		return mesh;
	}
	else
	{
		return 0;
	}
}

int getMaxFrames(int rows, int columns)
{
	return rows * columns;
}

void animateFrames(int* currentFrame, float* time, float frameDelay, float dt)
{
	(*time) += dt;

	if (*time >= frameDelay)
	{
		(*currentFrame)++;
		*time = 0;
	}
}

void checkEndFrames(int* currentFrame, int maxFrame)
{
	if (*currentFrame >= maxFrame)
	{
		*currentFrame = 0;
	}
}
// ---------------------------------------------------------------------------
// Project Name		:	Nook
// File Name		:	Audio.c
// Author			:	Mary Khuu
// Creation Date	:	15 Mar 2021
// Purpose			:	add audio to the game
// All content © 2021 DigiPen (USA) Corporation, all rights reserved.
// ---------------------------------------------------------------------------

#include "fmod.h"
#include <stdio.h>		// printf()
#include <stdbool.h>	// FALSE
#include "AEEngine.h"

#include "Audio.h"

FMOD_SYSTEM* soundSystem;
FMOD_SOUND* sound;
FMOD_CHANNEL* channel;
FMOD_RESULT result;


// Initialize the Audio System
void AudioInit()
{
	channel = 0;

	// Create and Initialize the FMOD System
	result = FMOD_System_Create(&soundSystem);

	void* extradriverdata = 0;
	result = FMOD_System_Init(soundSystem, 32, FMOD_INIT_NORMAL, extradriverdata);
}

void playSound(bool trigger, const char* file)
{
	// Create and Play the sound
	// Note: this should be generalized for multiple sounds and
	//       be placed in a function to be used outside of init.
	result = FMOD_System_CreateStream(soundSystem, file, FMOD_LOOP_OFF | FMOD_2D, 0, &sound);

	result = FMOD_System_PlaySound(soundSystem, sound, 0, trigger, &channel);
	
}

void playSoundAdvanced(const char* file, float volume)
{
	FMOD_CHANNEL* channel;

	result = FMOD_System_CreateStream(soundSystem, file, FMOD_LOOP_OFF | FMOD_2D, 0, &sound);

	result = FMOD_System_PlaySound(soundSystem, sound, 0, true, &channel);

	result = FMOD_Channel_SetVolume(channel, volume);

	result = FMOD_Channel_SetPaused(channel, false);
}

// Update the Audio System
// Note: this should be called frequently such as every game loop or
//       every time a user enters a command depending on the engine
void AudioUpdate()
{
	result = FMOD_System_Update(soundSystem);
}

// Cleanup the Audio System
void AudioCleanup()
{
	// Release all sounds that have been created
	result = FMOD_Sound_Release(sound);

	// Close and Release the FMOD system
	result = FMOD_System_Close(soundSystem);
	result = FMOD_System_Release(soundSystem);
}

#include <pch.h>
#include "Projects/ProjectTwo.h"
#include "P2_Pathfinding.h"

#pragma region Extra Credit

std::list<AStarPather::Node*> list;
AStarPather::Node map[61][61];

bool ProjectTwo::implemented_floyd_warshall()
{
    return false;
}

bool ProjectTwo::implemented_goal_bounding()
{
    return false;
}

bool ProjectTwo::implemented_jps_plus()
{
    return false;
}
#pragma endregion

bool AStarPather::initialize()
{
    // handle any one-time setup requirements you have

    /*
        If you want to do any map-preprocessing, you'll need to listen
        for the map change message.  It'll look something like this:

        Callback cb = std::bind(&AStarPather::your_function_name, this);
        Messenger::listen_for_message(Messages::MAP_CHANGE, cb);

        There are other alternatives to using std::bind, so feel free to mix it up.
        Callback is just a typedef for std::function<void(void)>, so any std::invoke'able
        object that std::function can wrap will suffice.
    */

    return true; // return false if any errors actually occur, to stop engine initialization
}

void AStarPather::shutdown()
{
    /*
        Free any dynamically allocated memory or any other general house-
        keeping you need to do during shutdown.
    */
}
/*
    This is where you handle pathing requests, each request has several fields:

    start/goal - start and goal world positions
    path - where you will build the path upon completion, path should be
        start to goal, not goal to start
    heuristic - which heuristic calculation to use
    weight - the heuristic weight to be applied
    newRequest - whether this is the first request for this path, should generally
        be true, unless single step is on

    smoothing - whether to apply smoothing to the path
    rubberBanding - whether to apply rubber banding
    singleStep - whether to perform only a single A* step
    debugColoring - whether to color the grid based on the A* state:
        closed list nodes - yellow
        open list nodes - blue

        use terrain->set_color(row, col, Colors::YourColor);
        also it can be helpful to temporarily use other colors for specific states
        when you are testing your algorithms

    method - which algorithm to use: A*, Floyd-Warshall, JPS+, or goal bounding,
        will be A* generally, unless you implement extra credit features

    The return values are:
        PROCESSING - a path hasn't been found yet, should only be returned in
            single step mode until a path is found
        COMPLETE - a path to the goal was found and has been built in request.path
        IMPOSSIBLE - a path from start to goal does not exist, do not add start position to path
*/
PathResult AStarPather::compute_path(PathRequest &request)
{

    //start/goal - start and goal world positions
    GridPos start = terrain->get_grid_position(request.start);
    GridPos goal = terrain->get_grid_position(request.goal);

    terrain->set_color(start, Colors::Red);
    //set color to orange
    terrain->set_color(goal, Colors::Red);

    //request.path.push_back(request.start);


/***********************************A* SEARCH ALGORITHM*********************************/
    //Push Start Node onto the Open List.

    if (request.newRequest)
    {
        for (int i = 0; i <= 40; i++)
        {
            for (int j = 0; j <= 40; j++)
            {
                map[i][j].parent = NULL;
                map[i][j].pos = GridPos{j, i};
                map[i][j].onList_ = onList::NONE;
                map[i][j].cost = 0.0f;
                map[i][j].given = 0.0f;
            }
        }
        list.clear();
        list.push_back(&map[start.col][start.row]);
    }

    //While (Open List is not empty) {
    while (!list.empty())
    {
        //Pop cheapest node off Open List (parent node).
        Node* parentNode = findCheapest(list);
        
        std::list<Node*>::iterator it;
        it = list.begin();
        std::advance(it, findNodeIndex(list, parentNode));
        it = list.erase(it);

        //request.path.push_back(terrain->get_world_position(parentNode->pos));
        //If node is the Goal Node, then path found (RETURN �found�).
        if (parentNode->pos == goal)
        {
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            Node* cur = parentNode;
            while (cur) {
                //push request
                request.path.push_front(terrain->get_world_position(cur->pos));
                //go to next parent
                cur = cur->parent;
            }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

            terrain->set_color(start, Colors::Orange);
            terrain->set_color(goal, Colors::Orange);
            return PathResult::COMPLETE;
        }

        
        bool NW = true;
        bool NE = true;
        bool SE = true;
        bool SW = true;

        //For (all neighboring child nodes)
        for (int i = 1; i <= 8; i++)
        {
            //set parent to parent
            GridPos childPos = getChild(parentNode->pos, i); //get child
            //deleted line
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //Node* oldParent = map[childPos.col][childPos.row].parent;

            if (childPos != parentNode->pos)
            {
                //set map's parent to new parent after getting position
                //map[childNode->pos.col][childNode->pos.row].parent = &map[parentNode->pos.col][parentNode->pos.row];
                
                //grid is on the map and isn't a wall
                if (terrain->is_valid_grid_position(childPos) && !terrain->is_wall(childPos))
                {
                    //i is non diagonals or is a valid diagonal
                    if (i <= 4 || (i == 5 && NE) || (i == 6 && SE) || (i == 7 && SW) || (i == 8 && NW))
                    {
                        //Compute its cost, f(x) = g(x) + h(x)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
                        float given = parentNode->given;
                        if (i >= 4)
                        {
                            //tile is a diagonal
                            given += (float)std::sqrt(2);
                            //map[childPos.col][childPos.row].given = map[parentNode->pos.col][parentNode->pos.row].given + (float)std::sqrt(2);
                        }
                        else
                        {
                            //tile is N, S, W, E
                            given += 1;
                            //map[childPos.col][childPos.row].given = map[parentNode->pos.col][parentNode->pos.row].given + 1;
                        }

                        float h = getHeuristic(request.settings.heuristic, childPos, goal);
                        //map[childPos.col][childPos.row].cost = map[parentNode->pos.col][parentNode->pos.row].given + h * request.settings.weight;
                        float newCost = given + h * request.settings.weight;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

                        //find if child exists on curr list, and assign it
                        map[parentNode->pos.col][parentNode->pos.row].onList_ = assignList(list, map[parentNode->pos.col][parentNode->pos.row].pos);

                        //If child node isn't on Open or Closed list, put it on Open List.
                        if (map[childPos.col][childPos.row].onList_ == onList::NONE)
                        {
////////////////////////////////////////////////////////////////////////////////////////////////////////////
                            map[childPos.col][childPos.row].parent = parentNode;
                            map[childPos.col][childPos.row].given = given;
                            map[childPos.col][childPos.row].cost = newCost;
////////////////////////////////////////////////////////////////////////////////////////////////////////////
                            map[childPos.col][childPos.row].onList_ = onList::OPEN;
                            terrain->set_color(childPos, Colors::Blue);
                            list.push_back(&map[childPos.col][childPos.row]);
                        }
                        //Else if child node is on Open or Closed List,
                        else if (map[childPos.col][childPos.row].onList_ == onList::OPEN || map[childPos.col][childPos.row].onList_ == onList::CLOSE)
                        {
                            //AND this new one is cheaper,
                            //then take the old expensive one off both lists
                            //if oldCost == 0 then it's our first time setting it
                            if (map[childPos.col][childPos.row].cost > newCost)
                            {
                                //and put this new cheaper one on the Open List.
////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                map[childPos.col][childPos.row].parent = parentNode;
                                map[childPos.col][childPos.row].given = given;
                                map[childPos.col][childPos.row].cost = newCost;
////////////////////////////////////////////////////////////////////////////////////////////////////////////
                                map[childPos.col][childPos.row].onList_ = onList::OPEN;
                                terrain->set_color(childPos, Colors::Blue);
                                list.push_back(&map[childPos.col][childPos.row]);
                            }
                            /*
                            else
                            {
                                map[childPos.col][childPos.row].cost = oldCost;
                                map[childPos.col][childPos.row].parent = oldParent;
                            }*/
                        }
                    }
                }
                //grid is valid but the non-diagonals is a wall, skip the diagonals
                else if (terrain->is_valid_grid_position(childPos) && terrain->is_wall(childPos) && i <= 4)
                {
                    if (i == 1) //NORTH
                    {
                        NE = false;
                        NW = false;
                    }

                    if (i == 2) //EAST
                    {
                        NE = false;
                        SE = false;
                    }

                    if (i == 3) //SOUTH
                    {
                        SE = false;
                        SW = false;
                    }

                    if (i == 4) //WEST
                    {
                        SW = false;
                        NW = false;
                    }
                }
            }
        }

/***************************************************************************************************************/
        //Place parent node on the Closed List (we're done with it).
        parentNode->onList_ = onList::CLOSE;
        map[parentNode->pos.col][parentNode->pos.row].onList_ = onList::CLOSE;
        terrain->set_color(parentNode->pos, Colors::Yellow);
        map[parentNode->pos.col][parentNode->pos.row] = *parentNode;
        //If taken too much time this frame (or in single step mode), 
        if (request.settings.singleStep == true)
        {
            //abort search for now and resume next frame (RETURN �working�).
            return PathResult::PROCESSING;
        }
    }
    //Open List empty, thus no path possible (RETURN �fail�).
    return PathResult::IMPOSSIBLE;

}

float AStarPather::getHeuristic(Heuristic method, GridPos position, GridPos goal)
{
    float dx = (float)std::fabs(position.row - goal.row);
    float dy = (float)std::fabs(position.col - goal.col);

    if (method == Heuristic::OCTILE)
    {
        return 1 * (dx + dy) + (float)(sqrt(2) - 2 * 1) * std::min(dx, dy);
    }

    if (method == Heuristic::CHEBYSHEV)
    {
        return 1 * (dx + dy) + (1 - 2 * 1) * std::min(dx, dy);
    }  

    if (method == Heuristic::MANHATTAN)
    {
        return dx + dy;
    }

    if (method == Heuristic::EUCLIDEAN)
    {
        return (float)sqrt(dx * dx + dy * dy);
    }

    return 0.0f;
}

AStarPather::onList AStarPather::assignList(std::list<Node*> list, GridPos position)
{
    //go through list
    for (const Node* node : list)
    {
        //if node exists in list
        //and is labeled as open
        if (node->pos == position && node->onList_ == onList::OPEN)
        {
            //return open
            return onList::OPEN;
        }
        //and is labeled as closed
        if (node->pos == position && node->onList_ == onList::CLOSE)
        {
            //return closed
            return onList::CLOSE;
        }
        //and is labeled as none
        if (node->pos == position && node->onList_ == onList::NONE)
        {
            return onList::NONE;
        }
    }

    //else it's not on either list
    return onList::NONE;
}

GridPos AStarPather::getChild(GridPos node, int i)
{
    GridPos pos;
    if (i == 1) //NORTH
    {
        pos = { node.row + 1, node.col};
    }
    else if (i == 5) //NE
    {
        pos = { node.row + 1, node.col + 1 };
    }
    else if (i == 2) //EAST
    {
        pos = { node.row, node.col + 1};
    }
    else if (i == 6) //SE
    {
        pos = { node.row - 1, node.col + 1 };
    }
    else if (i == 3) //SOUTH
    {
        pos = { node.row - 1, node.col };
    }
    else if (i == 7) //SW
    {
        pos = { node.row - 1, node.col - 1 };
    }
    else if (i == 4) //WEST
    {
        pos = { node.row, node.col - 1};
    }
    else if (i == 8) //NW
    {
        pos = { node.row + 1, node.col - 1};
    }

    return pos;
}

AStarPather::Node* AStarPather::findCheapest(std::list<Node*> list)
{
    Node* cheapestNode;
    float minCost = -1.0f;
    for (Node* node : list)
    {
        if ((node->cost < minCost || minCost == -1.0f) && node->onList_ != onList::CLOSE)
        {
            //is a valid node
            if (terrain->is_valid_grid_position(node->pos) && node->cost >= 0.0f)
            {
                cheapestNode = node;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
                minCost = cheapestNode->cost;
            }
        }
    }

    return cheapestNode;
}

int AStarPather::findNodeIndex(std::list<Node*> list, Node* node)
{
    int i = 0;
    int index = 0;
    for (Node* node_ : list)
    {
        if (node_->pos == node->pos)
        {
                index = i;
        }
        i++;
    }

    return index;
}
#include <stdio.h>

int main() {
    int x[5]={8, 10, 6, 2, 4};
    int temp, i, j;
    
    for(i=0; i<=4; i++)
        for(j=0; j<4; j++)
        
            if(x[j] > x[j+1])
            {
                temp=x[j];
                x[j]=x[j+1];
                x[j+1]= temp;
            }
    for(i=0; i<=4; i++)
    printf("%d   ", x[i]);
        

    return 0;
}
// Online C compiler to run C program online
#include <stdio.h>

int main() 
{
    int num[3][4];
    int i, j, total=0, average=0;
    int copynum[3][4];
    
printf("Enter 12 numbers:");
//Enter 12 numbers and Print the sum and average
for(i=0; i<=2; i++)
{
    for(j=0; j<=3; j++)
    {
    scanf("%d", &num[i][j]);
    total=total+num[i][j];
    copynum[i][j]=num[i][j];
    }
}
average=total/12;
printf("The sum is %d\n", total);
printf("The average is %d\n", average);

//Print 12 numbers
printf("The 12 integers are:\n");
for(i=0; i<=2; i++)
{
    for(j=0; j<=3; j++)
    printf("%5d", num[i][j]);
    printf("\n");
}
//Display Odd numbers
printf("Odd numbers: ");
for(i=0; i<=2; i++)
{
    for(j=0; j<=3; j++)
    if(num[i][j]%2==1)
    printf("%d  ", num[i][j]);
}
                printf("\n");
//Display Even numbers
printf("Even numbers: ");
for(i=0; i<=2; i++)
{
    for(j=0; j<=3; j++)
    if(num[i][j]%2==0)
    printf("%d  ", num[i][j]);
}
            printf("\n");
//Display the smallest
int small=num[0][0];
for(i=0; i<=2; i++)
    for(j=0; j<=3; j++)
    {
        if(num[i][j] < small)
        small=num[i][j];
    }
printf("The smallest number is: %d", small);
                printf("\n");
//Display the biggest
int big=num[0][0];
for(i=0; i<=2; i++)
    for(j=0; j<=3; j++)
    {
        if(num[i][j] > big)
        big=num[i][j];
    }
printf("The biggest number is: %d", big);
            printf("\n");
 //Display contents of array in reverse order
 printf("The 12 integers in reverse:\n");
for(i=2; i>=0; i--)
{
    for(j=3; j>=0; j--)
    printf("%5d", num[i][j]);
    printf("\n");
}
//Copying a two-dimensional array into another
printf("Copy of Two-Dimensional Array to new Array:");
for(i=0; i<=2; i++)
{
    for(j=0; j<=3; j++)
       printf("%5d", copynum[i][j]);
       printf("\n");
}
   


    return 0;
}
main()
{
  int num[3][4];
  int i. j;
  int total=0, average=0;
  
  printf("Enter 12 numbers:");
  for(i=0; i<=2; i++)
    for(j=0; j<=3; j++)
      {
      scanf("%d", &num[i][j]);
 		 total=total+num[i][j];
      }
  average=total/12;
  
  //display the content of the array
  for(i=0; i<=2; i++)
    for(j=0; j<=3; j++)
      printf("%d", num[i][j]);
  printf("\n");
  
  //display odd numbers
  printf("The odd numbers are:")
  for(i=0; i<=2; i++)
    {
    for(j=0; j<=3; j++)
      if(num[i][j]%2==1)
        printf("%d", num[i][j]);
    }
  
}
#include <stdio.h>
 
int main()
{
   int q[10];
   int sum, average;
   int even=0, odd=0;
   int big=0;
   int copyq[10]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
 
  
   printf("Enter 10 integers:");
  
   for(int i=0; i<=9; i++)//Input
   {
   scanf("%d", &q[i]);
   sum+=q[i];
   copyq[i]=q[i];
   if(q[i]>big)//Bigger Element
   big=q[i];
   }
  
int small=q[0];
for(int i=0; i<=9; i++)//Smallest Element
{
   if(q[i]<small)//Small Element
   small=q[i];
}
  
   printf("Even Numbers:");
   for(int i=0; i<=9; i++)//Even Numbers Displayer
   {
       if(q[i]%2==0)
       printf("%d  ", q[i]);
   }
                                       printf("\n");
  
   printf("Odd Numbers:");
   for(int i=0; i<=9; i++)//Odd Numbers Displayer
   {
       if(q[i]%2==1)
       printf("%d  ", q[i]);
   }
                                       printf("\n");
                                      
 
 
average=sum/10;
printf("Sum: %d\n", sum);
printf("Average: %d\n", average);
printf("Biggest Element: %d\n", big);
printf("Smallest Element: %d", small);
                                   printf("\n");
printf("Displaying in Reverse:");                             
  for(int i=9; i>=0; i--)//Displaying in Reverse
   printf("%d  ", q[i]);
  
printf("\n");
//Copy
printf("New One Dimensional Array originally is: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 \n");
printf("Copy of One-Dimensional Array to new Array:");
for (int i = 0; i < 10; ++i) {
       printf("%d   ", copyq[i]);
   }
  
  
  
  
 
   return 0;
}
#include <stdio.h>

int main()
{
    int q[5], average, total;
    
    printf("Enter 5 quiz scores:");
    for (int i=0; i<=4; i++)
    {
      scanf("%d", &q[i]);  
      total= total+q[i];
    }
    
    
    
    average=total/5;
    
    
    printf("The average is %d", average);
    return 0;
}
#include <stdio.h>
#include <dos.h>
#include <conio.h>



int main()
{
    float sales, salary;
    clrscr();
    
    gotoxy(22, 10);
    printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    gotoxy(22, 11);
    printf("X                                 X");
    gotoxy(22, 12);
    printf("X                                 X");
    gotoxy(22, 13);
    printf("X                                 X");
    gotoxy(22, 14);
    printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    
    gotoxy(25, 11);
    printf("Enter sales in dollars: ");
    scanf("%f", &sales);

    salary = 200 + (sales * .09);
    
    gotoxy(25, 12);
    printf("Salary is: %.2f", salary);
    
    getch();
    return 0;
}
#include <stdio.h>
#include <dos.h>
#include <conio.h>
 
int main()
{
 
   float bal, charge, cred, limit, account, newbal;
   clrscr();
  
   gotoxy(20, 2);
   printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
   gotoxy(20, 3);
   printf("X                                       X");
   gotoxy(20, 4);
   printf("X                                       X");
   gotoxy(20, 5);
   printf("X                                       X");
   gotoxy(20, 6);
   printf("X                                       X");
   gotoxy(20, 7);
   printf("X                                       X");
   gotoxy(20, 8);
   printf("X                                       X");
   gotoxy(20, 9);
   printf("X                                       X");
   gotoxy(20, 10);
   printf("X                                       X");
   gotoxy(20, 11);
   printf("X                                       X");
   gotoxy(20, 12);
   printf("X                                       X");
   gotoxy(20, 13);
   printf("X                                       X");
   gotoxy(20, 14);
   printf("X                                       X");
   gotoxy(20, 15);
   printf("X                                       X");
   gotoxy(20, 16);
   printf("X                                       X");
   gotoxy(20, 17);
   printf("X                                       X");
   gotoxy(20, 18);
   printf("X                                       X");
   gotoxy(20, 19);
   printf("X                                       X");
   gotoxy(20, 20);
   printf("X                                       X");
   gotoxy(20, 21);
   printf("X                                       X");
   gotoxy(20, 22);
   printf("X                                       X");
   gotoxy(20, 22);
   printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");


  
  
  
  gotoxy(26, 5);
   printf("Enter beginning balance:");
   scanf("%f", &bal);
  
   gotoxy(29, 7);
   printf("Enter total charge:");
   scanf("%f", &charge);
  
   gotoxy(28, 9);
   printf("Enter total credits:");
   scanf("%f", &cred);
  
   gotoxy(29, 11);
   printf("Enter credit limit:");
   scanf("%f", &limit);
  
   gotoxy(34, 13);
   printf("Account:");
   scanf("%f", &account);
  
  
   newbal=bal+charge-cred;
 
   gotoxy(30, 15);
   printf("Credit limit: %.2f\n", limit);
  
   gotoxy(34, 17);
   printf("Balance: %.2f\n", newbal);
  
   gotoxy(28, 19);
   (newbal>limit)? printf("Credit Limit Exceeded"): printf("Credit Limit not Exceeded");
  
  

   getch();
   return 0;
}
#include <stdio.h>
#include <conio.h>
#include <dos.h>

int main()
{
    clrscr();
    gotoxy(30, 10);
    
    printf("▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
    
    gotoxy(30, 14);
    
    printf("▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
    
    gotoxy(35, 12 );
    printf("Hello World");
    
    getch();
    return 0;
}
#include <stdio.h>

int main()
{
    int a, b, c, d, e, total;
    
    printf("Total miles driven per day:");
    scanf("%d", &a);
    printf("Cost per gallon of gasoline:");
    scanf("%d", &b);
    printf("Average miles per gallon:");
    scanf("%d", &c);
    printf("Parking fees per days:");
    scanf("%d", &d);
    printf("Tolls per day:");
    scanf("%d", &e);
    
    
    total = (a/c)*b+d+e;
    printf("Cost per Day: %d", total);
    
 
    return 0;
}
#include <stdio.h>

int main()
{
    float radius, diameter, circumference, area, pi=3.14;
    printf("Enter radius:");
    scanf("%f", &radius);
    
    printf("\nDiameter is %.2f\n", radius*2);
    printf("circumference is %.2f\n", 2*radius*pi);
    printf("Area is %.2f\n", pi*radius*radius);
    
    

    return 0;
}
#include<stdio.h>
struct Student{
    int id;
    char name[50];
    char session[50];
    float marks;
};
int main()
{
    int i,j;
    struct Student temp;
    struct Student s[10];

    for(i=0;i<10;i++){
        printf("Enter Data for Student %d:\n",i+1);
        scanf("%d%s%s%f",&s[i].id,&s[i].name,&s[i].session,&s[i].marks);
    }
    for(i=0;i<9;i++){
        for(j=0;j<9;j++){
            if(s[j].marks<s[j+1].marks){
                temp = s[j];
                s[j] = s[j+1];
                s[j+1] = temp;
            }
        }
    }
    printf("\n");
    printf("\n");
    printf("---------------------------\n");
    printf("---------------------------\n");
    for(i=0;i<10;i++){
        printf("Data for Student %d:\n",i+1);
        printf("Id:%d\n",s[i].id);
        printf("Name:%s\n",s[i].name);
        printf("Session:%s\n",s[i].session);
        printf("Marks:%.2f\n",s[i].marks);
    }


    return 0;
}
#include<stdio.h>
#include<math.h>

int main(){
    int i,j,average,sum=0,var=0;
    int marks[] = {4, 4, 7, 7, 9, 8, 1, 10, 7, 3};
    int lenght = 10;
    int largest = marks[0];
    int smallest = marks[0];
    //Smallest and Largest Calculation
    for(i=0;i<lenght;i++){
       if(marks[i] > largest){
            largest = marks[i];
       }
       else if(marks[i] < smallest){
            smallest = marks[i];
       }
       sum += marks[i];
    }
    //Average Calculation
    average = sum / lenght;
    //Variance Calculation
    for(i=0;i<lenght;i++){
        var += pow((average-marks[i]),2);
    }
    //Mode Calculation
    int occurance = 0;
    int max_occurance = 0;
    int max_value;
    for(i=0;i<lenght;i++){
        occurance = 0;
        for(j=0;j<lenght;j++){
            if(marks[i]==marks[j]){
                occurance++;
            }
        }
        if(occurance > max_occurance){
            max_occurance = occurance;
            max_value = marks[i];
        }
    }
    //Printing Values
    printf("Largest: %d\n",largest);
    printf("Smallest: %d\n",smallest);
    printf("Average: %d\n",average);
    printf("Variance: %d\n",var);
    printf("Mod: %d\n",max_value);

    return 0;
}
#include<stdio.h>

int main()
{
    int i,j,count=1;
    int arr[12][15];
    for(i=0;i<12;i++){
        for(j=0;j<15;j++){
            arr[i][j] = count;
            count++;
        }
    }
    for(i=0;i<15;i++){
        printf("%d\t",arr[0][i]);
    }
    printf("\n");
    for(i=0;i<12;i++){
        printf("%d\n\n",arr[i][0]);
    }
    for(i=0;i<7;i++){
        for(j=0;j<15;j++){
            printf("%d\t",arr[i][j]);
        }
        printf("\n");
    }
    printf("\n");
    for(i=11;i>=0;i--){
        for(j=14;j>=0;j--){
            printf("%d\t",arr[i][j]);
        }
        printf("\n");
    }
    return 0;
}
#include<stdio.h>
void diagnal(int arr[10][10]);
int main()
{
    int arr[10][10],i,j,count=1;
    for(i=0;i<10;i++){
        for(j=0;j<10;j++){
            arr[i][j] = count;
            count++;
        }
    }
    for(i=0;i<10;i++){
        for(j=0;j<10;j++){
            printf("%d\t",arr[i][j]);
        }
        printf("\n");
    }
    printf("\n");
    diagnal(arr);
    return 0;
}
void diagnal(int arr[10][10]){
    int i,j;
     for(i=0;i<10;i++){
        for(j=0;j<10;j++){
            if(i==j){
                printf("%d\t",arr[i][j]);
            }
        }
    }
}
#include<stdio.h>

int main()
{
    int i,j,k,m,n,p,q,sum;
    printf("Enter Rows and Columns of Matrix 1:");
    scanf("%d%d",&m,&n);
    printf("Enter Rows and Columns of Matrix 2:");
    scanf("%d%d",&p,&q);
    int a[m][n],b[p][q],c[m][q];
    if(n != p){
        printf("Can't Multiply Matrices");
    }
    else{
    printf("Enter Matrix 1:\n");
    for(i=0;i<m;i++){
        for(j=0;j<n;j++){
            scanf("%d",&a[i][j]);
        }
    }
    printf("Enter Matrix 2:\n");
    for(i=0;i<p;i++){
        for(j=0;j<q;j++){
            scanf("%d",&b[i][j]);
        }
    }
    printf("Matrix 1:\n");
    for(i=0;i<m;i++){
        for(j=0;j<n;j++){
            printf("%d\t",a[i][j]);
        }
        printf("\n");
    }
    printf("Matrix 2:\n");
    for(i=0;i<p;i++){
        for(j=0;j<q;j++){
            printf("%d\t",b[i][j]);
        }
        printf("\n");
    }
    for(i=0;i<m;i++){
        for(j=0;j<q;j++){
            sum = 0;
            for(k=0;k<m;k++){
                sum = sum + a[i][k] * b[k][j];
            }
                c[i][j] = sum;
         }
    }
    printf("Matrix 3:\n");
    for(i=0;i<m;i++){
        for(j=0;j<q;j++){
            printf("%d\t",c[i][j]);
        }
        printf("\n");
    }
    }

    return 0;
}
#include<stdio.h>

int main()
{
    int a[3][3],b[3][3],c[3][3];
    int i,j;
    printf("Enter Matrix 1:\n");
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            scanf("%d",&a[i][j]);
        }
    }
    printf("Enter Matrix 2:\n");
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            scanf("%d",&b[i][j]);
        }
    }
    printf("Matrix 1:\n");
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            printf("%d\t",a[i][j]);
        }
        printf("\n");
    }
    printf("Matrix 2:\n");
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            printf("%d\t",b[i][j]);
        }
        printf("\n");
    }
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            c[i][j] = a[i][j] + b [i][j];
        }
    }
    printf("Matrix 3:\n");
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            printf("%d\t",c[i][j]);
        }
        printf("\n");
    }
    return 0;
}
#include<stdio.h>

int main()
{
    int arr[3][3];
    int i,j,sr,sc;
    printf("Enter Matrix:\n");
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            scanf("%d",&arr[i][j]);
        }
    }
    printf("Matrix is:\n");
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            printf("%d\t",arr[i][j]);
        }
        printf("\n");
    }
    for(i=0;i<3;i++){
        sr = 0;
        sc = 0;
        for(j=0;j<3;j++){
        sr = sr + arr[i][j];
        sc = sc + arr[j][i];
        }
        printf("The Sum of Row is:-----%d\n",sr);
        printf("The Sum of Coloumn is:-%d\n",sc);
    }
    return 0;
}
#include<stdio.h>

int main()
{
    int n=6,i,j,temp,flag;
    int arr[n] = {60,34,76,23,89,29};
    for(i=0;i<n-1;i++){
        flag = 0;
        for(j=0;j<n-1;j++){
            if(arr[j]>arr[j+1]){
                temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
                flag = 1;
            }
        }
        if(flag==0){
            break;
        }
    }
    for(i=0;i<n;i++){
        printf("%d ",arr[i]);
    }
    return 0;
}
#include<stdio.h>

int main()
{
    int arr[8],i,flag=0,n;
    printf("Enter 8 Elements of array:\n");
    for(i=0;i<8;i++){
        printf("arr[%d] = ",i);
        scanf("%d",&arr[i]);
    }
    printf("Enter the element to search in array:");
    scanf("%d",&n);
    for(i=0;i<8;i++){
        if(arr[i] == n){
            flag = 1;
            break;
        }
        else{
            flag = 0;
        }
    }
    if(flag==1){
        printf("The element is found at location : %d",i);
    }
    else{
        printf("Element not found");
    }
    return 0;
}
#include<stdio.h>

int main()
{
    int n=6,i,j,temp;
    int arr[n] = {77,42,35,12,101,5};

    for(i=0;i<n-1;i++){
        for(j=0;j<n-1;j++){
            if(arr[j] > arr[j+1]){
                temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
        }
    }
    for(i=0;i<n;i++){
        printf("%d ",arr[i]);
    }


    return 0;
}
#include <Servo.h> 

Servo servo; // servo object representing the MG 996R servo

void setup() {
  servo.attach(3); // servo is wired to Arduino on digital pin 3
}

void loop() {
  servo.write(0); // move MG996R's shaft to angle 0°
  delay(1000); // wait for one second
  servo.write(45); // move MG996R's shaft to angle 45°
  delay(1000); // wait for one second 
  servo.write(90); // move MG996R's shaft to angle 90°
  delay(1000); // wait for one second
  servo.write(135); // move MG996R's shaft to angle 135°
  delay(1000); // wait for one second
  servo.write(180); // move MG996R's shaft to angle 180°
  delay(1000); // wait for one second
}
#include <stdio.h>
int main() {
   // printf() displays the string inside quotation
   printf("Hello, World!");
   return 0;
}
#include "variadic_functions.h"
#include <stdio.h>
#include <stdarg.h>

/**
 * print_strings - a function that prints strings, followed by a new line.
 *
 * @separator: the string to be printed between numbers
 * @n: the number of strings passed to the function
 *
 * Return: nothing
 */

void print_strings(const char *separator, const unsigned int n, ...)
{
	unsigned int i;
	char *str;
	va_list ap;

	if (separator == NULL)
	{
		separator = "";
	}

	if (n == 0)
	{
		printf("\n");
		return;
	}

	va_start(ap, n);
	for (i = 0; i < n; i++)
	{
		str = va_arg(ap, char *);
		if (str  == NULL)
		{
			printf("(nil)");
		}
		else
		{
			printf("%s", str);

		}
		if (i < (n - 1))
		{
			printf("%s", separator);
		}
	}
	printf("\n");
	va_end(ap);
}
#include <stdio.h>

int main() {
 int a = 10;
 int *p =&a; 
 int b = *p;
 printf("a= %d\n",a);
 printf("adress of a= %d\n",&a);
 printf("value of p= %d\n",p);
printf("address of p= %d\n",&p);
printf("(deref) show the value of stored memory address in p= %d\n",*p);
printf("summary: p= &a ; *p = a | b = %d",b);
}
void main()
{
  printf("Welcome to C programming");
  return;
  clrscrn();
  printf("Welcome");
  return;
}
int do_complex_ops(int,int);

int main(void)
{



int x=0; /*THis is a variable x*/
int y=0; /*This is a variable y*/
int sum =0;

sum = do_complex_ops(x,y);


}


int do_complex_ops(int a,int b)
{
    /*TODO: Currently a STUB. Actual function to replace this*/

    /*FIXME: Need to fix this implementation*/
}
#include <stdio.h>

// Global variable with global scope
int globalVar = 10;

// Function with function scope
void foo() {
    //Note that we are redefining the variable with same name as teh global
    int globalVar;

    //The local Variable is incremented!!!. Not the global one.
    globalVar++;
}

int main() {

    foo();  // Call the function with function scope variable

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


}
#include <stdio.h>

int main() {
    int num = 42;     // An integer variable
    int *pointer;         // A pointer to an integer

    pointer = &num;       // Store the memory address of 'num' in 'ptr'

    // *ptr = 10;        // Change the value of 'num' to 10 through the pointer

    printf("num: %d\n", *pointer);  // This will output "num: 10"

    return 0;
}
#include <stdio.h>
#include<unistd.h>
#include <stdarg.h>
int _putchar(char ch)
{
	write(1, &ch, 1);
	return (1);
;
}

char *conv_val_to_base(long int number, int  base)
{
const  char  items_of_bases[] = "0123456789ABCDEF";
/*A static local variable retains its value across multiple function calls*/
static char buffer[50];
char sign = '0';
char *ptr;
unsigned long nb = number;
if (number < 0)
{
nb = -number;
sign = '-';
}
ptr = &buffer[49];
*ptr =  '\0';
do {
*--ptr =  items_of_bases[nb % base];
nb  /= base;
} while (nb != 0);
if (sign)
*--ptr = sign;
return (ptr);
}
/**
* print_items_of_str  - print chars of strings
* @str: string to print
* Return: number of chars printed
*/
int print_items_of_str(char *str)
{
int len = 0;
while (*str != '\0')
{
_putchar(*str);
str++;
len++;
}
return (len);
}
/**
 * compareStrings - Compare two strings
 * @this_str: String 1
 * @other_str: String 2
 * Return: Integer
 **/
int compareStrings(char *this_str, char *other_str)
{
int i;
for (i = 0; this_str[i] != '\0'; i++)
{
if (this_str[i] != other_str[i])
return (this_str[i] - other_str[i]);
}
return (0);
}
/**
* print_memory_address - print to console the chars of adress
* @list: list of arguments
* Return: number of printed chars
*/
int print_memory_address(va_list list)
{
long  int address_value;
char *ptr;
int len = 0;
address_value =  va_arg(list, unsigned long  int);
ptr = conv_val_to_base(address_value, 16);
/*if ptr is NULL we must return (nil) like the standart lib printf*/
if (!compareStrings(ptr, "0"))
return (print_items_of_str("(nil)"));
/*print the prefix of hexa(0x)*/
len += print_items_of_str("0x");
/*if pointer contains only the value (-1) that's mean*/
/* we are in the maximum adress*/
/*0xFFFFFFFFFFFFFFFF*/
if (!compareStrings(ptr, "-1"))
len += print_items_of_str("ffffffffffffffff");
else
{
/*we have to increment the pointer if  we meet zero in the first index*/
if (ptr[0] != '-' && ptr[0] == '0')
ptr++;
len += print_items_of_str(ptr);
}
return (len);
}

int _printf(const char *form , ... )
{
    va_list list ;
    va_start(list , form);
    print_memory_address(list);
    va_end(list);
    return (0);
}
int main()
{   
    printf("real add = %p\n" , "tc");
    _printf("%p\n", "tc" );

    return 0;
}
#include<stdio.h>
#include<stdio.h>
int max, min;
int a[100];
void maxmin(int i, int j)
{
 int max1, min1, mid;
 if(i==j)
 {
  max = min = a[i];
 }
 else
 {
  if(i == j-1)
  {
   if(a[i] <a[j])
   {
    max = a[j];
    min = a[i];
   }
   else
   {
    max = a[i];
    min = a[j];
   }
  }
  else
  {
   mid = (i+j)/2;
   maxmin(i, mid);
   max1 = max; min1 = min;
   maxmin(mid+1, j);
   if(max <max1)
    max = max1;
   if(min > min1)
    min = min1;
  }
 }
}
int main ()
{
 int i, num;
 printf ("\nEnter the total number of numbers : ");
 scanf ("%d",&num);
 printf ("Enter the numbers : \n");
 for (i=1;i<=num;i++)
  scanf ("%d",&a[i]);

 max = a[0];
 min = a[0];
 maxmin(1, num);
 printf ("Minimum element in an array : %d\n", min);
 printf ("Maximum element in an array : %d\n", max);
 return 0;
}
#include <stdio.h>
int binary_search(int arr[],int l,int h,int key)

    {
	if(l<=h){
    int mid=(l+h)/2;
    if(arr[mid]==key)
        return mid;
    if(arr[mid]>key){
    return binary_search(arr,l,mid-1,key);
    return binary_search(arr,mid+1,h,key);
}

}
return -1;
}
int  bubblesort(int arr[],int n)
    {
	int i,j,temp;
    for(i=0;i<n-1;i++){
        for(j=0;j<n-i-1;j++){
            if(arr[j]>arr[j+1]){
                temp=arr[j];
                arr[j]=arr[j+1];
                arr[j+1]=temp;
                
            }
        }
    }
        return temp;
    }
void printarr(int arr[],int n){
    int i;
    for(i=0;i<n;i++){
        printf("%d",arr[i]);
    }
} 
int main(){
	int n,i,arr[7],key;
    printf("enter the element size\n");
    scanf("%d",&n);
    printf("enter the element you want to sort\n");
    for(i=0;i<n;i++){
        scanf("%d\n",&arr[i]);
    }
    bubblesort(arr,n);
    printarr(arr,n);
    
    printf("\nEnter the element you want to search");
    scanf("%d",&key);
    int result=binary_search(arr,0,n-1,key);
    if (result==-1){
    printf("element not found");
    return 0;
    }
    printf("element found at %d position",result);
return 0;
}
#include <stdio.h>

#define MAX 100

typedef struct Job {
  char id[5];
  int deadline;
  int profit;
} Job;

void jobSequencingWithDeadline(Job jobs[], int n);

int minValue(int x, int y) {
  if(x < y) return x;
  return y;
}

int main(void) {
  //variables
  int i, j;

  //jobs with deadline and profit
  Job jobs[5] = {
    {"j1", 2,  60},
    {"j2", 1, 100},
    {"j3", 3,  20},
    {"j4", 2,  40},
    {"j5", 1,  20},
  };

  //temp
  Job temp;

  //number of jobs
  int n = 5;

  //sort the jobs profit wise in descending order
  for(i = 1; i < n; i++) {
    for(j = 0; j < n - i; j++) {
      if(jobs[j+1].profit > jobs[j].profit) {
        temp = jobs[j+1];
        jobs[j+1] = jobs[j];
        jobs[j] = temp;
      }
    }
  }

  printf("%10s %10s %10s\n", "Job", "Deadline", "Profit");
  for(i = 0; i < n; i++) {
    printf("%10s %10i %10i\n", jobs[i].id, jobs[i].deadline, jobs[i].profit);
  }

  jobSequencingWithDeadline(jobs, n);

  return 0;
}

void jobSequencingWithDeadline(Job jobs[], int n) {
  //variables
  int i, j, k, maxprofit;

  //free time slots
  int timeslot[MAX];

  //filled time slots
  int filledTimeSlot = 0;

  //find max deadline value
  int dmax = 0;
  for(i = 0; i < n; i++) {
    if(jobs[i].deadline > dmax) {
      dmax = jobs[i].deadline;
    }
  }

  //free time slots initially set to -1 [-1 denotes EMPTY]
  for(i = 1; i <= dmax; i++) {
    timeslot[i] = -1;
  }

  printf("dmax: %d\n", dmax);

  for(i = 1; i <= n; i++) {
    k = minValue(dmax, jobs[i - 1].deadline);
    while(k >= 1) {
      if(timeslot[k] == -1) {
        timeslot[k] = i-1;
        filledTimeSlot++;
        break;
      }
      k--;
    }

    //if all time slots are filled then stop
    if(filledTimeSlot == dmax) {
      break;
    }
  }

  //required jobs
  printf("\nRequired Jobs: ");
  for(i = 1; i <= dmax; i++) {
    printf("%s", jobs[timeslot[i]].id);

    if(i < dmax) {
      printf(" --> ");
    }
  }

  //required profit
  maxprofit = 0;
  for(i = 1; i <= dmax; i++) {
    maxprofit += jobs[timeslot[i]].profit;
  }
  printf("\nMax Profit: %d\n", maxprofit);
}
# include<stdio.h>

void knapsack(int n, float weight[], float profit[], float capacity) {
   float x[20], tp = 0;
   int i, j, u;
   u = capacity;

   for (i = 0; i < n; i++)
      x[i] = 0.0;

   for (i = 0; i < n; i++) {
      if (weight[i] > u)
         break;
      else {
         x[i] = 1.0;
         tp = tp + profit[i];
         u = u - weight[i];
      }
   }

   if (i < n)
      x[i] = u / weight[i];

   tp = tp + (x[i] * profit[i]);

   printf("\nThe result vector is:- ");
   for (i = 0; i < n; i++)
      printf("%f\t", x[i]);

   printf("\nMaximum profit is:- %f", tp);

}

int main() {
   float weight[20], profit[20], capacity;
   int num, i, j;
   float ratio[20], temp;

   printf("\nEnter the no. of objects:- ");
   scanf("%d", &num);

   printf("\nEnter the wts and profits of each object:- ");
   for (i = 0; i < num; i++) {
      scanf("%f %f", &weight[i], &profit[i]);
   }

   printf("\nEnter the capacityacity of knapsack:- ");
   scanf("%f", &capacity);

   for (i = 0; i < num; i++) {
      ratio[i] = profit[i] / weight[i];
   }

   for (i = 0; i < num; i++) {
      for (j = i + 1; j < num; j++) {
         if (ratio[i] < ratio[j]) {
            temp = ratio[j];
            ratio[j] = ratio[i];
            ratio[i] = temp;

            temp = weight[j];
            weight[j] = weight[i];
            weight[i] = temp;

            temp = profit[j];
            profit[j] = profit[i];
            profit[i] = temp;
         }
      }
   }

   knapsack(num, weight, profit, capacity);
   return(0);
}
int num_liars = 0, num_liars_left = 0;
        for (int i = 0; i < n; i++) {
            if (claims[i] > 0) {  
                num_liars++; 
                num_liars_left += claims[i] - 1;  
            }
        }

        if (num_liars == 0) { 
            printf("0\n");
        } else if (num_liars > num_liars_left) { 
            printf("-1\n");
        } else {
            int num_truth_tellers = n - num_liars;  
            int num_liars_total = num_liars_left + (num_liars - num_truth_tellers);  
            printf("%d\n", num_liars_total/7);
        }
    }

    return 0;
#define max_size 10000
int stack[max_size];
int top = -1;

void push(char data) 
{
    if (top == max_size-1) 
    {
        printf("Stack Overflow\n");
        return;
    } 
    else 
    {
        stack[++top] = data;
    }
}

int isempty() 
{
    if (top <= -1) 
    {
        return 1;
    }
    return 0;
}

int pop() 
{
    if (isempty()) 
    {
        printf("Stack Underflow\n");
        return -1;
    }
    return stack[top--];
}

bool isValid(char * s)
{
    while(*s!='\0')
    {
        if(*s == '(' || *s == '{' || *s == '[')
        {
            push(*s);
        }
        else if(*s == ')' || *s == '}' || *s == ']')
        {
            if(isempty() || (*s == ')' && pop() != '(') || (*s == '}' && pop() != '{') || (*s == ']' && pop() != '['))
            {
                return 0;
            }
        }
        s++;
    }
    if(isempty())
    {
        return 1;
    }
    else
    {
        return 0;
    }
}#define max_size 10000
int stack[max_size];
int top = -1;

void push(char data) 
{
    if (top == max_size-1) 
    {
        printf("Stack Overflow\n");
        return;
    } 
    else 
    {
        stack[++top] = data;
    }
}

int isempty() 
{
    if (top <= -1) 
    {
        return 1;
    }
    return 0;
}

int pop() 
{
    if (isempty()) 
    {
        printf("Stack Underflow\n");
        return -1;
    }
    return stack[top--];
}

bool isValid(char * s)
{
    while(*s!='\0')
    {
        if(*s == '(' || *s == '{' || *s == '[')
        {
            push(*s);
        }
        else if(*s == ')' || *s == '}' || *s == ']')
        {
            if(isempty() || (*s == ')' && pop() != '(') || (*s == '}' && pop() != '{') || (*s == ']' && pop() != '['))
            {
                return 0;
            }
        }
        s++;
    }
    if(isempty())
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
#include <stdio.h>

void print_number(int num)
{
    unsigned int number;

    if (num < 0)
    {
        number = -num;
        putchar('-');
    }
    else
    {
        number = num;
    }

    if (number / 10)
    {
        print_number(number / 10);
    }
    putchar('0' + (number % 10));
}

int main(void)
{
    int num = 1028;
    print_number(num);
    putchar('\n');
    return (0);
}
#include <stdio.h>
#include <stdarg.h>

//prototypes
void print_string(va_list arg);
void print_letter(va_list arg);
void print_integer(va_list arg);
void print_float(va_list arg);
void print_all(const char * const format, ...);

typedef struct print
{
    char *specifer;
    void(*print_func)(va_list arg);
}  print_t;

/**
 * main - check the code
 *
 * Return: Always 0.
 */

int main(void)
{
    print_all("ceis", 'A', 10, "Hello World");
    return(0);
}

/**
 * print_all- the function prints anything that is passed to the function
 * @format:the chareters that contains specifers
 *
 * Return: the function does not return anything
 */
void print_all(const char * const format, ...)
{
    int i , j, len;
    char *separator = "";
    va_list args;
    va_start(args, format);

    print_t functions[] = {
        {"c", print_letter},
        {"s", print_string},
        {"i", print_integer},
        {"f", print_float}
    };

    len = sizeof(functions) / sizeof(print_t);

    i = 0;

    //checking if format is null or if the current charater is null
    while(format && (*(format + i)))
    {
        j = 0;

        while(j < len && (*(format + i) != *(functions[j].specifer)))
        {
            j++;
        }
        if(j < len)
        {
            printf("%s",separator);
            functions[j].print_func(args);
            separator = ", ";
        }
        i++;
    }

    printf("\n");
    va_end(args);
}


//functions for printing different datatypes
void print_string(va_list arg)
{
    char *str;
    str = va_arg(arg, char*);

    printf("%s", str);
}

void print_letter(va_list arg)
{
    char str;
    str = va_arg(arg, int);

    printf("%c", str);
}

void print_integer(va_list arg)
{
    int num;
    num = va_arg(arg, int);

    printf("%d", num);
}

void print_float(va_list arg)
{
    float num;
    num = va_arg(arg, double);

    printf("%f", num);
}
#include <stdio.h>
#include <stdlib.h>

//prototypes
int add(int , int);
int subtract(int, int);
int multiply(int, int);
int division(int, int);
int module(int,int);

//struct

/**
 * calculator: the struct creates the sign and the associated function
 * @sign the sign for calculation
 * @func: function pointer
 * Return: the function returns the result of the addition
*/
typedef struct calculator{
    char *sign;
    int (*func)(int, int);
} calc_t;

/**
 * main - the function gets commandline arguements and performs calculations on them
 * @argc: the number of commandline arguements
 * @argv: the array containing the arguements
 * 
 * Return: returns zero on success
*/

int main(int argc, char  *argv[]){
    int i, num1, num2, len, result;
    char *sign;

    calc_t functions[]={
        {"+", add},
        {"-", subtract},
        {"*", multiply},
        {"/", division},
        {"%", module}
    };

    if (argc != 4)
        return (0);

    num1 = atoi(argv[1]);
    num2 = atoi(argv[3]);
    sign = argv[2];  //you have to pass the multiplication sign like this "*" for it to work

    len = sizeof(functions) / sizeof(calc_t);

    i  = 0;
    while (i < len)
    {
        if (*(sign) == *(functions[i].sign))
        {
            result = functions[i].func(num1, num2);
            printf("Result: %d\n", result);
        }
        i++;
    }
    return (0);
}


//functions performing the calculations

int add(int a, int b)
{
    return (a + b);
}

int subtract(int a, int b)
{
    return (a - b);
}


int multiply(int a, int b)
{
    return (a * b);
}

int division(int a, int b)
{
    return (a / b);
}

int module(int a,int b)
{
    return (a % b);
}
#include <stdio.h>
#include <stdlib.h>

/**
 * struct dog - creates the dog's information
 * @name: name of the dog
 * @age:age of the dog
 * @owner: owner of the dog
 *
 * Description:the struct creates the info on the dog
 */

struct dog
{
    char *name;
    float age;
    char *owner;
};

typedef struct dog dog_t;

// Fuction prototypes
dog_t *new_dog(char *name, float age, char *owner);
int _strlen(char *str);
char *_strcpy(char *dest, char *src);
void free_dog(dog_t *d);

/**
 * main - check the code
 *
 * Return: Always 0.
 */
int main(void)
{
    dog_t *my_dog;

    my_dog = new_dog("Poppy", 3.5, "Bob");
    printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog->name, my_dog->age);
    free_dog(my_dog);
    return (0);
}

/**
 * _strlen-calculates the length of a string
 * @str: the string
 *
 * Return: returns the size of the string
 */

int _strlen(char *str)
{
    int i, len;

    len = 0;
    for (i = 0; str[i]; i++)
    {
        len++;
    }
    return (len);
}

/**
 * _strcpy- copies one string to another string
 * @dest: where we are coping the string to
 * @src: the source of the string
 *
 * Return: returns a pointer to dest
 */
char *_strcpy(char *dest, char *src)
{
    int i = 0;

    for (i = 0; src[i]; i++)
    {
        dest[i] = src[i];
    }
    dest[i] = '\0';

    return (dest);
}

/**
 * new_dog - the function creates a new dog
 * @name:the name of the dog
 * @age: the age of the dog
 * @owner: the owner of the dog
 *
 * Return: returns a pointer to the new created dog else null
 */

dog_t *new_dog(char *name, float age, char *owner)
{
    dog_t *ptr;
    int name_len;
    int owner_len;

    if (name == NULL || age < 0 || owner == NULL)
        return (NULL);

    ptr = malloc(sizeof(dog_t));
    if (ptr == NULL)
        return (NULL);

    name_len = _strlen(name) + 1;
    ptr->name = malloc(sizeof(char) * name_len);
    if (ptr->name == NULL)
    {
        free(ptr);
        return (NULL);
    }
    owner_len = _strlen(owner) + 1;
    ptr->owner = malloc(sizeof(char) * owner_len);
    if (ptr->owner == NULL)
    {
        free(ptr->name);
        free(ptr);
        return (NULL);
    }
    ptr->age = age;
    ptr->name = _strcpy(ptr->name, name);
    ptr->owner = _strcpy(ptr->owner, owner);

    return (ptr);
}

/**
 * free_dog- a function that frees the created dog
 * @d: pointer to the created dog
 *
 * Return: doesnt return anything
 */

void free_dog(dog_t *d)
{
    if (d == NULL)
        return;

    free(d->name);
    free(d->owner);
    free(d);
}
#include <stdio.h>

/**
 * _strcat- the function concatenates two strings
 * @dest: where we are copying the string to
 * @str: where we are getting the string from
 *
 * Return: returns a pointer to dest
 */

int _strlen(char *str)
{
    int i, len;

    len = 0;
    for (i = 0; str[i]; i++)
    {
        len++;
    }
    return (len);
}

char *_strcat(char *dest, char *src)
{
    int i, dest_len, index;

    dest_len = _strlen(dest);

    index = dest_len;
    dest[index] = ' ';
    index = index + 1;
    for (i = 0; dest[i] && src[i]; i++)
    {
        dest[index] = src[i];
        index++;
    }
    dest[index] = '\0';
    return (dest);
}

int main(void)
{
    char str1[50] = "Hello";
    char str2[] = "Word!";

    char *ptr = _strcat(str1, str2);
    printf("%s\n", ptr);
    return (0);
}
#include <stdio.h>

int _strlen(char *str)
{
    int len, i;

    len = 0;
    for (i = 0; str[i]; i++)
        len++;
    return (len);
}

void reverse_string(char *str)
{
    int i, j, size;
    size = _strlen(str);

    j = 0;
    for (i = size - 1; i > j; i--)
    {
        char temp = str[j];
        str[j] = str[i];
        str[i] = temp;
        j++;
    }
}

int main(void)
{
    char str[] = "JQK";
    reverse_string(str);

    printf("Reversed string: %s\n", str);

    return 0;
}
#include <stdio.h>

/**
 * _strlen-calculates the length of a string
 * @str: the string
 * Return: returns the length of the string
 */

int _strlen(char *str)
{
    int i, len;

    len = 0;
    for (i = 0; str[i]; i++)
    {
        len++;
    }
    return (len);
}
#include <stdio.h>

/**
 * _strcpy-copies the src string to dest
 * @dest: where we are coping the string to
 * @src: the string that we are copying
 *
 * Return: returns a pointer to the dest string
 */

char *_strcpy(char *dest, char *src)
{
    int i;

    for (i = 0; src[i]; i++)
    {
        dest[i] = src[i];
    }
    dest[i] = '\0';
    return (dest);
}

int main()
{
    char str1[20] = "Hello";
    char str2[20];
    char *ptr;

    ptr = _strcpy(str2, str1);

    printf("str1: %s\n", str1);
    printf("str2: %s\n", ptr);

    return 0;
}
#include <stdio.h>

/**
 * _strstr: used to search a given substring in the main string
 * @haystack: the string we are searching the substring  in
 * @needle: the substring we are searching in haystack
 *
 * Return: returns the pointer to the first occurrence of the given substring in the main string.
 */

char *_strstr(char *haystack, char *needle)
{
    int i, j;
    char *start;

    for (i = 0; haystack[i]; i++)
    {
        for (j = 0; needle[j]; j++)
        {
            if (haystack[i + j] != needle[j])
            {
                break;
            }
        }

        if (needle[j] == '\0')
        {
            start = &haystack[i];
            return (start);
        }
    }
    return (NULL);
}

int main()
{
    char main_string[50] = "Hello, how's the weather today?";
    char search_string[30] = "weather";

    char *found_string = _strstr(main_string, search_string);

    if (found_string == NULL)
    {
        printf("Substring not found in the string\n");
    }
    else
    {
        printf("Substring located -> %s\n", found_string);
    }

    return 0;
}
#include <stdio.h>
#include <stdlib.h>
int adjmat[10][10];
struct banks
{
    int netAmount;
    char name;
    char types[3];
};
struct Pair {
    int first;
    char second;
};
int GetMinIndex(struct banks listOfAmounts[],int numBanks)
{
    int min=INT_MAX,minIndex=-1;
    for(int i=0;i<numBanks;i++)
    {
        if(listOfAmounts[i].netAmount==0)
            continue;
        if(listOfAmounts[i].netAmount < min)
        {
            minIndex=i;
            min=listOfAmounts[i].netAmount;
        }
    }
    return minIndex;
}
int getSimpleMaxIndex(struct banks listOfNetAmounts[],int numBanks){
    int max=INT_MIN, maxIndex=-1;
    for(int i=0;i<numBanks;i++){
        if(listOfNetAmounts[i].netAmount == 0) continue;

        if(listOfNetAmounts[i].netAmount > max){
            maxIndex = i;
            max = listOfNetAmounts[i].netAmount;
        }
    }
    return maxIndex;
}/*
struct Pair getMaxIndex(struct banks listOfNetAmounts[], int numBanks, int minIndex, struct banks input[], int maxNumTypes)
{
    int max = INT_MIN;
    int maxIndex = -1;
    char matchingType[100];

    for (int i = 0; i < numBanks; i++) {
        if (listOfNetAmounts[i].netAmount == 0) continue;
        if (listOfNetAmounts[i].netAmount < 0) continue;

        //TODO
        //see complexity of intersection

        char v[maxNumTypes][100];
        char *ls = set_intersection((char *)listOfNetAmounts[minIndex].types, (char *)listOfNetAmounts[minIndex].types + listOfNetAmounts[minIndex].numTypes * 100, (char *)listOfNetAmounts[i].types, (char *)listOfNetAmounts[i].types + listOfNetAmounts[i].numTypes * 100, (char *)v);

        if ((ls - (char *)v) / 100 != 0 && max < listOfNetAmounts[i].netAmount) {
            max = listOfNetAmounts[i].netAmount;
            maxIndex = i;
            strcpy(matchingType, v[0]);
        }
    }

    //if there is NO such max which has a common type with any remaining banks then maxIndex has -1
    // also return the common payment type
    struct pair result;
    result.first = maxIndex;
    strcpy(result.second, matchingType);
    return result;
}*/
struct BankAndType {
    int bankIndex;
    char paymentType;
};

struct BankAndType getMaxIndex(struct banks* listOfNetAmounts, int numBanks, int minIndex, struct banks* input, int maxNumTypes) {
    int max = INT_MIN;
    int maxIndex = -1;
    char matchingType = '\0';

    for (int i = 0; i < numBanks; i++) {
        if (listOfNetAmounts[i].netAmount == 0 || listOfNetAmounts[i].netAmount < 0) {
            continue;
        }

        for (int j = 0; j < listOfNetAmounts[i].types; j++) {
            char currentType = listOfNetAmounts[i].types[j];

            for (int k = 0; k < minIndex; k++) {
                if (listOfNetAmounts[k].netAmount == 0 || listOfNetAmounts[k].netAmount > 0) {
                    continue;
                }

                for (int l = 0; l < listOfNetAmounts[k].types; l++) {
                    if (currentType == listOfNetAmounts[k].types[l]) {
                        if (listOfNetAmounts[i].netAmount > max) {
                            max = listOfNetAmounts[i].netAmount;
                            maxIndex = i;
                            matchingType = currentType;
                        }
                    }
                }
            }
        }
    }

    struct BankAndType result = { maxIndex, matchingType };
    return result;
}
void Minimizecashflow(int numBanks,struct banks input[6],char aindexOf[6],int numTras,int adjmat[6][6],int maxTypes)
{


   struct banks listOfNetAmounts[numBanks];
   for(int b=0;b<numBanks;b++)
   {
       listOfNetAmounts[b].name=input[b].name;
       for(int i=0;i<numBanks;i++)
       {
            listOfNetAmounts[b].types[i]=input[b].types[i];
       }

       int amount=0;
       for(int i=0;i<numBanks;i++){
            amount += (adjmat[i][b]);
        }
       for(int j=0;j<numBanks;j++){
            amount += ((-1) * adjmat[b][j]);
        }


        listOfNetAmounts[b].netAmount = amount;

   }




   struct Pair  ansGraph[numBanks][numBanks];
   int numZeroNetAmounts=0;
   int maxIndex=0;

    for(int i=0;i<numBanks;i++){
        if(listOfNetAmounts[i].netAmount == 0)
            numZeroNetAmounts++;
    }


    while(numZeroNetAmounts!=numBanks){

        int minIndex=GetMinIndex(listOfNetAmounts, numBanks);
        struct Pair maxAns = getMaxIndex(listOfNetAmounts, numBanks, minIndex,input,maxTypes);
        int maxIndex = maxAns.first;

       if(maxIndex == -1){

            (ansGraph[minIndex][0].first) += abs(listOfNetAmounts[minIndex].netAmount);
            //(ansGraph[minIndex][0].second) = *(input[minIndex].types.begin());

            int simpleMaxIndex = getSimpleMaxIndex(listOfNetAmounts, numBanks);
            (ansGraph[0][simpleMaxIndex].first) += abs(listOfNetAmounts[minIndex].netAmount);
           // (ansGraph[0][simpleMaxIndex].second) = *(input[simpleMaxIndex].types.begin());

            listOfNetAmounts[simpleMaxIndex].netAmount += listOfNetAmounts[minIndex].netAmount;
            listOfNetAmounts[minIndex].netAmount = 0;

            if(listOfNetAmounts[minIndex].netAmount == 0) numZeroNetAmounts++;

            if(listOfNetAmounts[simpleMaxIndex].netAmount == 0) numZeroNetAmounts++;

        }
        else{
            int transactionAmount;
            if(listOfNetAmounts[minIndex].netAmount < listOfNetAmounts[maxIndex].netAmount)
            {
                 transactionAmount=listOfNetAmounts[minIndex].netAmount;
            }
            else
            {
                 transactionAmount=listOfNetAmounts[maxIndex].netAmount;
            }

            (ansGraph[minIndex][maxIndex].first) += (transactionAmount);
           // (ansGraph[minIndex][maxIndex].second) = maxAns.second;

            listOfNetAmounts[minIndex].netAmount += transactionAmount;
            listOfNetAmounts[maxIndex].netAmount -= transactionAmount;

            if(listOfNetAmounts[minIndex].netAmount == 0) numZeroNetAmounts++;

            if(listOfNetAmounts[maxIndex].netAmount == 0) numZeroNetAmounts++;
        }

    }

   // printAns(ansGraph,numBanks,input);


}
int main()
{


     printf("\n---------------------------------------------------------------------------------------Welcome to CASH FLOW MINIMIZER SYSTEM--------------------------------------------------------------------------------------\n\n\n");
     int numBanks;
     printf("\nEnter The Number Of Banks:");
     scanf("%d",&numBanks);
     printf("\n----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n\n");




     struct  banks input[numBanks];
     char aindexOf[numBanks];
     int maxTypes;

     printf("Enter The Details Of The Banks and Transactions As Stated:\n");
     printf("Bank Name , Number Of Payment Modes It has and the Payment Modes.\n");
     printf("\n----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n\n");




     for(int i=0;i<numBanks;i++)
     {
         if(i==0)
             printf("WorldBank:");
         else{
             printf("Bank: %d ",i);
         }


         fflush(stdin);
         printf("\nEnter name of bank:");
         fflush(stdin);
         scanf("%c",&input[i].name);
         aindexOf[i]=input[i].name;
         fflush(stdin);
         printf("\nEnter Number Of Modes: ");
         int numTypes;
         scanf("%d",&numTypes);
         printf("\nClick \nPhone pay-1, \nPaytm-2, \nGoogle pay-3::");


         if(i==0)
            maxTypes=numTypes;

           int inputTypesofpayment;
           input[i].types[0]=0;//gpay
           input[i].types[1]=0;//paytm
           input[i].types[2]=0;//phonepe
           while(numTypes--)
           {

               scanf("%d",&inputTypesofpayment);
               input[i].types[inputTypesofpayment]=1;
           }
                 printf("\n----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n\n\n");

     }



     printf("\nEnter number of Trasaction.");
     int NumTras;
     scanf("%d",&NumTras);
     int adjmat[numBanks][numBanks];
     for(int i=0;i<numBanks;i++)
     {
         for(int j=0;j<numBanks;j++){
            adjmat[i][j]=0;
         }

     }




     printf("Debtor Bank , creditor Bank and amount\n");
     for(int i=0;i<NumTras;i++)
     {
         printf("\n%d: th trasaction:",i+1);
         fflush(stdin);
         char fBank,sBank;
         int amount;
         fflush(stdin);
         scanf("%c %c",&fBank,&sBank);
         fflush(stdin);
         scanf("%d",&amount);
         fflush(stdin);
         int retindf=0;
         int retinds=0;
         for(int i=0;i<numBanks;i++)
         {
             //printf("\nI am in");
             if(aindexOf[i]==fBank)
                 retindf=i;
             if(aindexOf[i]==sBank)
                  retinds=i;
         }

        adjmat[retindf][retinds]=amount;

     }


     /*for(int i=0;i<numBanks;i++)
     {
         for(int j=0;j<numBanks;j++){
            printf("%d ",adjmat[i][j]);
         }
         printf("\n");

     }*/


    Minimizecashflow(numBanks,input,aindexOf,NumTras,adjmat,3);

    return 0;

}
//
//  main.c
//  Re40Dia20NF1D2
//
//  Created by Siddhartha Shandilya on 15/04/23.
//

#include<stdio.h>
#include<math.h>

  /*------ Flow in a Square Channel with a particle in between  ---------*/
#define        NF          1
#define        Re          40.0
#define        u_inlet     0.2093333333
#define        NX          801   //no. of nodes in the x-direction
#define        NY          801   //no. of nodes in the y-direction

#define        a           20.0    //particle diameter
#define        radius      10.0     //particle radius
#define        g           400.0   // x-coordinate of the center of the spherical particle
#define        f           400.0   // y-coordinate of the center of the spherical particle
#define        lmtheta     2.25  // angular separation of lagrangian marker
#define        Q           9     // no. of direction of velocity vectors (D2Q9 model implemented)
#define        T           1001 // no. of time steps
#define        tau         0.814  // dimensionless relaxation time due to fluid–particle collisions
#define        visc        (tau-0.5)/3.0 //viscosity
#define        rho0        1.0   // density initialization
//#define      Ht          NY-1.0 //height in vertical direction
#define        pie         3.141592653589 //value of pie
#define        w0          4.0/9.0 // weighting coefficient
#define        w1          1.0/9.0 // weighting coefficients for i = 1,2,3,4
#define        w2          1.0/36.0 // weighting coefficients for i = 5,6,7,8
//#define      Ub          0.0


#define         h           1

double          Cd;
int             k;
int             cx          [Q]={0,1,0,-1,0,1,-1,-1,1}; //discrete velocity vectors
int             cy          [Q]={0,0,1,0,-1,1,1,-1,-1}; // discrete velocity vectors
double          t           [Q]={w0,w1,w1,w1,w1,w2,w2,w2,w2};
int             next_x      [NX][Q];
int             next_y      [NY][Q];
double          SumFX;
double          r;
double          FX          [NX][NY];
double          FY          [NX][NY];
double          f1          [NX][NY][Q];    //main probability distribution function
double          f2          [NX][NY][Q];    //temporary PDF
double          rho         [NX][NY];
double          ux          [NX][NY];
double          uy          [NX][NY];
double          U           [NX][NY];
double          V           [NX][NY];
//double        ux_eq       [NX][NY];
//double        uy_eq       [NX][NY];
double          bnode       [NX][NY];
//double        ux_exact    [NY];

void        tables();
void        initialise();
void        cal_obs();
void        IBM();
void        collision();
void        streaming();
void        data(int, int);
void        data_Cd(int, int);
//void        exact();

int main()
{
    int count = 0;
    tables();
    initialise();
    for(k=0; k<T; k++)
    {
        printf("k=%d\r\t",k);
        cal_obs();
        IBM();
        collision();
        streaming();
        
        if(k%50000==0)
        {
            data(count, k);
        }
        if(k==1000)
        {
            data_Cd(count, k);
        }
    }

    return 0;
}

void tables()
{
    int x,y,i;

    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            for(i=0; i<Q; i++)
            {
                next_x[x][i] = x + cx[i];

                if(next_x[x][i]<0)
                    next_x [x][i] = NX-1;
                if(next_x[x][i]>(NX-1))
                    next_x[x][i] = 0;

                next_y[y][i] = y + cy[i];

                if(next_y[y][i]<0)
                    next_y [y][i] = NY-1;
                if(next_y[y][i]>(NY-1))
                    next_y[y][i] = 0;
            }
        }
    }

    return ;
}


void initialise()
{
    int x,y,i;

    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            rho[x][y] = rho0;
            ux[x][y] = 0.0; uy[x][y] = 0.0;
            
            for(i=0; i<Q; i++)
            {
                f1[x][y][i] = rho0*t[i];

            }
        }
    }

    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            bnode[x][y] = 0.0;
            if(y==0 || y==(NY-1))
            {
                bnode[x][y] = 1.0;
            }
        }
    }

    return ;
}

double cal_dela(int x, int y, double bX, double bY) {
    double rX = x - bX;                      //x-coordinate difference between the current marker and the current node
    double rY = y - bY;                      //y-coordinate difference between the current marker and the current node

    double arX = fabsf(rX);                  //absolute value of 'r'
    double arY = fabsf(rY);                  // ,,

    double delX = 0, delY = 0;               //calculating delta function

    if(arX >= 0 && arX < 1)
        delX = 1/8.0*(3-(2*arX)+sqrt(1+(4*arX)-(4*arX*arX)));
    if(arX >= 1 && arX < 2)
        delX = 1/8.0*(5-(2*arX)-sqrt(-7+(12*arX)-(4*arX*arX)));
    else // |r| >= 2
        delX = 0;


    if(arY >= 0 && arY < 1)                 //calculating delta function (y);
        delY = 1/8.0*(3-(2*arY)+sqrt(1+(4*arY)-(4*arY*arY)));
    if(arY >= 1 && arY < 2)
        delY = 1/8.0*(5-(2*arY)-sqrt(-7+(12*arY)-(4*arY*arY)));
    else // |r| >= 2
        delY = 0;

    double D = delX * delY;                          //calculation of Eq. No. 26
    return D;
}
double delta2(int x, int y, double bX, double bY)

{

    double D;
    double rX = x - bX;                      //x-coordinate difference between the current marker and the current node
    double rY = y - bY;                      //y-coordinate difference between the current marker and the current node
    double arX = fabs(rX);                  //absolute value of 'r'
    double arY = fabs(rY);
    double delX = 0.0; double delY = 0.0;

    if(arX <= 1)

        delX = 1.0 - arX;

    else

        delX = 0.0;

    

    if(arY <= 1)

        delY = 1.0 - arY;

    else

        delY = 0.0;

    

    D = delX * delY;

    

    return D;

}

void cal_obs()
{
    int x,y,i;
    //double dense;

    for(x=0; x<NX; x++)
    {
        for (y=0; y<NY; y++)
        {
            rho[x][y]=0.0; ux[x][y]=0.0; uy[x][y]=0.0;
            //if(bnode[x][y] !=1.0)
            {
                for (i=0; i<Q; i++)
                {
                    rho[x][y]     += f1[x][y][i];
                    ux[x][y]  += f1[x][y][i]*cx[i];
                    uy[x][y]  += f1[x][y][i]*cy[i];
                }
                //rho[x][y] = dense;
                ux[x][y]  = ux[x][y]/rho[x][y];
                uy[x][y]  = uy[x][y]/rho[x][y];
            }
        }
    }
return;
}

void IBM()
{
    double dels = (a * pie * lmtheta)/360.0;             //arc length calculation

    int b = 0;
    int markerCount = 360/lmtheta;                      //calculating no. of markers
    double UbX[markerCount], UbY[markerCount];           //velocities at markers
    double FbX[markerCount], FbY[markerCount];           //forces at markers
    double Fx[NX][NY];
    float  Fy[NX][NY];
    double SumFX;                                    //forces at grids
    for(int i=0; i<markerCount; ++i)
        UbX[i] = 0.0,                                     //initialising to zero
                UbY[i] = 0.0,
                FbX[i] = 0.0,
                FbY[i] = 0.0;

    for(int i=0; i<NX; i++)
        for(int j=0; j<NY; j++) {
            Fx[i][j] = 0.0;
            Fy[i][j] = 0.0;
        }

    //double radius = a/2.0;
    //iterate all the markers one by one
    for(double theta=0; theta<=360; theta+=lmtheta, b+=1)
    {
        double radiantheta = theta * (pie / 180.0);      //converting angle to radian
        double bX = (g + (a/2.0)*cos(radiantheta));        //calculating x-cordinate of lagrangian marker
        double bY = (f + (a/2.0)*sin(radiantheta));        //calculating y-cordinate of lagrangian marker
        int rbx = round(bX), rby = round(bY);           //rounding it to nearest integer

        //        for(int x=0; x<NX; x++)
        //        {
        //            for(int y=0; y<NY; y++)
        //            {


        int vicinity_map[4][2] = {
            // x,  y
            {-1, 0},  //left
            {+1, 0},  //right
            {0, +1},  //down
            {0, -1},  //up
        };

        int m=0;
        while(m != NF) {

            //iterate over each direction
            int rx, ry; //temp variables to store the coords of nodes in the vicinity of current marker
            for(int i=0; i<4; ++i) {
                //add in either(x or y) coord to move in one of the 4 desired directions
                //Note: we are not skipping any nearby node in any of the 4 directions
                rx = round(bX + vicinity_map[i][0]);
                ry = round(bY + vicinity_map[i][1]);

                double D = delta2(rx, ry, bX, bY);

                UbX[b] += (ux[rx][ry] * D * pow(h, 2)); //unforced velocity interpolation on markers
                UbY[b] += (uy[rx][ry] * D * pow(h, 2));
            }

            //OLD CODE
            //
            //for (int i = rbx - 1; i <= rbx + 1; i++)
            //{
            //    for (int j = rby - 1; j <= rby + 1; j++)
            //      {
            //        double distance = sqrt(pow(i-g, 2) + pow(j-f, 2));

            //
            //        if(distance > radius)                 //checking if the point is outside the circle
            //        {
            //            UbX[b] += (ux[i][j] * D * pow(h, 2));
            //            UbY[b] += (uy[i][j] * D * pow(h, 2));
            //        }
            //    }
            //}


            int Ub = 0;                             //calculating boundary force on markers
//            printf("f: %d, %d: %f\r\n", rbx, rby, rho[rbx][rby]);
            FbX[b] = (2*rho[rbx][rby] * Ub - UbX[b]) ;  //x-component of force on the marker from it's vicinity
            FbY[b] = (2*rho[rbx][rby] * Ub - UbY[b]) ;  //y-component


            for(int i=0; i<4; ++i)
            {
                //add in either(x or y) coord to move in one of the 4 desired directions
                //Note: we are not skipping any nearby node in any of the 4 directions
                rx = round(bX + vicinity_map[i][0/*delta in x-corrd*/]);
                ry = round(bY + vicinity_map[i][1/*delta in y-coord*/]);

                double D = delta2(rx, ry, bX, bY);

                Fx[rx][ry] += FbX[b] * D * dels;            //updating the force on neraby nodes of current markers
                Fy[rx][ry] += FbY[b] * D * dels;
            }

            ///OLD CODE
            //for (int i = rbx - 1; i <= rbx + 1; i++)
            //{
            //    for (int j = rby - 1; j <= rby + 1; j++)
            //  {
            //        double distance = sqrt(pow(i-g, 2) + pow(j-f, 2));

            //
            //        if(distance > radius)                    //checking if the point is outside the circle
            //         {
            //            Fx[i][j] += FbX[b] * D * dels;      //updating the force on nearby nodes of the current marker
            //            Fy[i][j] += FbY[b] * D * dels;
            //        }
            //    }
            //}
            //            }
            //        }

            m = m + 1;
        }
    }


    int dt = 1;
    //CFX = 0;
    SumFX = 0.0;                                              //calculating updated velocity on grids
    for(int i=0; i<NX; ++i)
    {
        for(int j=0; j<NY; ++j)
         {
//            printf("s: %d, %d: %f\r\n", i, j, rho[i][j]);
            ux[i][j] = ux[i][j] + (dt/(2*rho[i][j]))*Fx[i][j];
            uy[i][j] = uy[i][j] + (dt/(2*rho[i][j]))*Fy[i][j];
            FX[i][j] = Fx[i][j];
            FY[i][j] = Fy[i][j];
            SumFX += FX[i][j];
            Cd = -(SumFX)/(pow(u_inlet,2) * radius);
             printf("%d\t%lf\t\n", k,Cd);
            
            
//            printf("ff: %f, %f", Fx[i][j], Fy[i][j]);
        }
    }

    return;
}

void collision()
{
    int x,y,i;
    double udotc, u2, feq, force_term;

    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            U[x][y]=ux[x][y];
            V[x][y]=uy[x][y];

            if(bnode[x][y] != 1.0)
            {

                for(i=0; i<Q; i++)
                {
                    //U[x][y] = ux[x][y]+(fx*0.5)/rho[x][y];
                    //V[x][y] = uy[x][y]+(fy*0.5)/rho[x][y];

                    udotc = U[x][y]*cx[i]+V[x][y]*cy[i];
                    u2 = U[x][y]*U[x][y]+V[x][y]*V[x][y];

                    force_term = (1.0-0.5/tau)*t[i]*((3.0*(cx[i]-U[x][y])+9.0*cx[i]*(cx[i]*U[x][y]+cy[i]*V[x][y]))*FX[x][y]) + ((3.0*(cy[i]-V[x][y])+9.0*cy[i]*(cx[i]*U[x][y]+cy[i]*V[x][y]))*FY[x][y]) ;

                    feq = rho[x][y]*t[i]*(1+3.0*udotc+4.5*udotc*udotc-1.5*u2);
                    //f1[x][y][i] = f1[x][y][i]-(1.0/tau)*(f1[x][y][i]-feq);
                    f1[x][y][i] = f1[x][y][i]-(1.0/tau)*(f1[x][y][i]-feq) +(force_term);


                    // Compute force for each direction
                    //for (int i = 0; i < Q; i++)
                    //{
                    // Compute deviation of velocity from discrete velocity
                    //double dev = (c[i].x - u.x) / c*c;

                    // Compute dot product of e_i with u
                    //double dot = e[i].x * u.x + e[i].y * u.y + e[i].z * u.z;
                    //dot /= c * c*c*c;

                    // Compute dot product of previous result with e_i
                    //dot *= e[i];

                    // Compute weight factor for direction i
                    //double weight = w[i];

                    // Compute force for direction i
                    //double force = (1.0 - 0.5 * tau) * weight * (3.0 * dev + 9.0 * dot / (c * c * c * c));

                    // Add force to total force
                    //F.x += force * e[i].x;
                    //F.y += force * e[i].y;
                    //F.z += force * e[i].z;
                }
            }


        }
    }
    return ;
}

void streaming()
{


    int x,y,i,newx,newy;
    double rho_inlet, u_outlet;

    /*for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            //if(bnode[x][y]!=1.0)
            {
                for(i=0; i<Q; i++)
                {
                    newx = next_x[x][i];
                    newy = next_y[y][i];

                    f1[newx][newy][i] = f2[x][y][i];
                }
            }
        }
    }*/
    for(x=0; x<NX; x++)
    {
        for (y=0; y<NY; y++)
        {
            for (i=0; i<Q; i++)
            {
                newx=next_x[x][i];
                newy=next_y[y][i];
                f2[newx][newy][i] = f1[x][y][i];
            }
        }
    }

    for(x=0; x<NX; x++)
    {
        for (y=0; y<NY; y++)
        {
            for (i=0; i<Q; i++)
            {
                f1[x][y][i]=f2[x][y][i];
            }
        }
    }
    /*------ Standard bounce-back scheme -----------*/
    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            if(y==0)
            {
                f1[x][y][2] = f1[x][y][4];
                f1[x][y][5] = f1[x][y][7];
                f1[x][y][6] = f1[x][y][8];

            }
            if(y==NY-1)
            {
                f1[x][y][4] = f1[x][y][2];
                f1[x][y][7] = f1[x][y][5];
                f1[x][y][8] = f1[x][y][6];
            }
        }
    }

    for (y=0; y<NY; y++)
    {
        rho_inlet = (f1[0][y][0]+f1[0][y][2]+f1[0][y][4]+2.0*(f1[0][y][3]+f1[0][y][6]+f1[0][y][7]))/(1.0-u_inlet);
        f1[0][y][1] = f1[0][y][3]+(2.0/3.0)*rho_inlet*u_inlet;
        f1[0][y][5] = f1[0][y][7]-(1.0/2.0)*(f1[0][y][2]-f1[0][y][4])+(1.0/6.0)*rho_inlet*u_inlet;
        f1[0][y][8] = f1[0][y][6]+(1.0/2.0)*(f1[0][y][2]-f1[0][y][4])+(1.0/6.0)*rho_inlet*u_inlet;
    }

    
    for (y=0; y<NY; y++)
    {
        for(x=NX-1; x<NX; x++)
        {
            u_outlet = -1.0 + (f1[x][y][0]+f1[x][y][2]+f1[x][y][4]+2.0*(f1[x][y][1]+f1[x][y][5]+f1[x][y][8]))/rho0;
            f1[x][y][3] = f1[x][y][1]-(2.0/3.0)*rho0*u_outlet;
            f1[x][y][7] = f1[x][y][5]-(1.0/6.0)*rho0*u_outlet+(1.0/2.0)*(f1[x][y][2]-f1[x][y][4]);
            f1[x][y][6] = f1[x][y][8]-(1.0/6.0)*rho0*u_outlet-(1.0/2.0)*(f1[x][y][4]-f1[x][y][2]);
        }
    }
    return;
}

void data(int data_counter, int id)
{
    int     x, y;
    //double  Cd;
    //double SumFX;
    FILE    *f3;
    char    phase   [100];

    /*  Data for Tecplot*/
    //SumFX = 0.0;
    sprintf ( phase, "IBM_phase%d.dat",id);
    f3 = fopen(phase, "w");
    fprintf( f3, "Variables = X, Y, RHO, U, V, Fx, Fy \n");
    fprintf(f3,"Zone I=   %d,J=   %d,F=POINT\n", NX, NY);
    for (y = NY - 1; y > -1; y--)
    {    for (x = 0; x < NX; x++)
        {
            //SumFX += FX[x][y];
            
            fprintf(f3,"%d\t%d\t%lf\t%lf\t%lf\t%0.10lf\t%0.10lf\n",x,y,rho[x][y],U[x][y],V[x][y],FX[x][y],FY[x][y]);
            fprintf(f3, "\n");

        }

    }
    
    fflush(f3);
    fclose(f3);

    return;
}
void data_Cd(int data_counter, int id)
{
    //int     k,x,y;
    //double  SumFX;
    //double  Cd;
    
    FILE    *f3;
    char    phase   [100];

    /*  Data for Tecplot*/
    //SumFX = 0.0;
    sprintf ( phase, "Cd%d.dat",id);
    f3 = fopen(phase, "w");
    fprintf( f3, "Variables = Time Steps, Cd \n");
    //fprintf(f3,"Zone I=   %d,J=   %d,F=POINT\n", NX, NY);
    
    
    for(k=0; k<T; k++)
    {

            
            fprintf(f3,"%d\t%lf\t\n", k,Cd);
            

    }

    
 
    

    
    fflush(f3);
    fclose(f3);

    return;
}

/*
void data(int, int)
{       {
        //store output in a file
        FILE    *f3;
        f3 = fopen("IB-LBM_Output.txt", "w");
        fprintf( f3, "Variables = X, Y, RHO, U, V \n");
        //double radius = a/2.0;
        for (int x = 0; x < NX; x++) {
            for (int y=0; y<NY; ++y) {
                //double distance = sqrt(pow(x-g, 2) + pow(x-f, 2));
                //only if the node is outside the circle, we are writing to the file
                //if(distance > radius) {
                fprintf(f3,"%d\t%d\t%lf\t%lf\t%lf\n",x,y,rho[x][y],ux[x][y],uy[x][y]);
                fprintf(f3, "\n");
                //}
            }
        }

        fflush(f3);
        fclose(f3);
        return;
        }
}*/
//
//  main.c
//  Re40Dia20NF1D2
//
//  Created by Siddhartha Shandilya on 15/04/23.
//

#include<stdio.h>
#include<math.h>

  /*------ Flow in a Square Channel with a particle in between  ---------*/
#define        NF          1
#define        Re          40.0
#define        u_inlet     0.2093333333
#define        NX          801   //no. of nodes in the x-direction
#define        NY          801   //no. of nodes in the y-direction

#define        a           20.0    //particle diameter
#define        radius      10.0     //particle radius
#define        g           400.0   // x-coordinate of the center of the spherical particle
#define        f           400.0   // y-coordinate of the center of the spherical particle
#define        lmtheta     2.25  // angular separation of lagrangian marker
#define        Q           9     // no. of direction of velocity vectors (D2Q9 model implemented)
#define        T           100001 // no. of time steps
#define        tau         0.814  // dimensionless relaxation time due to fluid–particle collisions
#define        visc        (tau-0.5)/3.0 //viscosity
#define        rho0        1.0   // density initialization
//#define      Ht          NY-1.0 //height in vertical direction
#define        pie         3.141592653589 //value of pie
#define        w0          4.0/9.0 // weighting coefficient
#define        w1          1.0/9.0 // weighting coefficients for i = 1,2,3,4
#define        w2          1.0/36.0 // weighting coefficients for i = 5,6,7,8
//#define      Ub          0.0


#define         h           1

//double        CFX;
//int           k;
int             cx          [Q]={0,1,0,-1,0,1,-1,-1,1}; //discrete velocity vectors
int             cy          [Q]={0,0,1,0,-1,1,1,-1,-1}; // discrete velocity vectors
double          t           [Q]={w0,w1,w1,w1,w1,w2,w2,w2,w2};
int             next_x      [NX][Q];
int             next_y      [NY][Q];
double          SumFX;
double          r;
double          FX          [NX][NY];
double          FY          [NX][NY];
double          f1          [NX][NY][Q];    //main probability distribution function
double          f2          [NX][NY][Q];    //temporary PDF
double          rho         [NX][NY];
double          ux          [NX][NY];
double          uy          [NX][NY];
double          U           [NX][NY];
double          V           [NX][NY];
//double        ux_eq       [NX][NY];
//double        uy_eq       [NX][NY];
double          bnode       [NX][NY];
//double        ux_exact    [NY];

void        tables();
void        initialise();
void        cal_obs();
void        IBM();
void        collision();
void        streaming();
void        data(int, int);
void        cal_Cd(int, int);
//void        exact();

int main()
{
    int count = 0, k;
    tables();
    initialise();
    for(k=0; k<T; k++)
    {
        printf("k=%d\r\t",k);
        cal_obs();
        IBM();
        collision();
        streaming();
        
        /*if(k%50000==0)
        {
            data(count, k);
        }*/
        if(k==100000)
        {
            cal_Cd(count, k);
        }
    }

    return 0;
}

void tables()
{
    int x,y,i;

    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            for(i=0; i<Q; i++)
            {
                next_x[x][i] = x + cx[i];

                if(next_x[x][i]<0)
                    next_x [x][i] = NX-1;
                if(next_x[x][i]>(NX-1))
                    next_x[x][i] = 0;

                next_y[y][i] = y + cy[i];

                if(next_y[y][i]<0)
                    next_y [y][i] = NY-1;
                if(next_y[y][i]>(NY-1))
                    next_y[y][i] = 0;
            }
        }
    }

    return ;
}


void initialise()
{
    int x,y,i;

    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            rho[x][y] = rho0;
            ux[x][y] = 0.0; uy[x][y] = 0.0;
            
            for(i=0; i<Q; i++)
            {
                f1[x][y][i] = rho0*t[i];

            }
        }
    }

    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            bnode[x][y] = 0.0;
            if(y==0 || y==(NY-1))
            {
                bnode[x][y] = 1.0;
            }
        }
    }

    return ;
}

double cal_dela(int x, int y, double bX, double bY) {
    double rX = x - bX;                      //x-coordinate difference between the current marker and the current node
    double rY = y - bY;                      //y-coordinate difference between the current marker and the current node

    double arX = fabsf(rX);                  //absolute value of 'r'
    double arY = fabsf(rY);                  // ,,

    double delX = 0, delY = 0;               //calculating delta function

    if(arX >= 0 && arX < 1)
        delX = 1/8.0*(3-(2*arX)+sqrt(1+(4*arX)-(4*arX*arX)));
    if(arX >= 1 && arX < 2)
        delX = 1/8.0*(5-(2*arX)-sqrt(-7+(12*arX)-(4*arX*arX)));
    else // |r| >= 2
        delX = 0;


    if(arY >= 0 && arY < 1)                 //calculating delta function (y);
        delY = 1/8.0*(3-(2*arY)+sqrt(1+(4*arY)-(4*arY*arY)));
    if(arY >= 1 && arY < 2)
        delY = 1/8.0*(5-(2*arY)-sqrt(-7+(12*arY)-(4*arY*arY)));
    else // |r| >= 2
        delY = 0;

    double D = delX * delY;                          //calculation of Eq. No. 26
    return D;
}
double delta2(int x, int y, double bX, double bY)

{

    double D;
    double rX = x - bX;                      //x-coordinate difference between the current marker and the current node
    double rY = y - bY;                      //y-coordinate difference between the current marker and the current node
    double arX = fabs(rX);                  //absolute value of 'r'
    double arY = fabs(rY);
    double delX = 0.0; double delY = 0.0;

    if(arX <= 1)

        delX = 1.0 - arX;

    else

        delX = 0.0;

    

    if(arY <= 1)

        delY = 1.0 - arY;

    else

        delY = 0.0;

    

    D = delX * delY;

    

    return D;

}

void cal_obs()
{
    int x,y,i;
    //double dense;

    for(x=0; x<NX; x++)
    {
        for (y=0; y<NY; y++)
        {
            rho[x][y]=0.0; ux[x][y]=0.0; uy[x][y]=0.0;
            //if(bnode[x][y] !=1.0)
            {
                for (i=0; i<Q; i++)
                {
                    rho[x][y]     += f1[x][y][i];
                    ux[x][y]  += f1[x][y][i]*cx[i];
                    uy[x][y]  += f1[x][y][i]*cy[i];
                }
                //rho[x][y] = dense;
                ux[x][y]  = ux[x][y]/rho[x][y];
                uy[x][y]  = uy[x][y]/rho[x][y];
            }
        }
    }
return;
}

void IBM()
{
    double dels = (a * pie * lmtheta)/360.0;             //arc length calculation

    int b = 0;
    int markerCount = 360/lmtheta;                      //calculating no. of markers
    double UbX[markerCount], UbY[markerCount];           //velocities at markers
    double FbX[markerCount], FbY[markerCount];           //forces at markers
    double Fx[NX][NY];
    float  Fy[NX][NY];                       //forces at grids
    for(int i=0; i<markerCount; ++i)
        UbX[i] = 0.0,                                     //initialising to zero
                UbY[i] = 0.0,
                FbX[i] = 0.0,
                FbY[i] = 0.0;

    for(int i=0; i<NX; i++)
        for(int j=0; j<NY; j++) {
            Fx[i][j] = 0.0;
            Fy[i][j] = 0.0;
        }

    //double radius = a/2.0;
    //iterate all the markers one by one
    for(double theta=0; theta<=360; theta+=lmtheta, b+=1)
    {
        double radiantheta = theta * (pie / 180.0);      //converting angle to radian
        double bX = (g + (a/2.0)*cos(radiantheta));        //calculating x-cordinate of lagrangian marker
        double bY = (f + (a/2.0)*sin(radiantheta));        //calculating y-cordinate of lagrangian marker
        int rbx = round(bX), rby = round(bY);           //rounding it to nearest integer

        //        for(int x=0; x<NX; x++)
        //        {
        //            for(int y=0; y<NY; y++)
        //            {


        int vicinity_map[4][2] = {
            // x,  y
            {-1, 0},  //left
            {+1, 0},  //right
            {0, +1},  //down
            {0, -1},  //up
        };

        int m=0;
        while(m != NF) {

            //iterate over each direction
            int rx, ry; //temp variables to store the coords of nodes in the vicinity of current marker
            for(int i=0; i<4; ++i) {
                //add in either(x or y) coord to move in one of the 4 desired directions
                //Note: we are not skipping any nearby node in any of the 4 directions
                rx = round(bX + vicinity_map[i][0]);
                ry = round(bY + vicinity_map[i][1]);

                double D = delta2(rx, ry, bX, bY);

                UbX[b] += (ux[rx][ry] * D * pow(h, 2)); //unforced velocity interpolation on markers
                UbY[b] += (uy[rx][ry] * D * pow(h, 2));
            }

            //OLD CODE
            //
            //for (int i = rbx - 1; i <= rbx + 1; i++)
            //{
            //    for (int j = rby - 1; j <= rby + 1; j++)
            //      {
            //        double distance = sqrt(pow(i-g, 2) + pow(j-f, 2));

            //
            //        if(distance > radius)                 //checking if the point is outside the circle
            //        {
            //            UbX[b] += (ux[i][j] * D * pow(h, 2));
            //            UbY[b] += (uy[i][j] * D * pow(h, 2));
            //        }
            //    }
            //}


            int Ub = 0;                             //calculating boundary force on markers
//            printf("f: %d, %d: %f\r\n", rbx, rby, rho[rbx][rby]);
            FbX[b] = (2*rho[rbx][rby] * Ub - UbX[b]) ;  //x-component of force on the marker from it's vicinity
            FbY[b] = (2*rho[rbx][rby] * Ub - UbY[b]) ;  //y-component


            for(int i=0; i<4; ++i)
            {
                //add in either(x or y) coord to move in one of the 4 desired directions
                //Note: we are not skipping any nearby node in any of the 4 directions
                rx = round(bX + vicinity_map[i][0/*delta in x-corrd*/]);
                ry = round(bY + vicinity_map[i][1/*delta in y-coord*/]);

                double D = delta2(rx, ry, bX, bY);

                Fx[rx][ry] += FbX[b] * D * dels;            //updating the force on neraby nodes of current markers
                Fy[rx][ry] += FbY[b] * D * dels;
            }

            ///OLD CODE
            //for (int i = rbx - 1; i <= rbx + 1; i++)
            //{
            //    for (int j = rby - 1; j <= rby + 1; j++)
            //  {
            //        double distance = sqrt(pow(i-g, 2) + pow(j-f, 2));

            //
            //        if(distance > radius)                    //checking if the point is outside the circle
            //         {
            //            Fx[i][j] += FbX[b] * D * dels;      //updating the force on nearby nodes of the current marker
            //            Fy[i][j] += FbY[b] * D * dels;
            //        }
            //    }
            //}
            //            }
            //        }

            m = m + 1;
        }
    }


    int dt = 1;
    //CFX = 0;
    //SumFX = 0.0;                                               //calculating updated velocity on grids
    for(int i=0; i<NX; ++i)
    {
        for(int j=0; j<NY; ++j)
         {
//            printf("s: %d, %d: %f\r\n", i, j, rho[i][j]);
            ux[i][j] = ux[i][j] + (dt/(2*rho[i][j]))*Fx[i][j];
            uy[i][j] = uy[i][j] + (dt/(2*rho[i][j]))*Fy[i][j];
            FX[i][j] = Fx[i][j];
            FY[i][j] = Fy[i][j];
            //SumFX += FX[i][j];
            
//            printf("ff: %f, %f", Fx[i][j], Fy[i][j]);
        }
    }

    return;
}

void collision()
{
    int x,y,i;
    double udotc, u2, feq, force_term;

    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            U[x][y]=ux[x][y];
            V[x][y]=uy[x][y];

            if(bnode[x][y] != 1.0)
            {

                for(i=0; i<Q; i++)
                {
                    //U[x][y] = ux[x][y]+(fx*0.5)/rho[x][y];
                    //V[x][y] = uy[x][y]+(fy*0.5)/rho[x][y];

                    udotc = U[x][y]*cx[i]+V[x][y]*cy[i];
                    u2 = U[x][y]*U[x][y]+V[x][y]*V[x][y];

                    force_term = (1.0-0.5/tau)*t[i]*((3.0*(cx[i]-U[x][y])+9.0*cx[i]*(cx[i]*U[x][y]+cy[i]*V[x][y]))*FX[x][y]) + ((3.0*(cy[i]-V[x][y])+9.0*cy[i]*(cx[i]*U[x][y]+cy[i]*V[x][y]))*FY[x][y]) ;

                    feq = rho[x][y]*t[i]*(1+3.0*udotc+4.5*udotc*udotc-1.5*u2);
                    //f1[x][y][i] = f1[x][y][i]-(1.0/tau)*(f1[x][y][i]-feq);
                    f1[x][y][i] = f1[x][y][i]-(1.0/tau)*(f1[x][y][i]-feq) +(force_term);


                    // Compute force for each direction
                    //for (int i = 0; i < Q; i++)
                    //{
                    // Compute deviation of velocity from discrete velocity
                    //double dev = (c[i].x - u.x) / c*c;

                    // Compute dot product of e_i with u
                    //double dot = e[i].x * u.x + e[i].y * u.y + e[i].z * u.z;
                    //dot /= c * c*c*c;

                    // Compute dot product of previous result with e_i
                    //dot *= e[i];

                    // Compute weight factor for direction i
                    //double weight = w[i];

                    // Compute force for direction i
                    //double force = (1.0 - 0.5 * tau) * weight * (3.0 * dev + 9.0 * dot / (c * c * c * c));

                    // Add force to total force
                    //F.x += force * e[i].x;
                    //F.y += force * e[i].y;
                    //F.z += force * e[i].z;
                }
            }


        }
    }
    return ;
}

void streaming()
{


    int x,y,i,newx,newy;
    double rho_inlet, u_outlet;

    /*for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            //if(bnode[x][y]!=1.0)
            {
                for(i=0; i<Q; i++)
                {
                    newx = next_x[x][i];
                    newy = next_y[y][i];

                    f1[newx][newy][i] = f2[x][y][i];
                }
            }
        }
    }*/
    for(x=0; x<NX; x++)
    {
        for (y=0; y<NY; y++)
        {
            for (i=0; i<Q; i++)
            {
                newx=next_x[x][i];
                newy=next_y[y][i];
                f2[newx][newy][i] = f1[x][y][i];
            }
        }
    }

    for(x=0; x<NX; x++)
    {
        for (y=0; y<NY; y++)
        {
            for (i=0; i<Q; i++)
            {
                f1[x][y][i]=f2[x][y][i];
            }
        }
    }
    /*------ Standard bounce-back scheme -----------*/
    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            if(y==0)
            {
                f1[x][y][2] = f1[x][y][4];
                f1[x][y][5] = f1[x][y][7];
                f1[x][y][6] = f1[x][y][8];

            }
            if(y==NY-1)
            {
                f1[x][y][4] = f1[x][y][2];
                f1[x][y][7] = f1[x][y][5];
                f1[x][y][8] = f1[x][y][6];
            }
        }
    }

    for (y=0; y<NY; y++)
    {
        rho_inlet = (f1[0][y][0]+f1[0][y][2]+f1[0][y][4]+2.0*(f1[0][y][3]+f1[0][y][6]+f1[0][y][7]))/(1.0-u_inlet);
        f1[0][y][1] = f1[0][y][3]+(2.0/3.0)*rho_inlet*u_inlet;
        f1[0][y][5] = f1[0][y][7]-(1.0/2.0)*(f1[0][y][2]-f1[0][y][4])+(1.0/6.0)*rho_inlet*u_inlet;
        f1[0][y][8] = f1[0][y][6]+(1.0/2.0)*(f1[0][y][2]-f1[0][y][4])+(1.0/6.0)*rho_inlet*u_inlet;
    }

    
    for (y=0; y<NY; y++)
    {
        for(x=NX-1; x<NX; x++)
        {
            u_outlet = -1.0 + (f1[x][y][0]+f1[x][y][2]+f1[x][y][4]+2.0*(f1[x][y][1]+f1[x][y][5]+f1[x][y][8]))/rho0;
            f1[x][y][3] = f1[x][y][1]-(2.0/3.0)*rho0*u_outlet;
            f1[x][y][7] = f1[x][y][5]-(1.0/6.0)*rho0*u_outlet+(1.0/2.0)*(f1[x][y][2]-f1[x][y][4]);
            f1[x][y][6] = f1[x][y][8]-(1.0/6.0)*rho0*u_outlet-(1.0/2.0)*(f1[x][y][4]-f1[x][y][2]);
        }
    }
    return;
}

void data(int data_counter, int id)
{
    int     x, y;
    //double  Cd;
    //double SumFX;
    FILE    *f3;
    char    phase   [100];

    /*  Data for Tecplot*/
    //SumFX = 0.0;
    sprintf ( phase, "IBM_phase%d.dat",id);
    f3 = fopen(phase, "w");
    fprintf( f3, "Variables = X, Y, RHO, U, V, Fx, Fy \n");
    fprintf(f3,"Zone I=   %d,J=   %d,F=POINT\n", NX, NY);
    for (y = NY - 1; y > -1; y--)
    {    for (x = 0; x < NX; x++)
        {
            //SumFX += FX[x][y];
            
            fprintf(f3,"%d\t%d\t%lf\t%lf\t%lf\t%0.10lf\t%0.10lf\n",x,y,rho[x][y],U[x][y],V[x][y],FX[x][y],FY[x][y]);
            fprintf(f3, "\n");

        }

    }
    
    fflush(f3);
    fclose(f3);

    return;
}
void cal_Cd(int data_counter, int id)
{
    int     k,x,y;
    double  SumFX;
    double  Cd;
    
    FILE    *f3;
    char    phase   [100];

    /*  Data for Tecplot*/
    SumFX = 0.0;
    sprintf ( phase, "Cd%d.dat",id);
    f3 = fopen(phase, "w");
    fprintf( f3, "Variables = k, Cd \n");
    fprintf(f3,"Zone I=   %d,J=   %d,F=POINT\n", NX, NY);
    
    for (y = NY - 1; y > -1; y--)
    {    for (x = 0; x < NX; x++)
        {
            SumFX += FX[x][y];

        }
    }
    for(k=99999; k<T; k++)
    {

            Cd = -(SumFX)/(pow(u_inlet,2) * radius);
            fprintf(f3,"%d\t%lf\t%lf\t\n", k,Cd, SumFX);
            

    }

    
 
    

    
    fflush(f3);
    fclose(f3);

    return;
}

/*
void data(int, int)
{       {
        //store output in a file
        FILE    *f3;
        f3 = fopen("IB-LBM_Output.txt", "w");
        fprintf( f3, "Variables = X, Y, RHO, U, V \n");
        //double radius = a/2.0;
        for (int x = 0; x < NX; x++) {
            for (int y=0; y<NY; ++y) {
                //double distance = sqrt(pow(x-g, 2) + pow(x-f, 2));
                //only if the node is outside the circle, we are writing to the file
                //if(distance > radius) {
                fprintf(f3,"%d\t%d\t%lf\t%lf\t%lf\n",x,y,rho[x][y],ux[x][y],uy[x][y]);
                fprintf(f3, "\n");
                //}
            }
        }

        fflush(f3);
        fclose(f3);
        return;
        }
}*/
#include<stdio.h>
#include<math.h>

  /*------ Flow in a Square Channel with a particle in between  ---------*/
#define        NF          1
#define        Re          40.0
#define        u_inlet     0.1036333333 
#define        NX          801   //no. of nodes in the x-direction
#define        NY          801   //no. of nodes in the y-direction

#define        a           40.0    //particle diameter
#define        radius      20.0     //particle radius
#define        g           400.0   // x-coordinate of the center of the spherical particle
#define        f           400.0   // y-coordinate of the center of the spherical particle
#define        lmtheta     2.25  // angular separation of lagrangian marker
#define        Q           9     // no. of direction of velocity vectors (D2Q9 model implemented)
#define        T           100001 // no. of time steps
#define        tau         0.8109  // dimensionless relaxation time due to fluid–particle collisions
#define        visc        (tau-0.5)/3.0 //viscosity
#define        rho0        1.0   // density initialization
//#define      Ht          NY-1.0 //height in vertical direction
#define        pie         3.141592653589 //value of pie
#define        w0          4.0/9.0 // weighting coefficient
#define        w1          1.0/9.0 // weighting coefficients for i = 1,2,3,4
#define        w2          1.0/36.0 // weighting coefficients for i = 5,6,7,8
//#define      Ub          0.0


#define         h           1

//double        CFX;
//int           k;
int             cx          [Q]={0,1,0,-1,0,1,-1,-1,1}; //discrete velocity vectors
int             cy          [Q]={0,0,1,0,-1,1,1,-1,-1}; // discrete velocity vectors
double          t           [Q]={w0,w1,w1,w1,w1,w2,w2,w2,w2};
int             next_x      [NX][Q];
int             next_y      [NY][Q];
double          SumFX;
double          r;
double          FX          [NX][NY];
double          FY          [NX][NY];
double          f1          [NX][NY][Q];    //main probability distribution function
double          f2          [NX][NY][Q];    //temporary PDF
double          rho         [NX][NY];
double          ux          [NX][NY];
double          uy          [NX][NY];
double          U           [NX][NY];
double          V           [NX][NY];
//double        ux_eq       [NX][NY];
//double        uy_eq       [NX][NY];
double          bnode       [NX][NY];
//double        ux_exact    [NY];

void        tables();
void        initialise();
void        cal_obs();
void        IBM();
void        collision();
void        streaming();
void        data(int, int);
void        cal_Cd(int, int);
//void        exact();

int main()
{
    int count = 0, k;
    tables();
    initialise();
    for(k=0; k<T; k++)
    {
        printf("k=%d\r\t",k);
        cal_obs();
        IBM();
        collision();
        streaming();
        
        /*if(k%50000==0)
        {
            data(count, k);
        }*/
        if(k==100000)
        {
            cal_Cd(count, k);
        }
    }

    return 0;
}

void tables()
{
    int x,y,i;

    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            for(i=0; i<Q; i++)
            {
                next_x[x][i] = x + cx[i];

                if(next_x[x][i]<0)
                    next_x [x][i] = NX-1;
                if(next_x[x][i]>(NX-1))
                    next_x[x][i] = 0;

                next_y[y][i] = y + cy[i];

                if(next_y[y][i]<0)
                    next_y [y][i] = NY-1;
                if(next_y[y][i]>(NY-1))
                    next_y[y][i] = 0;
            }
        }
    }

    return ;
}


void initialise()
{
    int x,y,i;

    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            rho[x][y] = rho0;
            ux[x][y] = 0.0; uy[x][y] = 0.0;
            
            for(i=0; i<Q; i++)
            {
                f1[x][y][i] = rho0*t[i];

            }
        }
    }

    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            bnode[x][y] = 0.0;
            if(y==0 || y==(NY-1))
            {
                bnode[x][y] = 1.0;
            }
        }
    }

    return ;
}

double cal_dela(int x, int y, double bX, double bY) {
    double rX = x - bX;                      //x-coordinate difference between the current marker and the current node
    double rY = y - bY;                      //y-coordinate difference between the current marker and the current node

    double arX = fabsf(rX);                  //absolute value of 'r'
    double arY = fabsf(rY);                  // ,,

    double delX = 0, delY = 0;               //calculating delta function

    if(arX >= 0 && arX < 1)
        delX = 1/8.0*(3-(2*arX)+sqrt(1+(4*arX)-(4*arX*arX)));
    if(arX >= 1 && arX < 2)
        delX = 1/8.0*(5-(2*arX)-sqrt(-7+(12*arX)-(4*arX*arX)));
    else // |r| >= 2
        delX = 0;


    if(arY >= 0 && arY < 1)                 //calculating delta function (y);
        delY = 1/8.0*(3-(2*arY)+sqrt(1+(4*arY)-(4*arY*arY)));
    if(arY >= 1 && arY < 2)
        delY = 1/8.0*(5-(2*arY)-sqrt(-7+(12*arY)-(4*arY*arY)));
    else // |r| >= 2
        delY = 0;

    double D = delX * delY;                          //calculation of Eq. No. 26
    return D;
}
double delta2(int x, int y, double bX, double bY)

{

    double D;
    double rX = x - bX;                      //x-coordinate difference between the current marker and the current node
    double rY = y - bY;                      //y-coordinate difference between the current marker and the current node
    double arX = fabs(rX);                  //absolute value of 'r'
    double arY = fabs(rY);
    double delX = 0.0; double delY = 0.0;

    if(arX <= 1)

        delX = 1.0 - arX;

    else

        delX = 0.0;

    

    if(arY <= 1)

        delY = 1.0 - arY;

    else

        delY = 0.0;

    

    D = delX * delY;

    

    return D;

}

void cal_obs()
{
    int x,y,i;
    //double dense;

    for(x=0; x<NX; x++)
    {
        for (y=0; y<NY; y++)
        {
            rho[x][y]=0.0; ux[x][y]=0.0; uy[x][y]=0.0;
            //if(bnode[x][y] !=1.0)
            {
                for (i=0; i<Q; i++)
                {
                    rho[x][y]     += f1[x][y][i];
                    ux[x][y]  += f1[x][y][i]*cx[i];
                    uy[x][y]  += f1[x][y][i]*cy[i];
                }
                //rho[x][y] = dense;
                ux[x][y]  = ux[x][y]/rho[x][y];
                uy[x][y]  = uy[x][y]/rho[x][y];
            }
        }
    }
return;
}

void IBM()
{
    double dels = (a * pie * lmtheta)/360.0;             //arc length calculation

    int b = 0;
    int markerCount = 360/lmtheta;                      //calculating no. of markers
    double UbX[markerCount], UbY[markerCount];           //velocities at markers
    double FbX[markerCount], FbY[markerCount];           //forces at markers
    double Fx[NX][NY];
    float  Fy[NX][NY];                       //forces at grids
    for(int i=0; i<markerCount; ++i)
        UbX[i] = 0.0,                                     //initialising to zero
                UbY[i] = 0.0,
                FbX[i] = 0.0,
                FbY[i] = 0.0;

    for(int i=0; i<NX; i++)
        for(int j=0; j<NY; j++) {
            Fx[i][j] = 0.0;
            Fy[i][j] = 0.0;
        }

    //double radius = a/2.0;
    //iterate all the markers one by one
    for(double theta=0; theta<=360; theta+=lmtheta, b+=1)
    {
        double radiantheta = theta * (pie / 180.0);      //converting angle to radian
        double bX = (g + (a/2.0)*cos(radiantheta));        //calculating x-cordinate of lagrangian marker
        double bY = (f + (a/2.0)*sin(radiantheta));        //calculating y-cordinate of lagrangian marker
        int rbx = round(bX), rby = round(bY);           //rounding it to nearest integer

        //        for(int x=0; x<NX; x++)
        //        {
        //            for(int y=0; y<NY; y++)
        //            {


        int vicinity_map[4][2] = {
            // x,  y
            {-1, 0},  //left
            {+1, 0},  //right
            {0, +1},  //down
            {0, -1},  //up
        };

        int m=0;
        while(m != NF) {

            //iterate over each direction
            int rx, ry; //temp variables to store the coords of nodes in the vicinity of current marker
            for(int i=0; i<4; ++i) {
                //add in either(x or y) coord to move in one of the 4 desired directions
                //Note: we are not skipping any nearby node in any of the 4 directions
                rx = round(bX + vicinity_map[i][0]);
                ry = round(bY + vicinity_map[i][1]);

                double D = delta2(rx, ry, bX, bY);

                UbX[b] += (ux[rx][ry] * D * pow(h, 2)); //unforced velocity interpolation on markers
                UbY[b] += (uy[rx][ry] * D * pow(h, 2));
            }

            //OLD CODE
            //
            //for (int i = rbx - 1; i <= rbx + 1; i++)
            //{
            //    for (int j = rby - 1; j <= rby + 1; j++)
            //      {
            //        double distance = sqrt(pow(i-g, 2) + pow(j-f, 2));

            //
            //        if(distance > radius)                 //checking if the point is outside the circle
            //        {
            //            UbX[b] += (ux[i][j] * D * pow(h, 2));
            //            UbY[b] += (uy[i][j] * D * pow(h, 2));
            //        }
            //    }
            //}


            int Ub = 0;                             //calculating boundary force on markers
//            printf("f: %d, %d: %f\r\n", rbx, rby, rho[rbx][rby]);
            FbX[b] = (2*rho[rbx][rby] * Ub - UbX[b]) ;  //x-component of force on the marker from it's vicinity
            FbY[b] = (2*rho[rbx][rby] * Ub - UbY[b]) ;  //y-component


            for(int i=0; i<4; ++i)
            {
                //add in either(x or y) coord to move in one of the 4 desired directions
                //Note: we are not skipping any nearby node in any of the 4 directions
                rx = round(bX + vicinity_map[i][0/*delta in x-corrd*/]);
                ry = round(bY + vicinity_map[i][1/*delta in y-coord*/]);

                double D = delta2(rx, ry, bX, bY);

                Fx[rx][ry] += FbX[b] * D * dels;            //updating the force on neraby nodes of current markers
                Fy[rx][ry] += FbY[b] * D * dels;
            }

            ///OLD CODE
            //for (int i = rbx - 1; i <= rbx + 1; i++)
            //{
            //    for (int j = rby - 1; j <= rby + 1; j++)
            //  {
            //        double distance = sqrt(pow(i-g, 2) + pow(j-f, 2));

            //
            //        if(distance > radius)                    //checking if the point is outside the circle
            //         {
            //            Fx[i][j] += FbX[b] * D * dels;      //updating the force on nearby nodes of the current marker
            //            Fy[i][j] += FbY[b] * D * dels;
            //        }
            //    }
            //}
            //            }
            //        }

            m = m + 1;
        }
    }


    int dt = 1; 
    //CFX = 0; 
    //SumFX = 0.0;                                               //calculating updated velocity on grids
    for(int i=0; i<NX; ++i)
    {
        for(int j=0; j<NY; ++j)
         {
//            printf("s: %d, %d: %f\r\n", i, j, rho[i][j]);
            ux[i][j] = ux[i][j] + (dt/(2*rho[i][j]))*Fx[i][j];
            uy[i][j] = uy[i][j] + (dt/(2*rho[i][j]))*Fy[i][j];
            FX[i][j] = Fx[i][j];
            FY[i][j] = Fy[i][j];
            //SumFX += FX[i][j];
            
//            printf("ff: %f, %f", Fx[i][j], Fy[i][j]);
        }
    }

    return;
}

void collision()
{
    int x,y,i;
    double udotc, u2, feq, force_term;

    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            U[x][y]=ux[x][y];
            V[x][y]=uy[x][y];

            if(bnode[x][y] != 1.0)
            {

                for(i=0; i<Q; i++)
                {
                    //U[x][y] = ux[x][y]+(fx*0.5)/rho[x][y];
                    //V[x][y] = uy[x][y]+(fy*0.5)/rho[x][y];

                    udotc = U[x][y]*cx[i]+V[x][y]*cy[i];
                    u2 = U[x][y]*U[x][y]+V[x][y]*V[x][y];

                    force_term = (1.0-0.5/tau)*t[i]*((3.0*(cx[i]-U[x][y])+9.0*cx[i]*(cx[i]*U[x][y]+cy[i]*V[x][y]))*FX[x][y]) + ((3.0*(cy[i]-V[x][y])+9.0*cy[i]*(cx[i]*U[x][y]+cy[i]*V[x][y]))*FY[x][y]) ;

                    feq = rho[x][y]*t[i]*(1+3.0*udotc+4.5*udotc*udotc-1.5*u2);
                    //f1[x][y][i] = f1[x][y][i]-(1.0/tau)*(f1[x][y][i]-feq);
                    f1[x][y][i] = f1[x][y][i]-(1.0/tau)*(f1[x][y][i]-feq) +(force_term);


                    // Compute force for each direction
                    //for (int i = 0; i < Q; i++)
                    //{
                    // Compute deviation of velocity from discrete velocity
                    //double dev = (c[i].x - u.x) / c*c;

                    // Compute dot product of e_i with u
                    //double dot = e[i].x * u.x + e[i].y * u.y + e[i].z * u.z;
                    //dot /= c * c*c*c;

                    // Compute dot product of previous result with e_i
                    //dot *= e[i];

                    // Compute weight factor for direction i
                    //double weight = w[i];

                    // Compute force for direction i
                    //double force = (1.0 - 0.5 * tau) * weight * (3.0 * dev + 9.0 * dot / (c * c * c * c));

                    // Add force to total force
                    //F.x += force * e[i].x;
                    //F.y += force * e[i].y;
                    //F.z += force * e[i].z;
                }
            }


        }
    }
    return ;
}

void streaming()
{


    int x,y,i,newx,newy;
    double rho_inlet, u_outlet;

    /*for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            //if(bnode[x][y]!=1.0)
            {
                for(i=0; i<Q; i++)
                {
                    newx = next_x[x][i];
                    newy = next_y[y][i];

                    f1[newx][newy][i] = f2[x][y][i];
                }
            }
        }
    }*/
    for(x=0; x<NX; x++)
    {
        for (y=0; y<NY; y++)
        {
            for (i=0; i<Q; i++)
            {
                newx=next_x[x][i];
                newy=next_y[y][i];
                f2[newx][newy][i] = f1[x][y][i];
            }
        }
    }

    for(x=0; x<NX; x++)
    {
        for (y=0; y<NY; y++)
        {
            for (i=0; i<Q; i++)
            {
                f1[x][y][i]=f2[x][y][i];
            }
        }
    }
    /*------ Standard bounce-back scheme -----------*/
    for(x=0; x<NX; x++)
    {
        for(y=0; y<NY; y++)
        {
            if(y==0)
            {
                f1[x][y][2] = f1[x][y][4];
                f1[x][y][5] = f1[x][y][7];
                f1[x][y][6] = f1[x][y][8];

            }
            if(y==NY-1)
            {
                f1[x][y][4] = f1[x][y][2];
                f1[x][y][7] = f1[x][y][5];
                f1[x][y][8] = f1[x][y][6];
            }
        }
    }

    for (y=0; y<NY; y++)
	{
		rho_inlet = (f1[0][y][0]+f1[0][y][2]+f1[0][y][4]+2.0*(f1[0][y][3]+f1[0][y][6]+f1[0][y][7]))/(1.0-u_inlet);
		f1[0][y][1] = f1[0][y][3]+(2.0/3.0)*rho_inlet*u_inlet;
		f1[0][y][5] = f1[0][y][7]-(1.0/2.0)*(f1[0][y][2]-f1[0][y][4])+(1.0/6.0)*rho_inlet*u_inlet;
		f1[0][y][8] = f1[0][y][6]+(1.0/2.0)*(f1[0][y][2]-f1[0][y][4])+(1.0/6.0)*rho_inlet*u_inlet;
	}

	
	for (y=0; y<NY; y++)
	{
		for(x=NX-1; x<NX; x++)
		{
			u_outlet = -1.0 + (f1[x][y][0]+f1[x][y][2]+f1[x][y][4]+2.0*(f1[x][y][1]+f1[x][y][5]+f1[x][y][8]))/rho0;
			f1[x][y][3] = f1[x][y][1]-(2.0/3.0)*rho0*u_outlet;
			f1[x][y][7] = f1[x][y][5]-(1.0/6.0)*rho0*u_outlet+(1.0/2.0)*(f1[x][y][2]-f1[x][y][4]);
			f1[x][y][6] = f1[x][y][8]-(1.0/6.0)*rho0*u_outlet-(1.0/2.0)*(f1[x][y][4]-f1[x][y][2]);
		}
	}
    return;
}

void data(int data_counter, int id)
{
    int     x, y;
    //double  Cd;
    //double SumFX;
    FILE    *f3;
    char    phase   [100];

    /*  Data for Tecplot*/
    //SumFX = 0.0;
    sprintf ( phase, "IBM_phase%d.dat",id);
    f3 = fopen(phase, "w");
    fprintf( f3, "Variables = X, Y, RHO, U, V, Fx, Fy \n");
    fprintf(f3,"Zone I=   %d,J=   %d,F=POINT\n", NX, NY);
    for (y = NY - 1; y > -1; y--)
    {    for (x = 0; x < NX; x++)
        {
            //SumFX += FX[x][y];
            
            fprintf(f3,"%d\t%d\t%lf\t%lf\t%lf\t%0.10lf\t%0.10lf\n",x,y,rho[x][y],U[x][y],V[x][y],FX[x][y],FY[x][y]);
            fprintf(f3, "\n");

        }

    }
    
    fflush(f3);
    fclose(f3);

    return;
}
void cal_Cd(int data_counter, int id)
{
    int     k,x,y;
    double  SumFX;
    double  Cd;
    
    FILE    *f3;
    char    phase   [100];

    /*  Data for Tecplot*/
    SumFX = 0.0;
    sprintf ( phase, "Cd%d.dat",id);
    f3 = fopen(phase, "w");
    fprintf( f3, "Variables = k, Cd \n");
    fprintf(f3,"Zone I=   %d,J=   %d,F=POINT\n", NX, NY);
    
    for (y = NY - 1; y > -1; y--)
    {    for (x = 0; x < NX; x++)
        {
            SumFX += FX[x][y];

        }
    }
    for(k=99999; k<T; k++)
    {

            Cd = -(SumFX)/(pow(u_inlet,2) * radius);
            fprintf(f3,"%d\t%lf\t%lf\t\n", k,Cd, SumFX);
            

    }   

    
 
    

    
    fflush(f3);
    fclose(f3);

    return;
}

/*
void data(int, int)
{       {
        //store output in a file
        FILE    *f3;
        f3 = fopen("IB-LBM_Output.txt", "w");
        fprintf( f3, "Variables = X, Y, RHO, U, V \n");
        //double radius = a/2.0;
        for (int x = 0; x < NX; x++) {
            for (int y=0; y<NY; ++y) {
                //double distance = sqrt(pow(x-g, 2) + pow(x-f, 2));
                //only if the node is outside the circle, we are writing to the file
                //if(distance > radius) {
                fprintf(f3,"%d\t%d\t%lf\t%lf\t%lf\n",x,y,rho[x][y],ux[x][y],uy[x][y]);
                fprintf(f3, "\n");
                //}
            }
        }

        fflush(f3);
        fclose(f3);
        return;
        }
}*/
#include<stdio.h>
#include<conio.h>

int main(){
    int a[3][3],b[3][3],c[3][3];
    int i,j,k;
    int temp = 0;

    printf("Plz., enter the values of first matrix: ");
    for ( i = 0; i < 3; i++)
    {
        for ( j = 0; j < 3; j++)
        {
            printf("a[%d][%d] = ",i,j);
            scanf("%d",&a[i][j]);
        }
    }
    for ( i = 0; i < 3; i++)
    {
        printf("|   ");
        for ( j = 0; j < 3; j++)
        {
            printf("%d  ",a[i][j]);
        }
        printf("    | \n");
    }


    printf("Plz., enter the values of second matrix: ");
    for ( i = 0; i < 3; i++)
    {
        for ( j = 0; j < 3; j++)
        {
            printf("b[%d][%d] = ",i,j);
            scanf("%d",&b[i][j]);
        }
    }

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


    printf("The multiplication of the given matrix is: ");

    for ( i = 0; i < 3; i++)
    {
        for ( j = 0; j < 3; j++)
        {
            for ( k = 0; k < 3; k++)
            {
                temp = 0;
                temp += a[i][k]*b[k][j];
            }
            c[i][j] += temp;
        }
    }

    for ( i = 0; i < 3; i++)
    {
        printf("|   ");
        for ( j = 0; j < 3; j++)
        {
            printf("%d  ",c[i][j]);
        }
        printf("    | \n");
    }
}
#include<stdio.h>
#include<conio.h>

void main(){
    int a[3][3],b[3][3];
    int i,j;
    printf("\n Plz., enter values of two matrix to add them...");
    printf("\n Enter values of first matrix: ");

    for ( i = 0; i < 3; i++)
    {
        for ( j = 0; j < 3; j++)
        {
            scanf("%d",&a[i][j]);
        }
    }

            for ( i = 0; i < 3; i++)
    {
        printf("|");
        for ( j = 0; j < 3; j++)
        {
            printf("\t %d",a[i][j]);
        }
        printf("\t |");
        printf("\n");
    }

    printf("\n Enter the value of second matrix: ");

    for ( i = 0; i < 3; i++)
    {
        for ( j = 0; j < 3; j++)
        {
            scanf("%d",&b[i][j]);
        }
    }

        for ( i = 0; i < 3; i++)
    {
        printf("|");
        for ( j = 0; j < 3; j++)
        {
            printf("\t %d",a[i][j]);
        }
        printf("\t |");
        printf("\n");
    }

    printf("\n");
    printf("The summation of two matrix: ");

    for ( i = 0; i < 3; i++)
    {
        printf("|");
        for ( j = 0; j < 3; j++)
        {
            printf("\t %d",(a[i][j]+b[i][j]));
        }
        printf("\t |");
        printf("\n");
    }
}
#include<stdio.h>
#include<conio.h>

void main(){
    int age;
    read:
        printf("Plz., enter your age, if you are not a chhote bachhi = ");
    scanf("%d", &age);

    if (age>=18)
    {
        printf("You are eligibe to vote. \n");
    }
    else
    {
        printf("Chhote bacchi ho kya ? \n");
    }
    goto read;
    }
}
#include<stdio.h>
#include<conio.h>

void main(){
    int age,x=1;

while (x=1)
{
    printf("\n Plz., enter your age, if you are not a chhote bacchi = ");
    scanf("%d",&age);
    age>=18?(printf("You are eligible for vote.")):(printf("Chhote bacchi ho kya."));
}
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

void main(){
    unsigned int x,year;
    system("clear");
    read:
        printf("Plz., enter any year:");
    scanf("%d",&year);
    if (year%4==0)
    {
        printf("You have enter a leap year. \n");
    }
    else{
        printf("You have enter a normal year. \n");
    }
    goto read;
    }
#include"stdio.h"
#include"conio.h"

int main(){
    int a,b=1;
    printf("Plz., enter any number to print table : ");
    scanf("%d",&a);

    for ( b = 1; b <= 10; b++)
    {
        printf("%d * %d = %d \n",a,b,(a*b));
    }
}
#include<stdio.h>
#include<conio.h>

int main(){
    int a,b,c;
    printf("Enter the values of two variables to swap them with each other... \n");
    printf("The value of a: ");
    scanf("%d",&a);
    printf("The value of b: ");
    scanf("%d",&b);

    a = a + b;
    b = a - b;
    a = a - b;

    printf("The value of a: %d \n",a);
    printf("The value of b: %d",b);
}
int main()
{
    int a;
    printf("Enter the max number upto which you have to list all prime number: ");
    scanf("%d", &a);

    for (int i = 1; i <= a; i++)
    {
        for (int j = 2; j <= (i - 1); j++)
        {
            if ((i % 2) != 0)
            {
                printf("%d \n", i);
                break;
            }
        }
    }
}
#include <stdio.h>
#include <conio.h>

int main()
{
    int num, i;
    int flag;
    flag = 0;
    printf("Plz., enter any number to check, it is prime number or not... \n");
    printf("Pz., enter any number: ");
    scanf("%d", &num);

    for (i = 2; i <= (num - 1); i++)
    {
        if (num % i == 0)
        {
            printf("The given %d is non-prime number.", num);
            flag = 0;
            break;
        }
        flag = 1;
    }

    if (flag == 1)
    {
        printf("You have enter a prime number.");
    }
}
#include<stdio.h>
#include<conio.h>

int main(){
    int power(int ,int);
    int result;
    int a,b;
    printf("Plz., enter a number: ");
    scanf("%d",&a);

    printf("Plz., enter power of the number: ");
    scanf("%d",&b);

    result = power(a,b);
    printf("%d to the power of %d is: %d",a,b,result);
}

int power(int a,int b)
{
    int i,j,result;
    result = a;
    for ( i = 1; i <= b; i++){
        if(i != 1)
        {
            a = result*a;
        }
    }
    return(a);
}
#include <stdio.h>
#include <conio.h>

int array = 3;
int main()
{
    int a[2][2];
    int i, j;
    printf("Plz., enter the values of matrix: ");

    for (i = 0; i < array; i++)
    {
        for (j = 0; j < array; j++)
        {
            printf("a[%d][%d] = ", i, j);
            scanf("%d",&a[i][j]);
        }
    }

    for (i = 0; i < 3; i++)
    {
        printf("|\t");
        for (j = 0; j < 3; j++)
        {
            printf("%d ",a[i][j]);
        }
        printf("\t|\n");
    }
}
#include<stdio.h>
#include<conio.h>

int main(){
    int a,b,opt;
    printf("For sum press : 1 \n For sub press : 2 \n For mul press : 3 \n For div press : 4 \n");
    printf("Plz., choose a option to perform any mathematcal operaton: ");
    again:
    scanf("%d",&opt);

    switch (opt)
    {
    case 1:
        printf("Enter your first no. : ");
        scanf("%d",&a);
        printf("Enter your second no. : ");
        scanf("%d",&b);
        printf("The sum of %d and %d is %d",a,b,(a+b));
        break;

    case 2:
        printf("Enter your first no. : ");
        scanf("%d",&a);
        printf("Enter your second no. : ");
        scanf("%d",&b);
        printf("The sum of %d and %d is %d",a,b,(a-b));
        break;

    case 3:
        printf("Enter your first no. : ");
        scanf("%d",&a);
        printf("Enter your second no. : ");
        scanf("%d",&b);
        printf("The mul of %d and %d is %d",a,b,(a*b));
        break;

    case 4:
        printf("Enter your first no. : ");
        scanf("%d",&a);
        printf("Enter your second no. : ");
        scanf("%d",&b);
        printf("The div of %d and %d is %d",a,b,(a/b));
        break;
    
    
    default:
        printf("Plz., choose a valid option... \n");
        goto again;
        break;
    }
}
#include<stdio.h>
#include<conio.h>

int main(){
    char c;
    printf("Plz., enter any character: ");
    scanf("%c",&c);
    printf("%d",c);
}
#include <stdio.h>
#include <conio.h>

#define PI 3.14159
float cal(float radius);
int main()
{
    int i;
    float area, radius;

    printf("To stop program insert value of radius = 0...");
    printf("\n Radius of circle: ");
    scanf("%f", &radius);

    for (i = 0; radius != 0; i++)
    {
        if (radius < 0)
        {
            area = 0;
        }
        else
        {
            area = cal(radius);
        }
        printf("Area of Circle is %f \n", area);
        scanf("%f", &radius);
    }
}

float cal(float r)
{
    float a;
    a = PI * r * r;
    return (a);
}
#include <stdio.h>
#include<stdlib.h>
struct node
{
    int data;
    struct node *next;

}*front=NULL,*rear=NULL;
void enq(int key)
{
    struct node *t;
    t=(struct node*)malloc(sizeof(struct node));
    if(t==NULL)
      printf("queue is full");
    else
    {
        t->data=key;
        t->next=NULL;
        if(front==NULL)
          front=rear=t;
        else
         {
             rear->next=t;
             rear=t;
         }
    }

}
int deq()
{
    int x=-1;
    struct node *t;
    if(front==NULL)
    {
        printf("queue is empty");

    }
    else
    {
         x=front->data;
        t=front;

        front=front->next;
        free(t);
    }
    return x;
}
int qempty()
{
    return front==NULL;
}
void BFS(int G[7][7],int s,int n)
{
    int i=s,j;
    int vis[7]={0};
    vis[i]=1;
    printf("%d ",i);
    enq(i);
    while(!qempty())
    {
        i=deq();

        for(int j=1;j<n;j++)
        {
            if(G[i][j]==1 && vis[j]==0)
            {
                 vis[j]=1;
                 printf("%d ",j);
                 enq(j);
            }
        }
    }
}
void dfs(int G[7][7],int s,int n)
{
    static int vis[7]={0};
    int j;
    if(vis[s]==0)
    {
        printf("%d ",s);
        vis[s]=1;
        for(int j=1;j<n;j++)
        {
            if(G[s][j]==1 &&vis[j]==0)
                dfs(G,j,n);
        }

    }
}
int main()
{


int G[7][7]={{0,0,0,0,0,0,0},
             {0,0,1,1,0,0,0},
             {0,1,0,0,1,0,0},
             {0,1,0,0,1,0,0},
             {0,0,1,1,0,1,1},
             {0,0,0,0,1,0,0},
            {0,0,0,0,1,0,0}};
           dfs(G,4,7);
}
#include <stdio.h>
#include<stdlib.h>
struct node
{
    int data;
    struct node *next;

}*front=NULL,*rear=NULL;
void enq(int key)
{
    struct node *t;
    t=(struct node*)malloc(sizeof(struct node));
    if(t==NULL)
      printf("queue is full");
    else
    {
        t->data=key;
        t->next=NULL;
        if(front==NULL)
          front=rear=t;
        else
         {
             rear->next=t;
             rear=t;
         }
    }

}
int deq()
{
    int x=-1;
    struct node *t;
    if(front==NULL)
    {
        printf("queue is empty");

    }
    else
    {
         x=front->data;
        t=front;

        front=front->next;
        free(t);
    }
    return x;
}
int qempty()
{
    return front==NULL;
}
void BFS(int G[7][7],int s,int n)
{
    int i=s,j;
    int vis[7]={0};
    vis[i]=1;
    printf("%d ",i);
    enq(i);
    while(!qempty())
    {
        i=deq();

        for(int j=1;j<n;j++)
        {
            if(G[i][j]==1 && vis[j]==0)
            {
                 vis[j]=1;
                 printf("%d ",j);
                 enq(j);
            }
        }
    }
}
int main()
{


int G[7][7]={{0,0,0,0,0,0,0},
             {0,0,1,1,0,0,0},
             {0,1,0,0,1,0,0},
             {0,1,0,0,1,0,0},
             {0,0,1,1,0,1,1},
             {0,0,0,0,1,0,0},
            {0,0,0,0,1,0,0}};
           BFS(G,4,7);
}
#include<stdio.h>
#include<stdlib.h>


struct Node
{
   int data;
   struct Node*next;
};

struct Node * top = NULL;

void LinklistTraversal(struct Node * ptr){
    while(ptr!= NULL){
        printf("Element : %d \n",ptr->data);
        ptr = ptr->next;
    }
}
int isEmpty(struct Node * top)
{
    if (top == NULL){
        return 1;
    }
    else
    {
        return 0;
    }
}


int isFull(struct Node* top)
{
    struct Node * p = (struct Node *)malloc(sizeof(struct Node));
    if (p == NULL){
        return 1;
    }
    else

    {
       return 0;
    }
}

struct Node * push(struct Node* top,int x){
    if (isFull(top))
    {
        printf("Its overflow\n");
    }
    else{
        struct Node *n =(struct Node *)malloc(sizeof(struct Node));
        n->data =x;
        n->next=top;
        top=n;
        return top;
    }
    
}


int pop(struct Node * tp){
    if (isEmpty(tp))
    {
        printf("Its underflow\n");
    }
    else{
        struct Node* n=tp;
        top= (tp)->next;
        int x = n->data;
        free(n);
        return x;

    }
    
}



int main(){
    top = push(top,17);   
    top = push(top,19);   
    top = push(top,27);   
    top = push(top,22);   
    top = push(top,24);    
    top = push(top,21);   


    int element =pop(top);
    printf("Popped element is %d\n",element);

    LinklistTraversal(top); 
    return 0;
}
#include<stdio.h>
#include<stdlib.h>

struct stack
{
   int size;
   int top;
   int *arr;
};

int isEmpty(struct stack * ptr){
    if ( ptr->top == -1){
        return 1;
    }
    return 0;
}

int isfull(struct stack *ptr){
    if(ptr->top == ptr->size-1){
       return 1;
    }
    return 0;
}

void push(struct stack *ptr, int value ){
    if (isfull(ptr)){
        printf("stack overflow!\n");
    }
    else{
        ptr->top++;
        ptr->arr[ptr->top] =value;
    }
}


int pop(struct stack *ptr){
    if(isEmpty(ptr)){
        printf("Underflow!");
    }
    else{
        int value  =  ptr->arr[ptr->top];
        ptr-> top--;
        return value;
    }

}

int peek(struct stack * sp ,int i){
    int index = sp -> top- i +1;
    if(index < 0){
        printf("invalid");
        return -1;

    }
    else{
        return sp->arr[index];
    }
}

int stacktop(struct stack * sp){
    return sp->arr[sp->top];
}

int bottom(struct stack * sp){
    return sp->arr[0];

}

int main(){
    struct stack * sp= (struct stack *)malloc(sizeof(struct stack));
    sp->size = 15;
    sp->top=-1;
    sp->arr=(int*)malloc(sp->size*sizeof(int));
    printf("Stack is succesfully created \n");

    push(sp,8);
    push(sp,1);
    push(sp,21);
    push(sp,4);
    push(sp,34);
    push(sp,56);
    push(sp,24);
    push(sp,19);
    push(sp,27);
    push(sp,14);
    push(sp,33);
 
    //pop(sp);

    //printf("Element popped: %d \n",pop(sp));

    for (int j = 1; j < sp -> top+2; j++)
    {
       printf("The value at point %d is %d\n",j,peek(sp,j));
    }

    printf("The top most element in the stack is %d\n",stacktop(sp));
    printf("The bottom element in the stack is %d \n",bottom(sp));

    return 0;
}
#include<stdio.h>
#include<stdlib.h>

struct stack
{
   int size;
   int top;
   int *arr;
};

int isEmpty(struct stack * ptr){
    if ( ptr->top == -1){
        return 1;
    }
    return 0;
}

int isfull(struct stack *ptr){
    if(ptr->top == ptr->size-1){
       return 1;
    }
    return 0;
}

void push(struct stack *ptr, int value ){
    if (isfull(ptr)){
        printf("stack overflow!\n");
    }
    else{
        ptr->top++;
        ptr->arr[ptr->top] =value;
    }
}


int pop(struct stack *ptr){
    if(isEmpty(ptr)){
        printf("Underflow!");
    }
    else{
        int value  =  ptr->arr[ptr->top];
        ptr-> top--;
        return value;
    }

}

int peek(struct stack * sp ,int i){
    int index = sp -> top- i +1;
    if(index < 0){
        printf("invalid");
        return -1;

    }
    else{
        return sp->arr[index];
    }
}

int stacktop(struct stack * sp){
    return sp->arr[sp->top];
}

int bottom(struct stack * sp){
    return sp->arr[0];

}

int main(){
    struct stack * sp= (struct stack *)malloc(sizeof(struct stack));
    sp->size = 15;
    sp->top=-1;
    sp->arr=(int*)malloc(sp->size*sizeof(int));
    printf("Stack is succesfully created \n");

    push(sp,8);
    push(sp,1);
    push(sp,21);
    push(sp,4);
    push(sp,34);
    push(sp,56);
    push(sp,24);
    push(sp,19);
    push(sp,27);
    push(sp,14);
    push(sp,33);
 
    //pop(sp);

    //printf("Element popped: %d \n",pop(sp));

    for (int j = 1; j < sp -> top+2; j++)
    {
       printf("The value at point %d is %d\n",j,peek(sp,j));
    }

    printf("The top most element in the stack is %d\n",stacktop(sp));
    printf("The bottom element in the stack is %d \n",bottom(sp));

    return 0;
}
#include<stdio.h>
#include<stdlib.h>

struct queue{
    int size;
    int f;
    int r;
    int *arr;
};

int isEmpty(struct queue *q){
    if (q->r == q->f )
    {
        return 1;
    }
    return 0;
}

int isFull(struct queue *q){
    if (q->r==q->size-1)
    {
        return 1;
    }
    return 0;
}

void enqueue(struct queue *q , int value){
    if (isFull(q))
    {
        printf("Its full\n");
    }
    else{
        q->r++;
        q->arr[q->r]=value;
        printf("Enqueued element : %d\n",value);
    }
    
}

int dequeue(struct queue *q){
    int a = -1;
    if(isEmpty(q)){
        printf("Its empty \n");
    }
    else{
        q->f++;
        a=q->arr[q->f];
    }
    return a;

}

int main(){
    struct queue q;
    q.size = 4;
    q.f = q.r = -1;
    q.arr = (int*)malloc(q.size*sizeof(int));

    enqueue(&q,17);
    enqueue(&q,9);
    enqueue(&q,2001);
    enqueue(&q,27);

   printf("%d\n",dequeue(&q));
    printf("%d\n",dequeue(&q));
    printf("%d\n",dequeue(&q));
    printf("%d\n",dequeue(&q));
    

    if (isEmpty(&q))
    {
        printf("Queue is empty\n");
    }
    if(isFull(&q)){
        printf("Queue is  full \n");
    }


    return 0;
}
#include <stdio.h>

void printArray(int *a, int n)
{
    for (int i = 0; i < n; i++)
    {
        printf("%d ", a[i]);
    }
    printf("\n ");
}

int partition(int a[], int low, int high)
{
    int pivot = a[low];
    int i = low + 1;
    int j = high;
    int temp;
    do
    {
        while (a[i] <= pivot)
        {
            i++;
        }
        while (a[j] > pivot)
        {
            j--;
        }
        if (i < j)
        {
            temp = a[i];
            a[i] = a[j];
            a[j] = temp;
        }
    } while (i < j);

    temp = a[low];
    a[low] = a[j];
    a[j] = temp;
    return j;
}

void quicksort(int a[], int low, int high)
{
    int partitionindex;

    if (low < high)
    {
        partitionindex = partition(a, low, high);
        quicksort(a, low, partitionindex - 1);
        quicksort(a, partitionindex + 1, high);
    }
}

int main()
{
    // int a[] = {56, 67, 6, 98, 9, 0, 7, 12};
    int a[] = {1, 5, 3, 23, 4, 9};
    int n = 6;
    printArray(a, n);
    quicksort(a, 0, n - 1);
    printArray(a, n);
    return 0;
}
#include <stdio.h>
#include <stdlib.h>

struct stack
{
    int top;
    int size;
    int *arr;
};

int isEmpty(struct stack *ptr)
{
    if (ptr->top == -1)
    {
        return 1;
    }
    return 0;
}

int isFull(struct stack *ptr)
{
    if (ptr->top == ptr->size - 1)
    {
        return 1;
    }
    return 0;
}

void push(struct stack *ptr, int value)
{
    if (isFull(ptr))
    {
        printf("The stack is Overflow");
    }
    else
    {
        ptr->top++;
        ptr->arr[ptr->top] = value;
    }
}

char pop(struct stack *ptr)
{
    if (isEmpty(ptr))
    {
        printf("The stack is underflow");
    }
    else
    {
        char value = ptr->arr[ptr->top];
        ptr->top--;
        return value;
    }
}

char checkpranthesis(char *exp)
{
    struct stack *sp ;
    sp->size = 15;
    sp->top = -1;
    sp->arr = (char *)malloc(sp->size * sizeof(char));
    printf("Stack is succesfully created \n");

    for (int i = 0; exp[i] != '\0'; i++)
    {
        if (exp[i] == '(')
        {
            push(sp, '(');
        }
        else if (exp[i] == ')')
        {
            if (isEmpty(sp))
            {
                return 0;
            }
            pop(sp);
        }
    }
    if (isEmpty(sp))
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int main()
{
    char *exp = "(6+7)-((9*(8))";
    if (checkpranthesis(exp))
    {
        printf("It is matching");
    }
    else
    {
        printf("It is not matching");
    }

    return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct stack
{
    int size;
    int top;

    char *arr;
};

int stackTop(struct stack *sp)
{
    return sp->arr[sp->top];
}

int isEmpty(struct stack *ptr)
{
    if (ptr->top == -1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int isFull(struct stack *ptr)
{
    if (ptr->top == ptr->size - 1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
void push(struct stack *ptr, char val)
{
    if (isFull(ptr))
    {
        printf("Stack Overflow !", val);
    }
    else
    {
        ptr->top++;
        ptr->arr[ptr->top] = val;
    }
}

char pop(struct stack *ptr)
{
    if (isEmpty(ptr))
    {
        printf("Stack Underflow!!");
        return -1;
    }
    else
    {
        char val = ptr->arr[ptr->top];
        ptr->top--;
        return val;
    }
}


int precedence(char ch)
{
    if (ch == '*' || ch == '/')
        return 3;
    else if (ch == '+' || ch == '-')
        return 2;
    else
        return 0;
}

int isOperator(char ch)
{
    if (ch == '+' || ch == '-' || ch == '*' || ch == '/')
        return 1;
    else
        return 0;
}

char *infixToPostfix(char *infix)
{
    struct stack *sp = (struct stack *)malloc(sizeof(struct stack));
    sp->size = 10;
    sp->top = -1;
    sp->arr = (char *)malloc(sp->size * sizeof(char));
    char *postfix = (char *)malloc((strlen(infix) + 1) * sizeof(char));
    int i = 0;
    int j = 0;

    while (infix[i] != '\0')
    {
        if (!isOperator(infix[i]))
        {
            postfix[j] = infix[i];
            j++;
            i++;
        }
        else
        {
            if (precedence(infix[i]) > precedence(stackTop(sp))){
                push(sp, infix[i]);
                i++;
            }
            else{
                postfix[j] = pop(sp);
                j++;
            }
        }
    }
    
    
    while (!isEmpty(sp))
    {
        postfix[j] = pop(sp);
        j++;
    }
    postfix[j] = '\0';
    return postfix;
}

int main()
{
    char *infix = "s-y/z-k*d";
    printf("Postfix is %s \n", infixToPostfix(infix));
    // Topostfix(infix);

    return 0;
}
#include <stdio.h>
#include <stdlib.h>

struct stack
{
    int top;
    int size;
    int *arr;
};

char stackTop(struct stack* sp){
    return sp->arr[sp->top];
}

int match(char a, char b){
    if(a=='{' && b == '}'){
        return 1;
    }
    if(a=='[' && b == ']'){
        return 1;
    }
    if(a=='(' && b == ')'){
        return 1;
    }
  return 0;
}


int isEmpty(struct stack *ptr)
{
    if (ptr->top == -1)
    {
        return 1;
    }
    return 0;
}

int isFull(struct stack *ptr)
{
    if (ptr->top == ptr->size - 1)
    {
        return 1;
    }
    return 0;
     return 0;
}

void push(struct stack *ptr, int value)
{
    if (isFull(ptr))
    {
        printf("The stack is Overflow");
    }
    else
    {
        ptr->top++;
        ptr->arr[ptr->top] = value;
    }
}

char pop(struct stack *ptr)
{
    if (isEmpty(ptr))
    {
        printf("The stack is underflow");
    }
    else
    {
        char value = ptr->arr[ptr->top];
        ptr->top--;
        return value;
    }
}

char checkpranthesis(char *exp)
{
    struct stack *sp ;
    sp->size = 15;
    sp->top = -1;
    sp->arr = (char *)malloc(sp->size * sizeof(char));
    printf("Stack is succesfully created \n");

    char popped_ch;

    for (int i = 0; exp[i] != '\0'; i++)
    {
        if (exp[i] == '('|| exp[i]=='{' || exp[i]=='[')
        {
            push(sp, exp[i]);
        }
        else if (exp[i] == ')' || exp[i]=='}' || exp[i]==']')
        {
            if (isEmpty(sp))
            {
                return 0;
            }
            popped_ch = pop(sp);
            if(!match((popped_ch),exp[i])){
                return 0;
            }
        }
    }
    if (isEmpty(sp))
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

int main()
{
    char *exp = "(6+7)-((9*(8))}";
    if (checkpranthesis(exp))
    {
        printf("It is matching");
    }
    else
    {
        printf("It is not matching");
    }

    return 0;
}
#include <stdio.h>

void printArary(int *a, int n)
{
    for (int i = 0; i < n; i++)
    {
        printf("%d ", a[i]);
    }
    printf("\n");
}

void merge(int a[], int mid, int low, int high)
{
    int i, j, k, b[100];
    i = low;
    j = mid + 1;
    k = low;

    while (i <= mid && j <= high)
    {
        if (a[i] < a[j])
        {
            b[k] = a[i];
            i++;
            k++;
        }
        else
        {
            b[k] = a[j];
            j++;
            k++;
        }
    }
    while (i <= mid)
    {
        b[k] = a[i];
        k++;
        i++;
    }

    while (j <= high)
    {
        b[k] = a[j];
        k++;
        j++;
    }
    for (int i = 0; i <= high; i++)
    {
        a[i] = b[i];
    }
}
void mergeSort(int a[], int low, int high){
    int mid;
    if (low < high){
        mid = (low + high) / 2;
        mergeSort(a, low, mid);
        mergeSort(a, mid+1, high);
        merge(a, mid, low, high);
    }
}


int main()
{
    int a[] = {3, 4, 33, 2, 34, 2, 3};
    int n = 7;
    printArary(a, n);
    mergeSort(a, 0, 6);
    printArary(a, n);

    return 0;
}
#include<stdio.h>
#include<stdlib.h>

struct Node{
    int data;
    struct Node *next;
};

void traversal(struct Node *ptr){
    while (ptr != NULL)
    {
        printf("Element : %d\n", ptr->data);
        ptr = ptr->next;
    }
}

// Case 1
struct Node * insertAtFirst(struct Node *head, int data){
    struct Node * ptr = (struct Node *) malloc(sizeof(struct Node));
    ptr->data = data;

    ptr->next = head;
    return ptr; 
}

// Case 2
struct Node * insertAtIndex(struct Node *head, int data, int index){
    struct Node * ptr = (struct Node *) malloc(sizeof(struct Node));
    struct Node * p = head;
    int i = 0;

    while (i!=index-1)
    {
        p = p->next;
        i++;
    }
    ptr->data = data;
    ptr->next = p->next;
    p->next = ptr;
    return head;
}

// Case 3
struct Node * insertAtEnd(struct Node *head, int data){
    struct Node * ptr = (struct Node *) malloc(sizeof(struct Node));
    ptr->data = data;
    struct Node * p = head;

    while(p->next!=NULL){
        p = p->next;
    }
    p->next = ptr;
    ptr->next = NULL;
    return head;
}

// Case 4
struct Node * insertAfterNode(struct Node *head, struct Node *prevNode, int data){
    struct Node * ptr = (struct Node *) malloc(sizeof(struct Node));
    ptr->data = data;

    ptr->next = prevNode->next;
    prevNode->next = ptr;

    
    return head;
}



struct Node * insertbeginning(struct Node *head ,int data){
    struct Node *ptr = (struct Node *)malloc(sizeof(struct Node));
    ptr->data = data;
    ptr->next = head;
    return ptr;


}

struct Node * insertbetween(struct Node *head, int data ,int index)
{
    struct Node *ptr=(struct Node *)malloc(sizeof(struct Node));
    struct Node * p = head;
    ptr->data=data;
    int i =0;
    while ( i !=index-1)
    {
        p = p->next;
        i++;
    }
    ptr->next = p->next;
    return head;
}
// Case 1: Deleting the first element from the linked list
struct Node * deleteFirst(struct Node * head){
    struct Node * ptr = head;
    head = head->next;
    free(ptr);
    return head;
}

// Case 2: Deleting the element at a given index from the linked list
struct Node * deleteAtIndex(struct Node * head, int index){
    struct Node *p = head;
    struct Node *q = head->next;
    for (int i = 0; i < index-1; i++)
    {
        p = p->next;
        q = q->next;
    }
    
    p->next = q->next;
    free(q);
    return head;
}

// Case 3: Deleting the last element
struct Node * deleteAtLast(struct Node * head){
    struct Node *p = head;
    struct Node *q = head->next;
    while(q->next !=NULL)
    {
        p = p->next;
        q = q->next;
    }
    
    p->next = NULL;
    free(q);
    return head;
}



int main(){
    struct Node *head;
    struct Node *second;
    struct Node *third;
    struct Node *fourth;

    head = (struct Node*)malloc(sizeof(struct Node));
    second = (struct Node*)malloc(sizeof(struct Node));
    third = (struct Node *)malloc(sizeof(struct Node));
    fourth = (struct Node *)malloc(sizeof(struct Node));

    head ->data=3;
    head ->next=second;

    second ->data=9;
    second ->next=third;

    third ->data=7;
    third->next=fourth;

    fourth->data=34;
    fourth->next=NULL;

    //traversal(head);
    //printf("-----------\n");
  //  head = insertbeginning(head,17);

   // printf("-----------\n");
    //traversal(head);
    //printf("-----------\n");
    insertbetween(head,45,2);
    //printf("-----------\n");
    traversal(head);

    return 0;
}
#include <stdio.h>

void printArray(int *A, int n)
{
    for (int i = 0; i < n; i++)
    {
        printf("%d ", A[i]);
    }
    printf("\n ");
}

void insertoinSort(int *A, int n)
{
    int key, j;
    for (int i = 0; i < n - 1; i++)
    {
        key = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > key)
        {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = key;
    }
}
int main()
{

    int A[] = {12, 2, 32, 11, 54, 32, 45, 67, 89};
    int n = 9;
    printf("Before sorting\n");
    printArray(A, n);
    insertoinSort(A, n);
    printf("After sorting \n");
    printArray(A, n);

    return 0;
}
#include<stdio.h>
#include<stdlib.h>

struct Node
{
    int data;
    struct Node * next;
    struct Node * prev;
};

void traversal(struct Node * head){
    struct Node *ptr =head;
    do
    {
        printf("ELement : %d\n",ptr->data);
        ptr= ptr->next;

    } while (ptr!=head);

}


int main(){
    struct Node * head;
    struct Node * second;
    struct Node * third;
    struct Node * fourth;

    head =  (struct Node *)malloc(sizeof(struct Node));
    second =  (struct Node *)malloc(sizeof(struct Node));
    third =  (struct Node *)malloc(sizeof(struct Node));
    fourth =  (struct Node *)malloc(sizeof(struct Node));

    head->data =34;
    head ->next=second;

    second->data = 23;
    second ->next=third;

    third ->data=7;
    third->next=fourth;

    fourth->data=34;
    fourth->next=head;

    return 0;
}
#include<stdio.h>
#include<stdlib.h>

struct Node
{
   int data;
   struct Node*next;
};
struct Node *f= NULL;
struct Node *r= NULL;
void enqueue(struct node *top  ,int d) //Insert elements in Queue
{
	struct node* n;
	n = (struct node*)malloc(sizeof(struct node));
	n->data = d;
	n->next = NULL;
	if((r==NULL)&&(f==NULL))
	{
		f = r = n;
		r->next = f;
	}
	else
	{
		r->next = n;
		r = n;
		n->next = f;
	}
} 
void dequeue(struct node * top) // Delete an element from Queue
{
	struct node* t;
	t = f;
	if((f==NULL)&&(r==NULL))
		printf("\nQueue is Empty");
	else if(f == r){
		f = r = NULL;
		free(t);
	}
	else{
		f = f->next;
		r->next = f;
		free(t);
	}
	
	
}
void print(){ // Print the elements of Queue
	struct node* t;
	t = f;
	if((f==NULL)&&(r==NULL))
		printf("\nQueue is Empty");
	else{
		do{
			printf("\n%d",t->data);
			t = t->next;
		}while(t != f);
	}
}

int main(){
	top = enqueue(top,17);
	
return 0;
}
#include <stdio.h>
#include <stdlib.h>

struct circularQueue
{
    int size;
    int f;
    int r;
    int *arr;
};

int isEmpty(struct circularQueue *q)
{
    if (q->f == q->r)
    {
        return 1;
    }
    return 0;
}

int isFull(struct circularQueue *q)
{
    if ((q->r + 1) % q->size == q->f)
    {
        return 1;
    }
    return 0;
}

void enqueue(struct circularQueue *q, int value)
{
    if (isFull(q))
    {
        printf("It is Full\n");
    }
    else
    {
        q->r++;
        q->arr[q->r] = value;
        printf("ELment Enqueued is %d \n", value);
    }
}

int dequeue(struct circularQueue *q)
{
    int a = -1;
    if (isEmpty(q))
    {
        printf("It is Empty\n");
    }
    else
    {
        q->f = (q->f + 1) % q->size;
        a = q->arr[q->f];
    }
    return a;
}

int main()
{
    struct circularQueue q;
    {
        q.size = 5;
        q.f = q.r = 0;
        q.arr = (int *)malloc(q.size * sizeof(int));
    };
    enqueue(&q, 17);
    enqueue(&q, 17);
    enqueue(&q, 9);
    enqueue(&q, 2001);
    //enqueue(&q, 27);

    printf("Elment dequeued is :  %d\n", dequeue(&q));
    printf("Elment dequeued is :  %d\n", dequeue(&q));
    printf("Elment dequeued is :  %d\n", dequeue(&q));
    printf("Elment dequeued is :  %d\n", dequeue(&q));
   // printf("Elment dequeued is :  %d\n", dequeue(&q));*/

    if (isFull(&q))
    {
       printf("Queue is full Now!!");
    }
    if (isEmpty(&q))
    {
        printf("Queue is empty Now!!");
    }
    
    

    return 0;
}
#include<stdio.h>
#include<stdlib.h>

struct Node
{
    int data;
    struct Node*next;
};

void traversal(struct Node * head){
    struct Node *ptr =head;
    do
    {
        printf("ELement : %d\n",ptr->data);
        ptr= ptr->next;

    } while (ptr!=head);
    
}

int inseratbeginiing(struct Node *head,int data){
    struct Node * ptr =(struct Node *)malloc(sizeof(struct Node));
    ptr->data=data;

    struct Node * p = head->next;
    while (p->next != head)
    {
        p=p->next;
    }

    p->next = ptr;
    ptr->next = head;
    head = ptr;
    return head;
    
}


int main(){
    struct Node * head;
    struct Node * second;
    struct Node * third;
    struct Node * fourth;
    struct Node * fifth;

    head = (struct Node*)malloc(sizeof(struct Node));
    second = (struct Node*)malloc(sizeof(struct Node));
    third = (struct Node *)malloc(sizeof(struct Node));
    fourth = (struct Node *)malloc(sizeof(struct Node));
    fifth = (struct Node *)malloc(sizeof(struct Node));

    head ->data=3;
    head ->next=second;

    second ->data=9;
    second ->next=third;

    third ->data=7;
    third->next=fourth;

    fourth->data=34;
    fourth->next=fifth;

    fifth ->data=17;
    fifth ->next = head;

    traversal(head);
    head = inseratbeginiing(head,90);
    traversal(head);

    
    return 0;
}
#include <stdio.h>
//------TO PRINT THE ARRAY-------
void printArray(int *A, int n)
{
  for (int i = 0; i < n; i++)
  {
    printf("%d ", A[i]);
  }
  printf("\n");
}

//-------BUBBLE SORTING THE ARRAY-----------
void bubbleSort(int *A, int n)
{
  int temp;
  int isSorted = 0;
  for (int i = 0; i < n - 1; i++)
  {
    //printf("Working on pass number : %d\n", i + 1);
    for (int j = 0; j < n - i - 1; j++)
    {
      if (A[j] > A[j + 1])
      {
        temp = A[j];
        A[j] = A[j + 1];
        A[j + 1] = temp;
      }
    }
  }
}

void BubllesortApdative(int *A, int n)
{
  int temp;
  int isSorted = 0;
  for (int i = 0; i < n - 1; i++)
  {
    printf("Working on the pass number %d\n", i + 1);
    isSorted = 1;
    for (int j = 0; j < n - 1 - i; j++)
    {
      if (A[j] > A[j + 1])
      {
        temp = A[j];
        A[j] = A[j + 1];
        A[j + 1] = temp;
        isSorted = 0;
      }
    }
    if (isSorted)
    {
      return;
    }
  }
}
int main()
{
  int A[] = {1, 23, 34, 32, 45, 5, 78, 9, 45, 43, 34, 4, 56, 67, 6};
  int n = 15;
  printArray(A, n);
  bubbleSort(A, n);
  printArray(A, n);

  return 0;
}
#include <stdio.h>
#include <stdlib.h>
// STRUCTURE OF THE TREE OR NODE
struct node
{
    int data;
    struct node *left;
    struct node *right;
};
// TO CREATE THE TREE AND INPUT THE DATA IN IT...
struct node *createnode(int data)
{
    struct node *n;
    n = (struct node *)malloc(sizeof(struct node));
    n->data = data;
    n->left = NULL;
    n->right = NULL;
    return n;
}
// PREPRDER TRAVERSAL
void preorder(struct node *root)
{
    if (root != NULL)
    {
        printf("%d ", root->data);
        preorder(root->left); // RECURSIVE METHOD
        preorder(root->right);
    }
}
// POSTORDER TREVERSAL
void postorder(struct node *root)
{
    if (root != NULL)
    {
        postorder(root->left);
        postorder(root->right); // RECURSIVE METHOD
        printf("%d ", root->data);
    }
}
// INORDER TRAVERSAL
void inorder(struct node *root)
{
    if (root != NULL)
    {
        inorder(root->left);
        printf("%d ", root->data); // RECURSIVE METHOD
        inorder(root->right);
    }
}

// TO check it is binary SEARCH tree is or not...

int IsBst(struct node *root)
{
    static struct node *prev = NULL;
    if (root != NULL)
    {
        if (!IsBst(root->left))
        {
            return 0;
        }
        if (prev != NULL && root->data <= prev->data)
        {
            return 0;
        }
        prev = root;
        return IsBst(root->right);
    }
    else
        return 1;
}

// Searching element in the binary search treee.

struct node *search(struct node *root, int key)
{
    if (root == NULL)
    {
        return NULL;
    }
    if (root->data == key)
    {
        return root;
    }
    else if (key > root->data)
    {
        return search(root->right, key); // RECURSIVE METHOD
    }
    else
        return search(root->left, key);
}

struct node *inOrderPredecessor(struct node* root){
    root = root->left;
    while (root->right!=NULL)
    {
        root = root->right;
    }
    return root;
}


struct node *deleteNode(struct node *root, int value){

    struct node* iPre;
    if (root == NULL){
        return NULL;
    }
    if (root->left==NULL&&root->right==NULL){
        free(root);
    }

    //searching for the node to be deleted
    if (value < root->data){
        deleteNode(root->left,value);
    }
    else if (value > root->data){
        deleteNode(root->right,value);
    }
    //deletion strategy when the node is found
    else{
        iPre = inOrderPredecessor(root);
        root->data = iPre->data;
        deleteNode(root->left, iPre->data);
    }
}

int main()
{

    struct node *s = createnode(5); // CREATING THE TREE
    struct node *s1 = createnode(3);
    struct node *s2 = createnode(6);
    struct node *s3 = createnode(1);
    struct node *s4 = createnode(4);
    struct node *s6 = createnode(7);

    s->left = s1;
    s->right = s2;
    s1->left = s3;
    s1->right = s4;
    s2->right = s6;

    // preorder(s);
    // printf("\n");
    // postorder(s);
    // printf("\n");
    inorder(s);
    printf("\n");

  /*  // PRINTING THE IT IS OR NOT BST TREE

    if (IsBst(s))
    {
        printf("It is a binary search tree\n");
    }
    else
        printf("It is not a binary search tree\n");

    // PRINTING ELEMENT IS FOUND OR NOT

    struct node *n = search(s, 5);
    if (n != NULL)
    {
        printf("Elemment Found %d \n", n->data);
    }
    else
    {
        printf("ELement is not found");
    }*/

    return 0;
}
#include<stdio.h>
#include<stdlib.h>

struct node
{
    int data;
    struct node*left;
    struct node*right;

};

struct node *createNode(int data){
    struct node *n = (struct node *)malloc(sizeof(struct node)) ;
    n->data=data;
    n->left=NULL;
    n->right=NULL;
}
struct node * searchIter(struct node * root, int key){
    while (root!=NULL)
    {
        if(key==root->data){
            return root;
        }
        else if (key > root->data)
        {
            root = root->right;
        }else{
            root = root->left;
        }
        
    }
    return NULL;
    
}


int main(){

    //creating binary tree
struct node *p = createNode(5);
    struct node *p1 = createNode(3);
    struct node *p2 = createNode(6);
    struct node *p3 = createNode(1);
    struct node *p4 = createNode(4);
    //linking nodes
    p->left = p1;
    p->right = p2;
    p1->left = p3;
    p1->right = p4;



    struct node* n = searchIter(p, 6);
    if(n!=NULL){
    printf("Found: %d", n->data);
    }
    else{
        printf("Element not found");
    }
    return 0;
}
#include<stdio.h>
 
 
void display(int arr[], int n){
    // Code for Traversal
    for (int i = 0; i < n; i++)
    {
        printf("%d ", arr[i]);
    }
    printf("\n");   
}
 
int indInsertion(int arr[], int size, int element, int capacity, int index){
    // code for Insertion
    if(size>=capacity){
        return -1;
    }
    for (int i = size-1; i >=index; i--)
    {
        arr[i+1] = arr[i];
    }
    arr[index] = element;
    return 1; 
}
void indDeletion(int arr[], int size, int index)
{
    // code for Deletion
    for (int i = index; i < size-1; i++)
    {
        arr[i] = arr[i + 1];
    }  
}
 
 
int main(){
    int arr[100] = {7, 8, 12, 27, 88};
    int size = 5, element = 45, index=0;
    display(arr, size); 
   // indInsertion(arr, size, element, 100, index);
    //size +=1;
    //display(arr, size);
    indDeletion(arr,size,index);
    size--;
    display(arr,size);
    return 0;
}
#include<stdio.h>
#include<stdlib.h>
 
struct myArray
{
    int total_size;
    int used_size;
    int *ptr;
};
 
void createArray(struct myArray * a, int tSize, int uSize){
    // (*a).total_size = tSize;
    // (*a).used_size = uSize;
    // (*a).ptr = (int *)malloc(tSize * sizeof(int));
 
    a->total_size = tSize;
    a->used_size = uSize;
    a->ptr = (int *)malloc(tSize * sizeof(int));
}

void show(struct myArray *a){
    for (int i = 0; i < a->used_size; i++)
    {
        printf("%d\n", (a->ptr)[i]);
    }
}

void setVal(struct myArray *a){
    int n;
    for (int i = 0; i < a->used_size; i++)
    {
        printf("Enter element %d  :",i+1);
        scanf("%d", &n);
        (a->ptr)[i] = n;
    }
}
 
int main(){
    struct myArray marks;
    createArray(&marks, 10, 5);
    printf("We are running setVal now\n");
    setVal(&marks);
 
    printf("We are running show now\n");
    show(&marks);
 
    return 0;
}
#include <stdio.h>
#include <stdlib.h>

struct node {
    int data;
    struct node *next;
};

struct node *head;

void insert_at_beginning(int value);
void insert_at_last(int value);
void insert_at_position(int value, int position);
void insert_after_value(int value, int data);

void delete_at_beginning();
void delete_at_last();
void delete_at_position(int position);
void delete_after_value(int value);

void print_list();
void print_reverse(struct node* current);

int find_index(int_value);

void find_all_indices(int value);

void reverse_list();

int main() {
    int option, choice, value, position, data;
    while (1) {
        printf("\nMENU\n");
        printf("1. Insert values\n");
        printf("2. Delete values from the list\n");
        printf("3. Traverse the list\n");
        printf("4. Find the index of 1st occurence of value in list\n");
        printf("5. Find all indices correspoding to occurence of value\n");
        printf("6. Reverse the sequence of value in the list\n");
        printf("Enter your option: ");
        scanf("%d", &option);
        
        switch(option){
            case 1:
                printf("1. Insert at beginning\n");
                printf("2. Insert after last\n");
                printf("3. Insert at position\n");
                printf("4. Insert after a particular value\n");
                printf("5. Exit\n");
                printf("Enter your choice: ");
                scanf("%d", &choice);
                
                switch (choice) {
                    case 1:
                        printf("Enter value to insert: ");
                        scanf("%d", &value);
                        insert_at_beginning(value);
                        break;
                    case 2:
                        printf("Enter value to insert: ");
                        scanf("%d", &value);
                        insert_at_last(value);
                        break;
                    case 3:
                        printf("Enter value to insert: ");
                        scanf("%d", &value);
                        printf("Enter position to insert: ");
                        scanf("%d", &position);
                        insert_at_position(value, position);
                        break;
                    case 4:
                        printf("Enter value to insert after: ");
                        scanf("%d", &value);
                        printf("Enter data to insert: ");
                        scanf("%d", &data);
                        insert_after_value(value, data);
                        break;
                    case 5:
                        exit(0);
                    default:
                        printf("Invalid choice\n");
                        break;
                }
                break;
            case 2:
                printf("1. Delete at beginning\n");
                printf("2. Delete after last\n");
                printf("3. Delete at position\n");
                printf("4. Delete after a particular value\n");
                printf("5. Exit\n");
                printf("Enter your choice: ");
                scanf("%d", &choice);
                
                switch (choice) {
                    case 1:
                        delete_at_beginning(value);
                        break;
                    case 2:
                        delete_at_last(value);
                        break;
                    case 3:
                        printf("Enter position to delete: ");
                        scanf("%d", &position);
                        delete_at_position(position);
                        break;
                    case 4:
                        printf("Enter value to delete a node after that particular value: ");
                        scanf("%d", &value);
                        delete_after_value(value);
                        break;
                    case 5:
                        exit(0);
                    default:
                        printf("Invalid choice\n");
                        break;
                }
                break;
            case 3:
                printf("1. Print all the values in list\n");
                printf("2. Print values in reverse\n");
                printf("3. Exit\n");
                printf("Enter your choice: ");
                scanf("%d", &choice);
                
                switch (choice) {
                    case 1:
                        print_list();
                        break;
                    case 2:
                        printf("List in reverse order: ");
                        print_reverse(head);
                        printf("\n");
                        break;
                }
                break;
            case 4:
                printf("Enter value to find index: ");
                scanf("%d", &value);
                int index = find_index(value);
                if (index == -1) {
                    printf("Value not found\n");
                } 
                else {
                    printf("Index of first occurrence of %d: %d\n", value, index);
                }
                break;
            case 5:
                printf("Enter value to find all indices: ");
                scanf("%d", &value);
                find_all_indices(value);
                break;
            case 6:
                reverse_list();
                printf("List reversed successfully\n");
                break;
        }
    }
}

void insert_at_beginning(int value) {
    struct node *new_node = (struct node*) malloc(sizeof(struct node));
    new_node->data = value;
    new_node->next = head;
    head = new_node;
    printf("Value %d inserted at beginning\n", value);
}

void insert_at_last(int value) {
    if (head == NULL) {
        insert_at_beginning(value);
        return;
    }

    struct node *current = head;
    while (current->next != NULL) {
        current = current->next;
    }

    struct node *new_node = (struct node*) malloc(sizeof(struct node));
    new_node->data = value;
    new_node->next = NULL;
    current->next = new_node;

    printf("Value %d inserted after last\n", value);
}

void insert_at_position(int value, int position) {
    if (position == 0) {
        insert_at_beginning(value);
        return;
    }

    struct node *current = head;
    int i = 0;
    while (i < position - 1 && current != NULL) {
        current = current->next;
        i++;
    }

    if (current == NULL) {
        printf("Invalid position\n");
        return;
    }

    struct node *new_node = (struct node*) malloc(sizeof(struct node));
    new_node->data = value;
    new_node->next = current->next;
    current->next = new_node;

    printf("Value %d inserted at position %d\n", value, position);
}

// Function to insert a new node after a particular value in the linked list
void insert_after_value(int value, int data) {
    if (head == NULL) {
        printf("List is empty\n");
        return;
    }
    struct node* current = head;
    while (current != NULL && current->data != value) {
        current = current->next;
    }
    if (current == NULL) {
        printf("Value not found\n");
        return;
    }
    struct node* new_node = (struct node*) malloc(sizeof(struct node));
    new_node->data = data;
    new_node->next = current->next;
    current->next = new_node;
}


// Function to delete the first node from the linked list
void delete_at_beginning() {
    if (head == NULL) {
        printf("List is empty\n");
        return;
    }
    struct node* temp = head;
    head = head->next;
    free(temp);
}

// Function to delete the last node from the linked list
void delete_at_last() {
    if (head == NULL) {
        printf("List is empty\n");
        return;
    }
    if (head->next == NULL) {
        free(head);
        head = NULL;
        return;
    }
    struct node* current = head;
    while (current->next->next != NULL) {
        current = current->next;
    }
    free(current->next);
    current->next = NULL;
}

// Function to delete a node at a particular position/index in the linked list
void delete_at_position(int position) {
    if (head == NULL) {
        printf("List is empty\n");
        return;
    }
    if (position == 0) {
        delete_at_beginning();
        return;
    }
    struct node* current = head;
    int i;
    for (i = 0; i < position - 1 && current != NULL; i++) {
        current = current->next;
    }
    if (current == NULL || current->next == NULL) {
        printf("Invalid position\n");
        return;
    }
    struct node* temp = current->next;
    current->next = temp->next;
    free(temp);
}

// Function to delete the node after a particular value in the linked list
void delete_after_value(int value) {
    if (head == NULL) {
        printf("List is empty\n");
        return;
    }
    struct node* current = head;
    while (current != NULL && current->data != value) {
        current = current->next;
    }
    if (current == NULL || current->next == NULL) {
        printf("Value not found or last node\n");
        return;
    }
    struct node* temp = current->next;
    current->next = temp->next;
    free(temp);
}

void print_list() {
    struct node *current = head;
    printf("List: ");
    while (current != NULL) {
        printf("%d ", current->data);
        current = current->next;
    }
    printf("\n");
}

void print_reverse(struct node* current) {
    if (current == NULL) {
        return;
    }
    print_reverse(current->next);
    printf("%d ", current->data);
}

// Function to find the index of the first occurrence of a value in the linked list
int find_index(int value) {
    int index = 0;
    struct node* current = head;
    while (current != NULL) {
        if (current->data == value) {
            return index;
        }
        index++;
        current = current->next;
    }
    return -1; // Value not found
}

// Function to find all indices corresponding to the occurrence of a value in the linked list
void find_all_indices(int value) {
    int index = 0;
    struct node* current = head;
    printf("Indices of all occurrences of %d: ", value);
    while (current != NULL) {
        if (current->data == value) {
            printf("%d ", index);
        }
        index++;
        current = current->next;
    }
    printf("\n");
}

// Function to reverse the sequence of values in the linked list
void reverse_list() {
    struct node *prev_node, *current_node, *next_node;
    current_node = head;
    prev_node = NULL;
    while (current_node != NULL) {
        next_node = current_node->next;
        current_node->next = prev_node;
        prev_node = current_node;
        current_node = next_node;
    }
    head = prev_node;
}
int a[]={1,2,3,4,5};
  bool res=binary_search(a,a+5,20);
  int ind=lower_bound(a,a+5,3)-a;
  int indi=upper_bound(a,a+5,3)-a;
  cout<<indi<<endl;
int a[]={1,2,3,4,5};
  bool res=binary_search(a,a+5,20);
  cout<<res<<endl;
#include <stdio.h>
#include <stdlib.h>
struct node
{
   int data;
   struct node *next;
}*front=NULL,*rear=NULL;
void enqu(int x)
{

    struct node *t;
    t=(struct node*)malloc(sizeof(struct node));
    if(t==NULL)
        printf("queue is full");
    else
    {
         t->data=x;
         t->next=NULL;
        if(front==NULL)
             front=rear=t;
        else
        {
            rear->next=t;
            rear=t;
        }
    }
}
int deque()
{
    int x=-1;
    struct node *t;
    if(front==NULL)
        printf("queue i empty");
    else
    {
        t=front;
        x=t->data;
        front=front->next;
        free(t);
    }
    return x;
}
int qempty()
{
    return front==NULL;
}
void bfs(int g[][7],int i,int n)
{
   int v[7]={0};
   v[i]=1;
   printf("%d",i);
   enqu(i);
   while(!qempty())
   {
       int x=deque();
       for(int j=1;j<n;j++)
       {
           if(g[x][j]==1 &&v[j]==0)
           {
               printf("%d ",j);
               v[j]=1;
               enqu(j);
           }
       }
   }
}
void dfs(int g[][7],int i,int n)
{

    static int v[7]={0};
    printf("%d ",i);
    v[i]=1;
    for(int j=1;j<n;j++)
    {
        if(g[i][j]==1 && v[j]==0)
            dfs(g,j,n);
    }
}
int main()
{
   int g[7][7]={{0,0,0,0,0,0,0},
                {0,0,1,1,0,0,0},
                {0,1,0,0,1,0,0},
                {0,1,0,0,1,0,0},
                {0,0,1,1,0,1,1},
                {0,0,0,0,1,0,0},
                {0,0,0,0,1,0,0}};
      dfs(g,1,7);
}


#include <stdio.h>
#include <stdlib.h>
struct node
{
   int data;
   struct node *next;
}*front=NULL,*rear=NULL;
void enqu(int x)
{

    struct node *t;
    t=(struct node*)malloc(sizeof(struct node));
    if(t==NULL)
        printf("queue is full");
    else
    {
         t->data=x;
         t->next=NULL;
        if(front==NULL)
             front=rear=t;
        else
        {
            rear->next=t;
            rear=t;
        }
    }
}
int deque()
{
    int x=-1;
    struct node *t;
    if(front==NULL)
        printf("queue i empty");
    else
    {
        t=front;
        x=t->data;
        front=front->next;
        free(t);
    }
    return x;
}
int qempty()
{
    return front==NULL;
}
void bfs(int g[][7],int i,int n)
{
   int v[7]={0};
   v[i]=1;
   printf("%d",i);
   enqu(i);
   while(!qempty())
   {
       int x=deque();
       for(int j=1;j<n;j++)
       {
           if(g[x][j]==1 &&v[j]==0)
           {
               printf("%d ",j);
               v[j]=1;
               enqu(j);
           }
       }
   }
}
int main()
{
   int g[7][7]={{0,0,0,0,0,0,0},
                {0,0,1,1,0,0,0},
                {0,1,0,0,1,0,0},
                {0,1,0,0,1,0,0},
                {0,0,1,1,0,1,1},
                {0,0,0,0,1,0,0},
                {0,0,0,0,1,0,0}};
      bfs(g,4,7);
}


#include <bits/stdc++.h> 
int f(int ind,vector<int>&nums,vector<int>&dp)
{
    
    if(ind==0)
      return nums[ind];
    if(ind <1)
       return 0;

       if(dp[ind]!=-1)
      return dp[ind];
    int pick=nums[ind]+f(ind-2,nums,dp);
    int notp=0+f(ind-1,nums,dp);
    dp[ind]=max(pick,notp);
    return max(pick,notp);
}
int maximumNonAdjacentSum(vector<int> &nums){
    // Write your code here.
    int n=nums.size();
    vector<int> dp(n,-1);
    return f(n-1,nums,dp);
}
#include <bits/stdc++.h> 

int maximumNonAdjacentSum(vector<int> &nums){
    // Write your code here.
    int n=nums.size();

    int prev2=0;
    int pre=nums[0],curri=0;

    for(int i=1;i<n;i++)
    {
        int pick=nums[i];
        if(i>1)
         pick+=prev2;
         
        int notp=0+pre;
        curri=max(pick,notp);
        prev2=pre;
        pre=curri;
    }
    return pre;
}
#include <bits/stdc++.h> 
int f(int ind,vector<int>&nums,vector<int>&dp)
{
    
    if(ind==0)
      return nums[ind];
    if(ind <1)
       return 0;

       if(dp[ind]!=-1)
      return dp[ind];
    int pick=nums[ind]+f(ind-2,nums,dp);
    int notp=0+f(ind-1,nums,dp);
    dp[ind]=max(pick,notp);
    return max(pick,notp);
}
int maximumNonAdjacentSum(vector<int> &nums){
    // Write your code here.
    int n=nums.size();
    vector<int> dp(n,-1);
    return f(n-1,nums,dp);
}
#include<stdio.h>
#include<stdlib.h>
#define MAX_SIZE 100
struct Node
{
  int data;
  struct Node *left, *right;
};

struct Stack
{
  int size;
  int top;
  struct Node **array;
};

struct Node *newNode (int data)
{
  struct Node *node = (struct Node *) malloc (sizeof (struct Node));
  node->data = data;
  node->left = node->right = NULL;
  return node;
}

struct Stack *createStack (int size)
{
  struct Stack *stack = (struct Stack *) malloc (sizeof (struct Stack));
  stack->size = size;
  stack->top = -1;
  stack->array =
    (struct Node **) malloc (stack->size * sizeof (struct Node *));
  return stack;
}

int isFull (struct Stack *stack)
{
  return stack->top - 1 == stack->size;
}

int isEmpty (struct Stack *stack)
{
  return stack->top == -1;
}

void push (struct Stack *stack, struct Node *node)
{
  if (isFull (stack))
    return;
  stack->array[++stack->top] = node;
}

struct Node *pop (struct Stack *stack)
{
  if (isEmpty (stack))
    return NULL;
  return stack->array[stack->top--];
}

struct Node *peek (struct Stack *stack)
{
  if (isEmpty (stack))
    return NULL;
  return stack->array[stack->top];
}

void postorder (struct Node *root)
{
  if (root == NULL)
    return;

  struct Stack *stack = createStack (MAX_SIZE);
  do
    {
      while (root)
    {
      if (root->right)
        push (stack, root->right);
      push (stack, root);

      root = root->left;
    }

      root = pop (stack);

      if (root->right && peek (stack) == root->right)
    {
      pop (stack);
      push (stack, root);
      root = root->right;

    }
      else
    {
      printf ("%d ", root->data);
      root = NULL;
    }
    }
  while (!isEmpty (stack));
}

int main ()
{

  struct Node *root = NULL;
  root = newNode (10);
  root->left = newNode (20);
  root->right = newNode (30);
  root->left->left = newNode (40);
  root->left->right = newNode (50);
  root->right->left = newNode (60);
  root->right->right = newNode (70);
  printf ("Post order traversal of binary tree is :\n");
  printf ("[");
  postorder(root);
  printf ("]");

  return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct node
{
    struct node *left;
    struct node *right;
    int data;
};

struct stack
{
    struct node *data;
    struct stack *next;
};

void push(struct stack **top, struct node *n);
struct node *pop(struct stack **top);
int isEmpty(struct stack *top);

int tree_traversal(struct node *root)
{
    struct node *temp = root;
    struct stack *s_temp = NULL;
    int flag = 1;
    while (flag)
    {
        if (temp)
        {
            printf("%d ", temp->data);
            push(&s_temp, temp);
            temp = temp->left;
        }
        else
        {
            if (!isEmpty(s_temp))
            {
                temp = pop(&s_temp);
                temp = temp->right;
            }
            else
                flag = 0;
        }
    }
}

void push(struct stack **top, struct node *n)
{
    struct stack *new_n = (struct stack *)malloc(sizeof(struct stack));
    new_n->data = n;
    new_n->next = (*top);
    (*top) = new_n;
}

int isEmpty(struct stack *top)
{
    if (top == NULL)
        return 1;
    else
        return 0;
}

struct node *pop(struct stack **top_n)
{
    struct node *item;
    struct stack *top;
    top = *top_n;
    item = top->data;
    *top_n = top->next;
    free(top);
    return item;
}

struct node *create_node(int data)
{
    struct node *new_n = (struct node *)malloc(sizeof(struct node));
    new_n->data = data;
    new_n->left = NULL;
    new_n->right = NULL;
    return (new_n);
}

int main()
{
    struct node *root;
    root = create_node(8);
    root->left = create_node(5);
    root->right = create_node(4);
    root->left->left = create_node(7);
    root->left->right = create_node(6);
    tree_traversal(root);
    return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct node
{
    struct node *left;
    struct node *right;
    int data;
};

struct stack
{
    struct node *data;
    struct stack *next;
};

void push(struct stack **top, struct node *n);
struct node *pop(struct stack **top);
int isEmpty(struct stack *top);

int tree_traversal(struct node *root)
{
    struct node *temp = root;
    struct stack *s_temp = NULL;
    int flag = 1;
    while (flag)
    {
        if (temp)
        {
            printf("%d ", temp->data);
            push(&s_temp, temp);
            temp = temp->left;
        }
        else
        {
            if (!isEmpty(s_temp))
            {
                temp = pop(&s_temp);
                temp = temp->right;
            }
            else
                flag = 0;
        }
    }
}

void push(struct stack **top, struct node *n)
{
    struct stack *new_n = (struct stack *)malloc(sizeof(struct stack));
    new_n->data = n;
    new_n->next = (*top);
    (*top) = new_n;
}

int isEmpty(struct stack *top)
{
    if (top == NULL)
        return 1;
    else
        return 0;
}

struct node *pop(struct stack **top_n)
{
    struct node *item;
    struct stack *top;
    top = *top_n;
    item = top->data;
    *top_n = top->next;
    free(top);
    return item;
}

struct node *create_node(int data)
{
    struct node *new_n = (struct node *)malloc(sizeof(struct node));
    new_n->data = data;
    new_n->left = NULL;
    new_n->right = NULL;
    return (new_n);
}

int main()
{
    struct node *root;
    root = create_node(8);
    root->left = create_node(5);
    root->right = create_node(4);
    root->left->left = create_node(7);
    root->left->right = create_node(6);
    tree_traversal(root);
    return 0;
}
void mirror(struct node *t)
{
    if(t==NULL)
        return;
    else
    {
        struct node *m;
        m=t->left;
        t->left=t->right;
        t->right=m;
        mirror(t->left);
        mirror(t->right);

    }
}
int evl(char *postfix)
{
    int i=0,x1,x2,r=0;
    for(i=strlen(postfix); i>=0;i--)
    {
        if(isOperand(postfix[i]))
            push(postfix[i]-'0');
        else
        {
            x1=pop();
            x2=pop();
            switch(postfix[i])
            {
                case '+':r=x1+x2;break;
                case '-':r=x1-x2;break;
                case '*':r=x1*x2;break;
                case '/':r=x1/x2;break;
            }
            push(r);
        }
    }
    return pop();
}
int main()
{
    char *postfix="+2/62";
    printf("%d",evl(postfix));


}
int evl(char *postfix)
{
    int i=0,x1,x2,r=0;
    for(i=0;postfix[i]!='\0';i++)
    {
        if(isOperand(postfix[i]))
            push(postfix[i]-'0');
        else
        {
            x2=pop();
            x1=pop();
            switch(postfix[i])
            {
                case '+':r=x1+x2;break;
                case '-':r=x1-x2;break;
                case '*':r=x1*x2;break;
                case '/':r=x1/x2;break;
            }
            push(r);
        }
    }
    return pop();
}
int main()
{
    char *postfix="234*+82/-";
    printf("%d",evl(postfix));


}
#include <stdio.h>
#include <stdlib.h>
#include<strings.h>
struct Node
{
 char data;
 struct Node *next;
}*top=NULL;
void push(char x)
{
 struct Node *t;
 t=(struct Node*)malloc(sizeof(struct Node));

 if(t==NULL)
 printf("stack is full\n");
 else
 {
 t->data=x;
 t->next=top;
 top=t;
 }

}
char pop()
{
 struct Node *t;
 char x=-1;

 if(top==NULL)
 printf("Stack is Empty\n");
 else
 {
 t=top;
 top=top->next;
 x=t->data;
 free(t);
 }
 return x;
}
int pre(char x)
{
    if(x=='+'||x=='-')
        return 1;
    else if(x=='/' || x=='*')
        return 2;
    else if(x=='%' || x=='^')
        return 3;
    else
        return 0;

}
int isOperand(char x)
{
   if(x=='+' || x=='-' || x=='(' || x==')'|| x=='*'||x=='/'||x=='^')
      return 0;
   else
      return 1;

}
void intopost(char infix[])
{
    int i=0;
    while(infix[i]!='\0')
    {
        if(infix[i]=='(')
            push(infix[i++]);
        else if(isOperand(infix[i]))
        {
            scanf("%c",infix[i]);
            i++;
        }
        else if(infix[i]==')')
        {
            char x=pop();
                while(x!='(')
                {
                    printf("%c",x);;
                    x=pop();
                }
                i++;
        }
        else{
                if(top==NULL)
                    push(infix[i++]);
                else if(pre(infix[i])>pre(top->data))
                     push(infix[i++]);
                else
                   printf("%c",pop());

        }
    }
        while(top!=NULL)
            printf("%c",pop());


}
int main()
{
    char *infix;
    infix="a+(b*c)";
    intopost(infix);


}
#include <stdio.h>
#include <stdlib.h>
#include<strings.h>
struct Node
{
 char data;
 struct Node *next;
}*top=NULL;
void push(char x)
{
 struct Node *t;
 t=(struct Node*)malloc(sizeof(struct Node));

 if(t==NULL)
 printf("stack is full\n");
 else
 {
 t->data=x;
 t->next=top;
 top=t;
 }

}
char pop()
{
 struct Node *t;
 char x=-1;

 if(top==NULL)
 printf("Stack is Empty\n");
 else
 {
 t=top;
 top=top->next;
 x=t->data;
 free(t);
 }
 return x;
}
int pre(char x)
{
      if(x=='+' || x=='-')
          return 1;
      else if(x=='*' || x=='/')
         return 2;
      else if(x=='^')
          return 3;
    return 0;
}
int isOperand(char x)
{
 if(x=='+' || x=='-' || x=='*' || x=='/'||x=='^'||x==')')
    return 0;
 else
    return 1;

}
char *intopost(char infix[])
{
    int i=0,j=0;
   // push('(');
   // strcat(infix,')');
    char *postfix;
    int len=strlen(infix);
    postfix=(char*)malloc((len+2)*sizeof(char));
    while(infix[i]!='\0')
    {
           if(infix[i]=='(')
              push(infix[i++]);
           else if(isOperand(infix[i]))
              postfix[j++]=infix[i++];
            else if(infix[i]==')')
            {
                char x=pop();
                while(x!='(')
                {
                    postfix[j++]=x;
                    x=pop();
                }
                i++;
            }
            else
            {
                if(top==NULL)
                    push(infix[i++]);
                else if(pre(infix[i])>pre(top->data))
                     push(infix[i++]);
                else
                   postfix[j++]=pop();


            }
        }
            while(top!=NULL)
               postfix[j++]=pop();
      postfix[j]='\0';
      return postfix;

}
int main()
{
    int n;
    scanf("%d",&n);
    char infix[n];
    for(int i=0;i<n;i++)
       scanf("%c",&infix[i]);

     int i=0,j=n-1;
     while(i<j)
     {
         char temp=infix[i];
         infix[i]=infix[j];
         infix[j]=temp;
     }


    //printf("%s",infix);

   char *postfix=intopost(infix);
    i=0,j=n-1;
    while(i<j)
     {
         char temp=postfix[i];
         postfix[i]=postfix[j];
         postfix[j]=temp;
     }
      for(int i=0;i<n;i++)
       scanf("%c",postfix[i]);

  // printf("%s ",postfix);
      return 0;
}
// C program for Merge Sort 
#include <stdio.h>
#include <stdlib.h>
  
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, 
           int m, int r)
{
    int i, j, k;
    int n1 = m - l + 1;
    int n2 = r - m;
  
    // Create temp arrays
    int L[n1], R[n2];
  
    // Copy data to temp arrays 
    // L[] and R[] 
    for (i = 0; i < n1; i++)
        L[i] = arr[l + i];
    for (j = 0; j < n2; j++)
        R[j] = arr[m + 1 + j];
  
    // Merge the temp arrays back 
    // into arr[l..r]
    // Initial index of first subarray
    i = 0; 
  
    // Initial index of second subarray
    j = 0; 
  
    // Initial index of merged subarray
    k = l; 
    while (i < n1 && j < n2) 
    {
        if (L[i] <= R[j]) 
        {
            arr[k] = L[i];
            i++;
        }
        else 
        {
            arr[k] = R[j];
            j++;
        }
        k++;
    }
  
    // Copy the remaining elements 
    // of L[], if there are any
    while (i < n1) {
        arr[k] = L[i];
        i++;
        k++;
    }
  
    // Copy the remaining elements of 
    // R[], if there are any 
    while (j < n2) 
    {
        arr[k] = R[j];
        j++;
        k++;
    }
}
  
// l is for left index and r is 
// right index of the sub-array 
// of arr to be sorted 
void mergeSort(int arr[], 
               int l, int r)
{
    if (l < r) 
    {
        // Same as (l+r)/2, but avoids 
        // overflow for large l and h
        int m = l + (r - l) / 2;
  
        // Sort first and second halves
        mergeSort(arr, l, m);
        mergeSort(arr, m + 1, r);
  
        merge(arr, l, m, r);
    }
}
  
// UTILITY FUNCTIONS 
// Function to print an array 
void printArray(int A[], int size)
{
    int i;
    for (i = 0; i < size; i++)
        printf("%d ", A[i]);
    printf("\n");
}
  
// Driver code
int main()
{
    int arr[] = {12, 11, 13, 5, 6, 7};
    int arr_size = sizeof(arr) / sizeof(arr[0]);
  
    printf("Given array is \n");
    printArray(arr, arr_size);
  
    mergeSort(arr, 0, arr_size - 1);
  
    printf("\nSorted array is \n");
    printArray(arr, arr_size);
    return 0;
}
#include<stdio.h>
void quicksort(int number[25],int first,int last){
   int i, j, pivot, temp;
   if(first<last){
      pivot=first;
      i=first;
      j=last;
      while(i<j){
         while(number[i]<=number[pivot]&&i<last)
         i++;
         while(number[j]>number[pivot])
         j--;
         if(i<j){
            temp=number[i];
            number[i]=number[j];
            number[j]=temp;
         }
      }
      temp=number[pivot];
      number[pivot]=number[j];
      number[j]=temp;
      quicksort(number,first,j-1);
      quicksort(number,j+1,last);
   }
}
int main(){
   int i, count, number[25];
   printf("How many elements are u going to enter?: ");
   scanf("%d",&count);
   printf("Enter %d elements: ", count);
   for(i=0;i<count;i++)
   scanf("%d",&number[i]);
   quicksort(number,0,count-1);
   printf("Order of Sorted elements: ");
   for(i=0;i<count;i++)
   printf(" %d",number[i]);
   return 0;
}
// Selection sort in C
#include <stdio.h>
// function to swap the the position of two elements
void swap(int *a, int *b) {
  int temp = *a;
  *a = *b;
  *b = temp;
}
void selectionSort(int array[], int size) {
  for (int step = 0; step < size - 1; step++) {
    int min_idx = step;
    for (int i = step + 1; i < size; i++) 
{
      // To sort in descending order, change > to < in this line.
      // Select the minimum element in each loop.
      if (array[i] < array[min_idx])
        min_idx = i;
    }
    // put min at the correct position
    swap(&array[min_idx], &array[step]);
  }
}
// function to print an array
void printArray(int array[], int size) {
  for (int i = 0; i < size; ++i) {
    printf("%d  ", array[i]);
  }
  printf("\n");
}
// driver code
int main() {
  int data[] = {20, 12, 10, 15, 2};
  int size = sizeof(data) / sizeof(data[0]);
  selectionSort(data, size);
  printf("Sorted array in Acsending Order:\n");
  printArray(data, size);
}
// Selection sort in C
#include <stdio.h>
// function to swap the the position of two elements
void swap(int *a, int *b) {
  int temp = *a;
  *a = *b;
  *b = temp;
}
void selectionSort(int array[], int size) {
  for (int step = 0; step < size - 1; step++) {
    int min_idx = step;
    for (int i = step + 1; i < size; i++) 
{
      // To sort in descending order, change > to < in this line.
      // Select the minimum element in each loop.
      if (array[i] < array[min_idx])
        min_idx = i;
    }
    // put min at the correct position
    swap(&array[min_idx], &array[step]);
  }
}
// function to print an array
void printArray(int array[], int size) {
  for (int i = 0; i < size; ++i) {
    printf("%d  ", array[i]);
  }
  printf("\n");
}
// driver code
int main() {
  int data[] = {20, 12, 10, 15, 2};
  int size = sizeof(data) / sizeof(data[0]);
  selectionSort(data, size);
  printf("Sorted array in Acsending Order:\n");
  printArray(data, size);
}
#include <stdio.h>
 
void bubble_sort(long [], long);
 
int main()
{
  long array[100], n, c, d, swap;
 
  printf("Enter number of elements\n");
  scanf("%ld", &n);
 
  printf("Enter %ld longegers\n", n);
 
  for (c = 0; c < n; c++)
    scanf("%ld", &array[c]);
 
  bubble_sort(array, n);
 
  printf("Sorted list in ascending order:\n");
 
  for ( c = 0 ; c < n ; c++ )
     printf("%ld\n", array[c]);
 
  return 0;
}
 
void bubble_sort(long list[], long n)
{
  long c, d, t;
 
  for (c = 0 ; c < ( n - 1 ); c++)
  {
    for (d = 0 ; d < n - c - 1; d++)
    {
      if (list[d] > list[d+1])
      {
        /* Swapping */
 
        t         = list[d];
        list[d]   = list[d+1];
        list[d+1] = t;
      }
    }
  }
}
#include <stdio.h>
int main() {
  int r, c, a[100][100], b[100][100], sum[100][100], i, j;
  printf("Enter the number of rows (between 1 and 100): ");
  scanf("%d", &r);
  printf("Enter the number of columns (between 1 and 100): ");
  scanf("%d", &c);

  printf("\nEnter elements of 1st matrix:\n");
  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      printf("Enter element a%d%d: ", i + 1, j + 1);
      scanf("%d", &a[i][j]);
    }

  printf("Enter elements of 2nd matrix:\n");
  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      printf("Enter element b%d%d: ", i + 1, j + 1);
      scanf("%d", &b[i][j]);
    }

  // adding two matrices
  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      sum[i][j] = a[i][j] + b[i][j];
    }

  // printing the result
  printf("\nSum of two matrices: \n");
  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      printf("%d   ", sum[i][j]);
      if (j == c - 1) {
        printf("\n\n");
      }
    }

  return 0;
}
#include <stdio.h>
int main() {
  int a[10][10], transpose[10][10], r, c;
  printf("Enter rows and columns: ");
  scanf("%d %d", &r, &c);

  // asssigning elements to the matrix
  printf("\nEnter matrix elements:\n");
  for (int i = 0; i < r; ++i)
  for (int j = 0; j < c; ++j) {
    printf("Enter element a%d%d: ", i + 1, j + 1);
    scanf("%d", &a[i][j]);
  }

  // printing the matrix a[][]
  printf("\nEntered matrix: \n");
  for (int i = 0; i < r; ++i)
  for (int j = 0; j < c; ++j) {
    printf("%d  ", a[i][j]);
    if (j == c - 1)
    printf("\n");
  }

  // computing the transpose
  for (int i = 0; i < r; ++i)
  for (int j = 0; j < c; ++j) {
    transpose[j][i] = a[i][j];
  }

  // printing the transpose
  printf("\nTranspose of the matrix:\n");
  for (int i = 0; i < c; ++i)
  for (int j = 0; j < r; ++j) {
    printf("%d  ", transpose[i][j]);
    if (j == r - 1)
    printf("\n");
  }
  return 0;
}
#include <stdio.h>

/*Write C code that does the following operation. 
-	Asks and gets the number of WINs (3 points/win), DRAWs (1 points/draw) and LOSSes (0 points/loss) for four football teams. 
-	Records them in a multidimensional array. 
-	Calculates the total scores. 
-	Reports the score table.*/


int main() {
    int score[3][3];
    for(int i=0;i<3;i++)
    {
        printf("enter win draw and loss of team %d: ",i+1);
        scanf("%d %d %d ",&score[i][0],&score[i][1],&score[i][2]);
    }
    printf("team name\t  win\t draw\t loss\t points\n");
    for(int i=0;i<3;i++)
    {
        int points=score[i][0]*3+score[i][1]*1;
        printf("\nteam %d\t\t  %d\t\t  %d\t\t %d\t\t  %d\n",i+1,score[i][0],score[i][1],score[i][2],points);
    }
    
    
    return 0;
}


output:

enter win draw and loss of team 1: 2
1
1
1
enter win draw and loss of team 2: 2
3
1
enter win draw and loss of team 3: 3
3
2
team name	  win	 draw	 loss	 points

team 1		  2		  1		 1		  7

team 2		  1		  2		 3		  5

team 3		  1		  3		 3		  6
#include <iostream>
using namespace std;

int main()
{
    int *p;
    p= (int *)malloc(5*sizeof(int));  
    //will allocate memory for 5 integers, so it is an array of integers and it is assigned to p
    
    //initializing the values
    p[0] = 10;
    p[1] = 20;
    p[2] = 30;
    p[3] = 40;
    p[4] = 50;

    
    for(int i=0; i<5; i++)
    {
        cout << p[i] << endl;
    }
    
    return 0;
}
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int data[5]={14,33,27,35,10};
    int i,j;
    int swap;
    int temp;
    for(int i=0;i<5;i++)
    {
        printf("please enter array element %d: ",i+1);
        scanf("%d",&data[i]);
    }
    for(int i=0;i<5-1;i++)
    {
        swap=0;
        for(int j=0;j<5-1;j++)
        {
            if(data[j]>data[j+1])
            {
                temp=data[j];
                data[j]=data[j+1];
                data[j+1]=temp;
            }
        }
    }
    printf("bubble sort of array are: ");
    for(int i=0;i<5; i++)
    {
        printf("%d ",data[i]);
    }
    printf("\n");

    
    return 0;
}
#include <stdio.h>

int main() {
    int arr[10]={23,43,12,18,6,48,39,65,43,-3};
    int max = arr[0];
    int min = arr[0];
    int i;
    for(i=1;i<10;i++)
    {
        if(arr[i]>max)
            max=arr[i];
        if(arr[i]<min)
            min=arr[i];
    }
    printf("the maximum number of the array is %d ",max);
    printf("\nthe minimum number of the array is %d ",min);
    
    //find second maximium and minimum number of the array
    int max2=min;
    int min2=max;
    for(i=0;i<9;i++)
    {
        if(arr[i]!=max && arr[i]>max2)
        {
            max2=arr[i];
        }
        if(arr[i]!=min && arr[i]<min2)
        {
            min2=arr[i];
        }
    }
    printf("\nthe second maximum number is %d ",max2);
    printf("\nthe second minimum number is %d ",min2);
    return 0;
}
#include <stdio.h>
#include <stdlib.h>
void findMin(int n);
void findMax(int n);
 
int main() {
   int arr[10];
   int min=arr[0], minind=0;
   int max=arr[0],maxind=0;
   
    for(int i=0;i<=9;i++)
    {
        printf("please enter element %d: ",i+1);
        scanf("%d",&arr[i]);
    }
   for(int i=1;i<=9;i++)
   {
       if(arr[i]>max)
       {
           max=arr[i];
           maxind=i;
       }
       if(arr[i]<min)
       {
           min=arr[i];
           minind=i;
       }
   }
   printf("maximum number of the array is %d at index %d\n: ",max,maxind);
   printf("\nminimum number of the array is %d at index %d\n: ",min,minind);
  
return 0;
}
#include <stdio.h>
#include <stdlib.h>

int main() {
    int arr1[6]={-20,-2,3,0,10,20};
    int arr2[4]={6,1,33,9};
    int arr3[100];
    int n1=5;
    int n2=4;
    int n3=n1+n2;
    for(int i=0; i<n1; i++)
    arr3[i]=arr1[i];
    for(int i=0; i<n2; i++)
    arr3[i + n1]= arr2[i];
    
    printf("the marged array are: ");
    for(int i=0; i<n3; i++)
    printf("%d ",arr3[i]);
    
    printf("\nFinal array after sorting: ");
    for(int i = 0; i < n3; i++){
        int temp;
        for(int j = i+1; j < n3; j++) {
            if(arr3[i] > arr3[j]) {
                temp = arr3[i];
                arr3[i] = arr3[j];
                arr3[j] = temp;
            }
        }
    }   
    for(int i = 0; i < n3 ; i++)      //print sorted array
        printf(" %d ",arr3[i]);
    

    return 0;
}
void findPeaks(int arr[],int n);
int main() {
    int arr[10];
    int i;
    int number;
    for(int i=0;i<10;i++)
    {
        printf("enter elment of the array %d: ",i+1);
        scanf("%d",&arr[i]);
    }
    for(int i=0;i<10;i++)
    {
        if(arr[i]>arr[i-1] && arr[i]>arr[i+1])
        {
            printf("the value of %d at index %d is a peak\n",arr[i],i);
        }
        else
        printf("No peak\n");
    }
    return 0;
}
/*Find minimum and maximum of the array and tell them where is the position*/
#include <stdio.h>
#include <stdlib.h>
void findMinimum(int arr[]);
void findMaximum(int arr[]);

int main() {
    int arr[10]={1,223,3,4,-11,6,7,8,9,10};
    int i;
    int minimum=arr[0];
    int maximum=arr[0];
    int minindex=0;
    int maxindex=0;
    for(int i=0;i<10;i++)
    {
        if(arr[i]<minimum)
        {minimum=arr[i];
        minindex=i+1;
        }
        if(arr[i]>maximum)
        {
            maximum=arr[i];
            maxindex=i+1;}
    }
    printf("\nthe minimum number of the array is %d at position %d",minimum,minindex);
    printf("\nthe maximum number of the array is %d at index %d",maximum,maxindex);
   
    return 0;
}
#include <stdio.h>
#include <stdlib.h>

int main() {
    int arr[5]= {1,4,3,5,6,};
    int i,j;
    int un=0;
    for(int i=0;i<5;i++)
    {
        printf("%d ",i);
        for(j=i+1;j<5;j++)
        {
            if(arr[i]==arr[j])
            {
                un=1;
                break;
            }
        }
        //if(un==1)
        //break;
    }
    if(un==1)
    {
        printf("the value is not unique:");
    }
    else
    {
        printf("the value is unique");
    }
    

    return 0;
}
#include <stdio.h>
#include <stdlib.h>

int main() {
   int arr[5]={100,60,40,78,99};
   int number;
   for(int i=0;i<5;i++)
   {
       printf("please enter numbers %d: ",i+1);
       scanf("%d",&arr[i]);
   }
   int min=arr[0];
   int max=arr[0];
   for(int i=0;i<5;i++)
   {
       if(arr[i]<min)
       min=arr[i];
       
       if(arr[i]>max)
       max=arr[i];
   }
   printf("\nmaximum number is %d: ",max);
   printf("\nminimum number is %d: ",min);
    return 0;
}
#include <stdio.h>
#include <stdlib.h>

int main() {
    int arr[9]={1,10,20,30,40,50,60,70,80};
    int number;
    int i,j;
    int entry=-1;
    printf("please enter number that you are looking for: ");
    scanf("%d",&number);
    
    while(1)
    {
        for(int i=0;i<9;i++)
        {
            if(arr[i]==number)
            entry=i;
        }
        if(entry==-1)
        {
            printf("\n%d does not exist in the array",number);
        }
        else
        {
            printf("\n%d does exist in the array it is entry %d: ",number,entry+1);
        }
        printf("\nplease enter another number: ");
        scanf("%d",&number);
        entry==-1;
    }
    
    return 0;
}
#include <stdio.h>
#include <stdlib.h>

/*2.	Write a C program that performs the following operations subsequently:
- Ask the user to enter the homework, midterm, and final exam grades of 10 students one by one and store them in an array (Create one array for each exam). Each grade is between 0 to 100.
- Calculate the overall grade and letter grade of each student. Homework represents the 30% of the overall grade, while midterm represents 30% and final represents 40%.
Student’s letter grade is determined as follows:
0 – 30 is equivalent to F
30	– 60 is equivalent to C
60	– 100 is equivalent to A.
- Your program should output the grade and letter grade of each student.*/


#include <stdio.h>
#include <stdlib.h>

int main() {
   int homework[10];
   int midterm[10];
   int final[10];
   float overall[10];
   char letter[10];
   int i;
   for(int i=0;i<10;i++)
   {
       printf("please enter homework, midterm and final grade of student %d: ",i+1);
       scanf("%d\n %d\n %d\n",&homework[i],&midterm[i],&final[i]);
   }
   
    // 0 – 30 is equivalent to F
   // 30	– 60 is equivalent to C
  //  60	– 100 is equivalent to A.

   for(int i=0;i<10;i++)
   {
       overall[i]=homework[i]*0.3+midterm[i]*0.3+final[i]*0.4;
       if(overall[i]>=60)
       letter[i]='A';
       else if(overall[i]>=30 && overall[i]<59)
       letter[i]='C';
       else
       letter[i]='F';
       
       printf("student %d overall grade is %f his or her grade letter is %c\n",i+1,overall[i],letter[i]);
   }
    return 0;
}
#include <stdio.h>
#include <stdlib.h>
void printPattern;

int main() {
   int n=5;
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<=i;j++)
       {
           printf("*");
       }
       printf("\n");
   }
return 0;
}
// Online C compiler to run C program online
#include <stdio.h>
#include <stdlib.h>

int main() {
    int arr[5]= {1,2,3,5,4};
    int i,j;
    int un=0;
    for(int i=0;i<5;i++)
    {
        printf("%d ",i);
        for(j=i+1;j<5;j++)
        {
            if(arr[i]==arr[j])
            {
                un=1;
                break;
            }
        }
        
    }
    if(un==1)
    {
        printf("the value is not unique:");
    }
    else
    {
        printf("the value is unique");
    }
    

    return 0;
}
displaying pattern

    *
   ***
  *****
 *******

finding the minimum in an array

finding the maximum in an array

find all peak points in the array

printing the contents of the array in reverse order

reverse the contents of array

count the occurence of a specific value

merge two arrays together __arr = arr1 +  arr2

find the second largest element in the array

union of two sorted arrays

#include <stdio.h>
#include <stdlib.h>
void findMinimum(int arr[],int n);
void findMaximum(int arr[],int n);
void findPeaks(int arr[],int n);
void printReverse(int arr[],int n);
void reverse1(int arr[],int n);
void reverse2(int arr[],int n);
void printArray(int arr[], int n);
void countOccurence(int arr[],int n,int val);
void merge(int arr1[],int n1,int arr2[], int n2);
void secondLargest(int arr[], int n);


int main()
{
    int arr[10];
    int i;
    for(i=0;i<10;i++)
    {
        printf("Enter element %d: ",(i+1));
        scanf("%d",&arr[i]);
    }
    //findMinimum(arr,10);
    //findMaximum(arr,10);
    //findPeaks(arr,10);
    //printReverse(arr,10);
    //reverse1(arr,10);
    //reverse2(arr,10);
    countOccurence(arr,10,5);


    return 0;
}


void secondLargest(int arr[], int n)
{
    int max = arr[0];
    int min = arr[0];
    int i;
    for(i=1;i<n;i++)
    {
        if(arr[i]>max)
            max=arr[i];
        if(arr[i]<min)
            min=arr[i];
    }
    int max2=min;
    for(i=0;i<n;i++)
    {
        if(arr[i]!=max && arr[i]>max2)
        {
            max2=arr[i];
        }
        
    }
    
    
}


void merge(int arr1[],int n1,int arr2[], int n2)
{
    int merge[n1+n2];
    int i;
    for(i=0;i<n1;i++)
    {
        merge[i]=arr1[i];
    }
    for(i=0;i<n2;i++)
    {
        merge[n1+i]=arr2[i];
    }
    
}

void countOccurence(int arr[],int n, int val)
{
    int i;
    int counter=0;
    for(i=0;i<n;i++)
    {
        if(arr[i]==val)
            counter++;
    }

    printf("%d appears %d times in the array\n",val,counter);

}



void findMinimum(int arr[],int n)
{
    int min = arr[0];
    int minind = 0;
    int i;
    for(i=1;i<n;i++)
    {
        if(arr[i]<min)
            {min=arr[i];
             minind=i;}
    }
    printf("The min value is %d at index %d\n",min,minind);
}

void findMaximum(int arr[],int n)
{
    int max = arr[0];
    int maxind = 0;
    int i;
    for(i=1;i<n;i++)
    {
        if(arr[i]>max)
            {max=arr[i];
             maxind=i;}
    }
    printf("The max value is %d at index %d\n",max,maxind);
}

void findPeaks(int arr[],int n)
{
    int i;
    int peaks=0;
    for(i=1;i<9;i++)
    {
        if(arr[i]>arr[i-1] && arr[i]>arr[i+1])
         {
             printf("The value %d at index %d is a peak\n",arr[i],i);
             peaks++;
         }
    }

    if(peaks==0)
        printf("no peaks encountered");
}

void printReverse(int arr[],int n)
{
    int i;
    for(i=n-1;i>=0;i--)
    {
        printf("%d ",arr[i]);
    }
}

void reverse1(int arr[],int n)
{
    int revarr[n];
    int i;
    for(i=0;i<10;i++)
    {
        revarr[i]=arr[n-1-i];
    }
    printArray(revarr,10);
}

void reverse2(int arr[],int n)
{
   /* arr[0]<=>arr[9]
    arr[1]<=>arr[8]
    arr[2]<=>arr[7]
    arr[3]<=>arr[6]
    arr[4]<=>arr[5]*/
    int i,temp;
    for(i=0;i<(n/2);i++)
    {
        temp = arr[i];
        arr[i] = arr[n-1-i];
        arr[n-1-i] = temp;
    }

    printArray(arr,10);

}

void printArray(int arr[], int n)
{
    int i;
    for(i=0;i<n;i++)
        printf("%d ",arr[i]);
}










#include <stdio.h>
#include <stdlib.h>


int main()
{
    /*
    // question 1
    int arr[10];
    int i;
    for(i=0;i<=9;i++)
    {
        printf("Element %d: ",i+1);
        scanf("%d",&arr[i]);
    }

    for(i=0;i<=9;i++)
    {
        printf("Element %d: %d\n",i+1,arr[i]);

    }*/


    /*
     // question 2
    int arr[10];
    int i;
    for(i=0;i<=9;i++)
    {
        printf("Element %d: ",i+1);
        scanf("%d",&arr[i]);
    }

    printf("Even numbers: ");
    for(i=0;i<=9;i++)
    {
        if(arr[i]%2==0)
            printf("%d ",arr[i]);
    }

    printf("\nOdd numbers: ");
    for(i=0;i<=9;i++)
    {
        if(arr[i]%2==1)
            printf("%d ",arr[i]);
    }

    */

    // q3
    int arr[10];
    int i;
    for(i=0;i<=9;i++)
    {
        printf("Element %d: ",i+1);
        scanf("%d",&arr[i]);
    }

    int sum=0;
    for(i=0;i<=9;i++)
    {
        sum=sum+arr[i];
    }
    printf("The sum of all elements is %d \n",sum);
    */


    //  Question 4
    /*
    int arr[10];
    int i;
    int evenCount=0, oddCount=0;
    for(i=0;i<=9;i++)
    {
        printf("Element %d: ",i+1);
        scanf("%d",&arr[i]);
    }

    for(i=0;i<=9;i++)
    {
        if(arr[i]%2==0)
            evenCount++;
        else
            oddCount++;
    }
    printf("The number of even elements is %d \n",evenCount);
    printf("The number of odd elements is %d \n",oddCount);
    */


 return 0;
 }




#include "MCMCLib.h"

// Define the log likelihood function
double log_likelihood(const gsl_vector *x, void *params)
{
    // Extract the parameters
    double mu = gsl_vector_get(x, 0);
    double sigma = gsl_vector_get(x, 1);

    // Compute the log likelihood
    double logL = -0.5 * log(2 * M_PI * sigma * sigma)
                  - 0.5 * (y - mu) * (y - mu) / (sigma * sigma);

    return logL;
}

// Define the function to perform MCMC sampling
void mcmc_sampling()
{
    // Set the initial values for the parameters
    gsl_vector *x = gsl_vector_alloc(2);
    gsl_vector_set(x, 0, mu0);
    gsl_vector_set(x, 1, sigma0);

    // Set the proposal distribution
    gsl_matrix *cov = gsl_matrix_alloc(2, 2);
    gsl_matrix_set_identity(cov);
    gsl_matrix_scale(cov, sigma_prop);

    // Set the MCMC options
    MCMCOptions options;
    options.n_burnin = 1000;
    options.n_iter = 10000;
    options.thinning = 10;

    // Set the MCMC data
    MCMCData data;
    data.n_params = 2;
    data.logL = log_likelihood;
    data.params = NULL;
    data.x = x;
    data.cov = cov;

    // Perform the MCMC sampling
    MCMCSample *sample = MCMCSample_alloc(options.n_iter);
    MCMC(options, data, sample);

    // Extract the samples
    for (int i = 0; i < sample->n; i++)
    {
        mu_samples[i] = gsl_vector_get(sample->x[i], 0);
        sigma_samples[i] = gsl_vector_get(sample->x[i], 1);
    }

    // Free the allocated memory
    MCMCSample_free(sample);
    gsl_vector_free(x);
    gsl_matrix_free(cov);
}
#include<stdio.h>

void WT(int processes[], int n, int bt[], int wt[])
{
	wt[0] = 0;
	
	for (int i = 1; i < n ; i++ )
		wt[i] = bt[i-1] + wt[i-1] ;
}

void TAT( int processes[], int n, int bt[], int wt[], int tat[])
{
	// bt[i] + wt[i]
	for (int i = 0; i < n ; i++)
		tat[i] = bt[i] + wt[i];
}

void AT( int processes[], int n, int bt[])
{
	int wt[n], tat[n], total_wt = 0, total_tat = 0;

	WT(processes, n, bt, wt);

	TAT(processes, n, bt, wt, tat);

	printf("Processes Bursttime Waitingtime Turn-aroundtime\n");

	for (int i=0; i<n; i++)
	{
		total_wt = total_wt + wt[i];
		total_tat = total_tat + tat[i];
		printf(" %d ",(i+1));
		printf("\t\t\t%d ", bt[i] );
		printf("\t\t\t\t%d ", wt[i] );
		printf("\t\t\t%d\n",tat[i] );
	}
	int s=(float)total_wt / (float)n;
	int t=(float)total_tat / (float)n;
	printf("Average waiting time = %d",s);
	printf("\n");
	printf("Average turn around time = %d ",t);
}

int main()
{
	int processes[] = { 1, 2, 3};
	int n = sizeof processes / sizeof processes[0];

	int burst_time[] = {10, 5, 8};

	AT(processes, n, burst_time);
	return 0;
}
#include <stdio.h>
int main()
{
   int i,j, k = 0;
   for (i = 1; i <= 5; ++i) {
      for (j = 1;j<= 5 - i; ++j) {
         printf("  ");
      }
      for(k=0;k!=2*i-1;++k) {
         printf("* ");
      }
      printf("\n");
   }
   return 0;
}
int char_to_int(char c) {
   if (c >= '0' && c <= '9') return c - '0';
   if (c >= 'A' && c <= 'F') return c - 'A' + 10;
   return 0; /* oops, something else... */
}
#include <stdint.h>
#include <stdio.h>

int main(void) {
  char myString[]="0x3f9d70a4";
  uint32_t num;
  float f;
  sscanf(myString, "%x", &num);  // assuming you checked input
  f = *((float*)&num);
  printf("the hexadecimal 0x%08x becomes %.3f as a float\n", num, f);
}
/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp32-microsd-card-arduino/
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*/

// Libraries for SD card
#include "FS.h"
#include "SD.h"
#include <SPI.h>

//Libraries for BME280 sensor
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

// Libraries to get time from NTP Server
#include <WiFi.h>
#include "time.h"

// Replace with your network credentials
const char* ssid     = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";

// Timer variables
unsigned long lastTime = 0;
unsigned long timerDelay = 30000;

// BME280 I2C
Adafruit_BME280 bme;

// Variables to hold sensor readings
float temp;
float hum;
float pres;
String dataMessage;

// NTP server to request epoch time
const char* ntpServer = "pool.ntp.org";

// Variable to save current epoch time
unsigned long epochTime; 

// Function that gets current epoch time
unsigned long getTime() {
  time_t now;
  struct tm timeinfo;
  if (!getLocalTime(&timeinfo)) {
    //Serial.println("Failed to obtain time");
    return(0);
  }
  time(&now);
  return now;
}

// Initialize WiFi
void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  Serial.println(WiFi.localIP());
}

// Init BME280
void initBME(){
  if (!bme.begin(0x76)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }
}

// Initialize SD card
void initSDCard(){
   if (!SD.begin()) {
    Serial.println("Card Mount Failed");
    return;
  }
  uint8_t cardType = SD.cardType();

  if(cardType == CARD_NONE){
    Serial.println("No SD card attached");
    return;
  }
  Serial.print("SD Card Type: ");
  if(cardType == CARD_MMC){
    Serial.println("MMC");
  } else if(cardType == CARD_SD){
    Serial.println("SDSC");
  } else if(cardType == CARD_SDHC){
    Serial.println("SDHC");
  } else {
    Serial.println("UNKNOWN");
  }
  uint64_t cardSize = SD.cardSize() / (1024 * 1024);
  Serial.printf("SD Card Size: %lluMB\n", cardSize);
}

// Write to the SD card
void writeFile(fs::FS &fs, const char * path, const char * message) {
  Serial.printf("Writing file: %s\n", path);

  File file = fs.open(path, FILE_WRITE);
  if(!file) {
    Serial.println("Failed to open file for writing");
    return;
  }
  if(file.print(message)) {
    Serial.println("File written");
  } else {
    Serial.println("Write failed");
  }
  file.close();
}

// Append data to the SD card
void appendFile(fs::FS &fs, const char * path, const char * message) {
  Serial.printf("Appending to file: %s\n", path);

  File file = fs.open(path, FILE_APPEND);
  if(!file) {
    Serial.println("Failed to open file for appending");
    return;
  }
  if(file.print(message)) {
    Serial.println("Message appended");
  } else {
    Serial.println("Append failed");
  }
  file.close();
}

void setup() {
  Serial.begin(115200);
  
  initWiFi();
  initBME();
  initSDCard();
  configTime(0, 0, ntpServer);
  
  // If the data.txt file doesn't exist
  // Create a file on the SD card and write the data labels
  File file = SD.open("/data.txt");
  if(!file) {
    Serial.println("File doesn't exist");
    Serial.println("Creating file...");
    writeFile(SD, "/data.txt", "Epoch Time, Temperature, Humidity, Pressure \r\n");
  }
  else {
    Serial.println("File already exists");  
  }
  file.close();
}

void loop() {
  if ((millis() - lastTime) > timerDelay) {
    //Get epoch time
    epochTime = getTime();
    
    //Get sensor readings
    temp = bme.readTemperature();
    //temp = 1.8*bme.readTemperature() + 32;
    hum = bme.readHumidity();
    pres = bme.readPressure()/100.0F;

    //Concatenate all info separated by commas
    dataMessage = String(epochTime) + "," + String(temp) + "," + String(hum) + "," + String(pres)+ "\r\n";
    Serial.print("Saving data: ");
    Serial.println(dataMessage);

    //Append the data to file
    appendFile(SD, "/data.txt", dataMessage.c_str());

    lastTime = millis();
  }
}
#include<stdio.h>
#include<conio.h>
void main()
{
   int a=10;
   int b=20;
   printf("%d \n",a<b); //true=1,false=0 a<=b,a>=bitand
   printf("%d \n",a==b); //t=1,f=0
   printf("%d \n",a!=b);
    getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
    int i=10;
    int x=i++;
    printf("%d \n",x);//10
    printf("%d \n",i);//11
    
    int j=5;
    int y=--j;//4
    printf("%d \n",y);
    getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
    int a=10;
    printf("%d \n",a);//10
    ++a;
    printf("%d \n",a);//11
    
    printf("%d \n",a++); //11
    
    printf("%d",a); //12
    
    getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
    int a,b,c,d;
    a=11;
    b=2;
    c=a%b;
    d=a/b;
    printf("reminder: %d \n",c);
    printf("quotient: %d",d);
}
#include<stdio.h>
#include<conio.h>

void main()
{
    int marks[10];
    
    marks[0]=50;
    marks[1]=20;
    
    for(int i=2;i<10;i++)
    {
        scanf("%d",&marks[i]);
    }
    
    for(int i=0;i<10;i++)
    {
        printf("marks: %d \n %d \n",i,marks[i]);    
    }
}
#include<stdio.h>
#include<conio.h>
void main()
{
    int a; //declaration
    a=5; //assign
    
    int b;
    b=2;
    
    int c,d,e;
    float f;
    c=a+b;
    d=a-b;
    e=a*b;
     f=(float)a/b;
    printf("%d %d %d %f",c,d,e,f);
    
}
#include<stdio.h>
#include<conio.h>
void main()
{
    char grade='A';
    printf("grade: %c \n",grade);
    
    double accuracy=10.12312344;
    printf("ACCURACY: %lf",accuracy); //lf= long float
    
}    
    
#include<stdio.h>
#include<conio.h>
void main()
{
    int a=5;
    printf("%d \n",a); //%d etc are  format specifiers \n new line command
    
    float b=9.2;
    printf("%f",b);
    
    getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
    int a; //declaration
    a=10; //assign
    
    int b;
    b=20;
    
    int c,d,e,f;
    c=a+b;
    d=a-b;
    e=a*b;
    f=a/b;
    printf("%d %d %d %d",c,d,e,f);
    
}
// Queue implementation in C

#include <stdio.h>
#include <stdlib.h>
#define SIZE 5

void enqueue();
void dequeue();
void display();

int items[SIZE], front = -1, rear = -1;

int main() {
  //deQueue is not possible on empty queue
  int x;
  
  printf("1 for enqueue\n");
  printf("2 for dequeue\n");
  printf("3 for display\n");
  printf("0 for exit\n");
  while(1)
  {
      printf("enter choise:");
      scanf("%d",&x);
      
      switch(x)
      {
        case 1:
            enqueue();
            break;
        case 2:
            dequeue();
            break;
        case 3:
            display();
            break;
        case 0:
            exit(1);
            printf("EXIT");
        default:
            printf("plz enter valid number\n");
      }
  }

  return 0;
}

void enqueue(){
    int value;
    
    printf("enter value to enqueue:");
    scanf("%d",&value);
    
  if (rear == SIZE - 1)
    printf("\nQueue is Full!!");
  else {
    if (front == -1)
      front = 0;
    rear++;
    items[rear] = value;
    printf("\nInserted -> %d\n", value);
  }
}

void dequeue(){
  if (front == -1)
    printf("\nQueue is Empty!!");
  else {
    printf("\nDeleted : %d\n", items[front]);
    front++;
    if (front > rear)
      front = rear = -1;
  }
}

// Function to print the queue
void display(){
  if (rear == -1)
    printf("\nQueue is Empty!!!");
  else {
    int i;
    printf("\nQueue elements are:\n");
    for (i = front; i <= rear; i++)
      printf("%d  ", items[i]);
  }
  printf("\n");
}
#include<stdio.h>
#include <stdlib.h>
int s[100],top=0,n;

void push()
{
    int x;
    
    if(top>=n)
    {
        printf("stack overflow\n");
    }
    else
    {
        printf("enter number:");
        scanf("%d",&x);
        top++;
        s[top]=x;
    }
}
void pop()
{
    if(top<=0)
    {
        printf("stack underflow\n");
    }
    else
    {
        printf("%d is popped\n",s[top]);
        top--;
    }
}
void peep()
{
    int i;
    
    printf("enter ith position:");
    scanf("%d",&i);
    
    if(top-i+1<=0)
    {
        printf("stack underflow\n");
    }
    else
    {
        printf("%d is %dth valur from the top\n",s[top-i+1],i);
    }
}
void change()
{
    int i,x;
    
    printf("enter ith position from top to change:");
    scanf("%d",&i);
    
    if(top-i+1<=0)
    {
        printf("stack underflow\n");
    }
    else
    {
        printf("enter new value:");
        scanf("%d",&x);
        
        s[top-i+1]=x;
        printf("new value of %dth position from top is %d\n",i,x);
    }
    
}
int main()
{
    int choise;
    
    printf("enter length of stack:");
    scanf("%d",&n);
    
    printf(" 1 for push \n");
    printf(" 2 for pop \n");
    printf(" 3 for peep \n");
    printf(" 4 for change \n");
    printf(" 0 for exit \n");
    
    
    while(1)
    {
        printf("enter choise:");
        scanf("%d",&choise);
        
        switch(choise)
        {
            case 1:
                push();
                break;
            case 2:
                pop();
                break;
            case 3:
                peep();
                break;
            case 4:
                change();
                break;
            case 0:
                exit(1);
                break;
            default:
                printf("enter valid number\n");
                
        }
    }
}
#include <stdio.h>

int main() {
    int myInt;
    myInt = 0xFFFFFFE2;
    printf("%d\n",myInt);

    return 0;
}
#include <cs50.h>
#include <stdio.h>

int main(void)
         {
         int x = get_int("x: ");
		 int y = get_int("y: ");
		 int z = x + y;
		 printf("%i\n", z);
         }
#include <stdio.h>

main(){
    int myAge[5];
    myAge[0] = 2;
    myAge[1] = 3;
    myAge[2] = 4;
    myAge[3] = 5;
    myAge[4] = 6;
    printf("my age is %i", myAge[0]);
    return 0;
}
#include <stdio.h>

main(){
    int age[5] = {2, 3, 4, 5, 6};
    printf("%d \n", age[0]);
    printf("%d \n", age[2]);
    printf("%d \n", age[3]);
    printf("%d \n", age[4]);
    return 0;
}
#include <cs50.h>
#include <studio.h>

int main(void)
         {
         string answer = get_string("What's your name? ");
		 printf("hello, %s\n", answer);
         }
#include <stdio.h>  
int binarySearch(int a[], int beg, int end, int val)    
{    
    int mid;    
    if(end >= beg)     
    {        mid = (beg + end)/2;    
/* if the item to be searched is present at middle */  
        if(a[mid] == val)    
        {                 
            return mid+1;    
        }    
            /* if the item to be searched is smaller than middle, then it can only be in left subarray */  
        else if(a[mid] < val)     
        {  
            return binarySearch(a, mid+1, end, val);    
        }    
            /* if the item to be searched is greater than middle, then it can only be in right subarray */  
        else     
        {  
            return binarySearch(a, beg, mid-1, val);    
        }          
    }    
    return -1;     
}   
int main() {  
  int a[] = {11, 14, 25, 30, 40, 41, 52, 57, 70}; // given array  
  int val = 40; // value to be searched  
  int n = sizeof(a) / sizeof(a[0]); // size of array  
  int res = binarySearch(a, 0, n-1, val); // Store result  
  printf("The elements of the array are - ");  
  for (int i = 0; i < n; i++)  
  printf("%d ", a[i]);   
  printf("\nElement to be searched is - %d", val);  
  if (res == -1)  
  printf("\nElement is not present in the array");  
  else  
  printf("\nElement is present at %d position of array", res);  
  return 0;  
}  
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <psapi.h>
#define SIZE_TAB 200

volatile char program[SIZE_TAB];
CRITICAL_SECTION CriticalSection;
DWORD WINAPI aa(void *v);
DWORD WINAPI bb(void *v);

int main(int argc, char *argv[])
{
InitializeCriticalSection(&CriticalSection);

HANDLE thread_a = CreateThread(NULL, 0, aa, 0, 0, 0);
HANDLE thread_b = CreateThread(NULL, 0, bb, 0, 0, 0);

while (1)
{
    for (int i = 0; i<SIZE_TAB; i++)
        printf("%c", program[i]);
    Sleep(1000);
    printf("\n\n");
}

DeleteCriticalSection(&CriticalSection);

CloseHandle(thread_a);
CloseHandle(thread_b);
return 0;
}


 DWORD WINAPI aa(void *v)
 {

    EnterCriticalSection(&CriticalSection);
    for (int i = 0; i < SIZE_TAB; i++)
    {
        program[i] = 'A';
        for (int j = 0; j<8000; j++);
    }
    LeaveCriticalSection(&CriticalSection);

   }

   DWORD WINAPI bb(void *v)
   {

    EnterCriticalSection(&CriticalSection);
    for (int i = 0; i<SIZE_TAB; i++)
    {
        program[i] = 'B';
        for (int j = 0; j<8000; j++);
    }
    LeaveCriticalSection(&CriticalSection);
   } 
static void send_binary(esp_mqtt_client_handle_t client)
{
    spi_flash_mmap_handle_t out_handle;
    const void *binary_address;
    const esp_partition_t *partition = esp_ota_get_running_partition();
    esp_partition_mmap(partition, 0, partition->size, SPI_FLASH_MMAP_DATA, &binary_address, &out_handle);
    // sending only the configured portion of the partition (if it's less than the partition size)
    int binary_size = MIN(CONFIG_BROKER_BIN_SIZE_TO_SEND,partition->size);
    int msg_id = esp_mqtt_client_publish(client, "/topic/binary", binary_address, binary_size, 0, 0);
    ESP_LOGI(TAG, "binary sent with msg_id=%d", msg_id);
}
#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("Hello world!\n");
    return 0;
}
#include <stdio.h>
#include <stdlib.h>

int main()
{
int favNum = 90;
printf("My fav %s is %d", "number", 500);

    return 0;
}
#include <stdio.h>

#include <stdlib.h>


int main()

{

 int luckyNumber[] = {2, 2, 3, 33, 1};

 luckyNumber[1] = 200;

 printf("%d", luckyNumber[1]);

 return 0;

}
#include <stdio.h>

#include <stdlib.h>


int main()

{

 int luckyNumber[] = {2, 2, 3, 33, 1};

 printf("%d", luckyNumber[3]);

 return 0;

}
#include <stdio.h>

#include <stdlib.h>


int main()

{

 printf("Top");

 sayHi();

 printf("bottom");

 return 0;

}


VoidsayHi90(){

 printf("Hello world");

}
#include <stdio.h>

#include <stdlib.h>



int main()

{

 int num1;

 int num2;

 printf("Enter first number ");

 scanf("%d", &num1);

 printf("Enter second number ");

 scanf("%d", &num2);


 printf("Answer: %d, num1 + num2 ");


return 0;

}
#include <stdio.h>

#include <stdlib.h>


int main()

{

 char color[20];

 char pluralNoun [20];

 char personF[20];

 char personL[20];


 printf("Enter a color: ");

 scanf("%s", color);

 printf("Enter a pliuralNoun ");

 scanf("%s", pluralNoun);

 printf("Enter a person: ");

 scanf("%s%s", personF, personL);



 printf("The great American race is %s\n", color);

 printf("%s are Merican\n", pluralNoun);

 printf("I ate %s %s\n", personF, personL);


return 0;

}
#include <stdio.h>

main()
{
  printf("Hello Worlds\n");
  
  return 0;
}
char buffer[BUFFER_SIZE];
while (fscanf(stream, "%s", buffer) == 1) // expect 1 successful conversion
{
  // process buffer
}
if (feof(stream)) 
{
  // hit end of file
}
else
{
  // some other error interrupted the read
}
#include <stdio.h>
#include <stdlib.h>

int main(){

    FILE *myFile;
    myFile = fopen("somenumbers.txt", "r");

    //read file into array
    int numberArray[16];
    int i;

    if (myFile == NULL){
        printf("Error Reading File\n");
        exit (0);
    }

    for (i = 0; i < 16; i++){
        fscanf(myFile, "%d,", &numberArray[i] );
    }

    for (i = 0; i < 16; i++){
        printf("Number is: %d\n\n", numberArray[i]);
    }

    fclose(myFile);

    return 0;
}
printf("Enter numbers from 1-1000 (To indicate you are done, enter 0)\n");
	
	// Getting input from user
	float input;
	for (int i = 0; i < numsLen; ++i) {
		printf("Enter a number: ");
		scanf("%f", &input);
		if (input == 0) break;
		nums[i] = input;
		++newLen;
	}
/*
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp8266-nodemcu-webserial-library/
  
  This sketch is based on the WebSerial library example: ESP8266_Demo
  https://github.com/ayushsharma82/WebSerial
*/

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <WebSerial.h>

#define LED 2

AsyncWebServer server(80);

const char* ssid = "REPLACE_WITH_YOUR_SSID";          // Your WiFi SSID
const char* password = "REPLACE_WITH_YOUR_PASSWORD";  // Your WiFi Password

void recvMsg(uint8_t *data, size_t len){
  WebSerial.println("Received Data...");
  String d = "";
  for(int i=0; i < len; i++){
    d += char(data[i]);
  }
  WebSerial.println(d);
  if (d == "ON"){
    digitalWrite(LED, LOW);
  }
  if (d=="OFF"){
    digitalWrite(LED, HIGH);
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.printf("WiFi Failed!\n");
    return;
  }
  Serial.println("IP Address: ");
  Serial.println(WiFi.localIP());
  // WebSerial is accessible at "<IP Address>/webserial" in browser
  WebSerial.begin(&server);
  WebSerial.msgCallback(recvMsg);
  server.begin();
}

void loop() {
  WebSerial.println("Hello!");
  delay(2000);
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main () {
   int i, n;
   time_t t;
   
   n = 5;
   
   /* Intializes random number generator */
   srand((unsigned) time(&t));

   /* Print 5 random numbers from 0 to 49 */
   for( i = 0 ; i < n ; i++ ) {
      printf("%d\n", rand() % 50);
   }
   
   return(0);
}
float rstoc(x) {
  float decimal = abs(x - trunc(x));

  float random_selector = (float)rand() / RAND_MAX;

  float adjustor;
  if (random_selector < decimal) adjustor = 1;
  else adjustor = 0;

  // consider sign
  if(x < 0) adjustor = -1 * adjustor;

  return trunc(x) + adjustor;
}
int solution(int n) {
    int right = n & -n;    // 가장 오른쪽 1인 비트의 값
    int x     = n + right; // 원래 수 + 가장 오른쪽 비트
    
    return x | (((x ^ n) >> 2) / right); // 줄어든 1의 개수만큼 오른쪽부터 채운다
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

struct node {
   int data;
   int key;
   struct node *next;
};

struct node *head = NULL;
struct node *current = NULL;

//display the list
void printList() {
   struct node *ptr = head;
   printf("\n[ ");
	
   //start from the beginning
   while(ptr != NULL) {
      printf("(%d,%d) ",ptr->key,ptr->data);
      ptr = ptr->next;
   }
	
   printf(" ]");
}

//insert link at the first location
void insertFirst(int key, int data) {
   //create a link
   struct node *link = (struct node*) malloc(sizeof(struct node));
	
   link->key = key;
   link->data = data;
	
   //point it to old first node
   link->next = head;
	
   //point first to new first node
   head = link;
}

//delete first item
struct node* deleteFirst() {

   //save reference to first link
   struct node *tempLink = head;
	
   //mark next to first link as first 
   head = head->next;
	
   //return the deleted link
   return tempLink;
}

//is list empty
bool isEmpty() {
   return head == NULL;
}

int length() {
   int length = 0;
   struct node *current;
	
   for(current = head; current != NULL; current = current->next) {
      length++;
   }
	
   return length;
}

//find a link with given key
struct node* find(int key) {

   //start from the first link
   struct node* current = head;

   //if list is empty
   if(head == NULL) {
      return NULL;
   }

   //navigate through list
   while(current->key != key) {
	
      //if it is last node
      if(current->next == NULL) {
         return NULL;
      } else {
         //go to next link
         current = current->next;
      }
   }      
	
   //if data found, return the current Link
   return current;
}

//delete a link with given key
struct node* delete(int key) {

   //start from the first link
   struct node* current = head;
   struct node* previous = NULL;
	
   //if list is empty
   if(head == NULL) {
      return NULL;
   }

   //navigate through list
   while(current->key != key) {

      //if it is last node
      if(current->next == NULL) {
         return NULL;
      } else {
         //store reference to current link
         previous = current;
         //move to next link
         current = current->next;
      }
   }

   //found a match, update the link
   if(current == head) {
      //change first to point to next link
      head = head->next;
   } else {
      //bypass the current link
      previous->next = current->next;
   }    
	
   return current;
}

void sort() {

   int i, j, k, tempKey, tempData;
   struct node *current;
   struct node *next;
	
   int size = length();
   k = size ;
	
   for ( i = 0 ; i < size - 1 ; i++, k-- ) {
      current = head;
      next = head->next;
		
      for ( j = 1 ; j < k ; j++ ) {   

         if ( current->data > next->data ) {
            tempData = current->data;
            current->data = next->data;
            next->data = tempData;

            tempKey = current->key;
            current->key = next->key;
            next->key = tempKey;
         }
			
         current = current->next;
         next = next->next;
      }
   }   
}

void reverse(struct node** head_ref) {
   struct node* prev   = NULL;
   struct node* current = *head_ref;
   struct node* next;
	
   while (current != NULL) {
      next  = current->next;
      current->next = prev;   
      prev = current;
      current = next;
   }
	
   *head_ref = prev;
}

void main() {
   insertFirst(1,10);
   insertFirst(2,20);
   insertFirst(3,30);
   insertFirst(4,1);
   insertFirst(5,40);
   insertFirst(6,56); 

   printf("Original List: "); 
	
   //print list
   printList();

   while(!isEmpty()) {            
      struct node *temp = deleteFirst();
      printf("\nDeleted value:");
      printf("(%d,%d) ",temp->key,temp->data);
   }  
	
   printf("\nList after deleting all items: ");
   printList();
   insertFirst(1,10);
   insertFirst(2,20);
   insertFirst(3,30);
   insertFirst(4,1);
   insertFirst(5,40);
   insertFirst(6,56);
   
   printf("\nRestored List: ");
   printList();
   printf("\n");  

   struct node *foundLink = find(4);
	
   if(foundLink != NULL) {
      printf("Element found: ");
      printf("(%d,%d) ",foundLink->key,foundLink->data);
      printf("\n");  
   } else {
      printf("Element not found.");
   }

   delete(4);
   printf("List after deleting an item: ");
   printList();
   printf("\n");
   foundLink = find(4);
	
   if(foundLink != NULL) {
      printf("Element found: ");
      printf("(%d,%d) ",foundLink->key,foundLink->data);
      printf("\n");
   } else {
      printf("Element not found.");
   }
	
   printf("\n");
   sort();
	
   printf("List after sorting the data: ");
   printList();
	
   reverse(&head);
   printf("\nList after reversing the data: ");
   printList();
}
#include <stdio.h>

int main() {
    int marks[4];
    int *ptr;
    ptr = &marks[0];
    int i;
    
    for(i=0;i<4;i++){
        printf("enter the value of the marks: %d\n" , i+1);
        scanf("%d" , ptr);
        ptr++;
        
    }
     for(i=0;i<4;i++){
         printf(" the value of the marks %d is :%d\n" , i+1 , marks[i]);
     }
    
	//code
	return 0;
}
#include <stdio.h>
int factorial(int a);


int main() {
    int a =3;
    
    printf("the value of factorial is %d" , factorial(a));
	//code
	return 0;
}

int factorial(int a){
 
 
 if(a==0 || a==1){
     return 1;
 }else{
     return a * factorial(a-1);
 }
}
#include <stdio.h>
void printpattern(int n);

int main() {
    int n = 4;
    
    printpattern(n);
    
    
	//code
	return 0;
}
void printpattern(int n){
    int i;
    if(n == 1){
        printf("*\n");
        return;
    }
    printpattern(n-1);
    for(i=0;i<2*n-1;i++){
        printf("*");
        
    }
    printf("\n");
}
#include <stdio.h>
int fib(int a);

int main() {
    int a;
    printf("enter the number\n");
    scanf("%d" , &a);
    
    
    printf("the sequence will be %d" , fib(a));
	//code
	return 0;
}

int fib(int a){
    int f;
    if (a == 1 || a == 2){
        return 1;
        
    }else{
        f = fib(a-2) + fib(a-1);
        return f;
    }
}
#include <stdio.h>
#include<stdlib.h>
#include<time.h>


int main() {
    
    int number , nguess=1 , guess;
    srand(time(0));
    number = rand()%100+1;
    
   // printf("the number is %d" , number);
    
    do{
        printf("guess the number between 1-100 %d\n" , guess);
        scanf("%d" , &guess);
        
        if(guess<number){
            
            printf("enter higher number\n");
            
        }
        else if(guess>number){
            
            printf("enter lower number\n");
        }
    else {
        
        printf("you guessed the number in %d attempts\n" , nguess);
    }
    
    nguess++;
    } while(guess!=number);
    
	//code
	return 0;
}
#include <stdio.h>

int main() {
    
    int i=1;
    int n;
    
    printf("enter the number\n");
    scanf("%d" , &n);
    
    do{
        printf("%d\n" , i*n);
        
        i++;
    }while(i <= 10);
	//code
	return 0;
}
#include <stdio.h>

int main() {
    
    int i = 0;
    
    for (i=0; i<50 ; i++) {
        
    if(i %2==0){
        
        printf("the n even numbers are %d\n" , i);
    }
        /* code */
    }
	//code
	return 0;
}
#include <stdio.h>

int main() {
    
     int year;
     printf("enter the year\n");
     scanf("%d" , &year);
     
     
     (year %4 ==0) ? (printf("the year is leap year")) : (printf("the year is not leap year"));
	//code
	return 0;
}
#include <stdio.h>

int main() {
    
    int i = 0;
    
    while(i<50){
        
        if(i %2==0){
            
            printf("the number is even %d\n" , i);
        }
        
        i++;
    }
	//code
	return 0;
}
#include <stdio.h>

int main() {
    
    float a , b , c , d;
    
    printf("enter the numbers\n");
    scanf(" %f %f %f %f" , &a , &b , &c , &d);
    
   
    if(a > b && a > c && a > d){
        
        printf("a is the greatesr number %f" , a);
    }
    
     if(b > a && b > c && b > d){
        
        printf("b is the greatesr number %f" , b);
    }
    
     if(c > b && c > a && c > d){
        
        printf("c is the greatesr number %f" , c);
    } 
    
    
    if(d > b && d > c && d > a){
        
        printf("d is the greatesr number %f" , d);
    }
	//code
	return 0;
}
#include <stdio.h>

int main() {
    int i = 0;
    int n;
    
    printf("enter the value of n\n");
    scanf("%d" , &n);
    
    
    do{
        
     printf("the first n numbers are %d\n" , i+1);
     
     i++;
    }
    while(i < n);
	//code
	return 0;
}

include <msp430.h>

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;                          // Stop watchdog timer

    // Configure two FRAM waitstate as required by the device datasheet for MCLK
    // operation at 24MHz(beyond 8MHz) _before_ configuring the clock system.
   // FRCTL0 = FRCTLPW | NWAITS_2;

    __bis_SR_register(SCG0);                           // disable FLL
    CSCTL3 |= SELREF__REFOCLK;                         // Set REFO as FLL reference source
    CSCTL0 = 0;                                        // clear DCO and MOD registers
    CSCTL1 |= DCORSEL_7;                               // Set DCO = 24MHz
    CSCTL2 = FLLD_0 + 732;                             // DCOCLKDIV = 24MHz
    __delay_cycles(3);
    __bic_SR_register(SCG0);                           // enable FLL
    while(CSCTL7 & (FLLUNLOCK0 | FLLUNLOCK1));         // FLL locked

    CSCTL4 = SELMS__DCOCLKDIV | SELA__REFOCLK;        // set default REFO(~32768Hz) as ACLK source, ACLK = 32768Hz
                                                       // default DCOCLKDIV as MCLK and SMCLK source
    CSCTL5 = DIVS_2;                                   // se divide totul la 2

    P1DIR |= BIT0 | BIT1 | BIT2;                       // set ACLK SMCLK and LED pin as output
    P1SEL1 |= BIT0 | BIT1;                             // set ACLK and  SMCLK pin as second function


    PM5CTL0 &= ~LOCKLPM5;                              // Disable the GPIO power-on default high-impedance mode
                                                       // to activate previously configured port settings

    while(1)
    {
        P1OUT ^= BIT2;                                 // Toggle P1.2 using exclusive-OR
        __delay_cycles(12000000);                       // Delay for 12000000*(1/MCLK)=0.5s
    }
}
#include <String.h>
#include <stdio.h>
int main() {
  // initializing the pointer string array
  char *names[] = {"tree", "bowl", "hat", "mice", "toon"};
  char *temp; // temporary variable for swaping the values
  int i, j, a;
  printf("The names are:\n");
  for (i = 0; i < 5; i++)
    printf("%s\n", names[i]);
  // arranging names in alphabetically using selection sort
  for (i = 0; i < 5; i++) {
    for (j = i + 1; j < 5; j++) {
      // compares the two string and returns an integer value
      // if the value of a is greater than 0 then swapping begins
      a = strcmp(names[i], names[j]);
      
      if (a > 0) {
        temp = names[i];
        names[i] = names[j];
        names[j] = temp;
      }
    }
  }
  printf("The arranged names are:\n");
  for (i = 0; i < 5; i++)
    printf("%s\n", names[i]);
  return 0;
}
#include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include <Adafruit_NeoPixel.h>
#include <Servo.h>

// sensors
#define LDR0pin A0 
#define LDR1pin A1 
#define LDR2pin A2 
#define LDR3pin A3 
#define LDR4pin A4 

// servos/motors
#define boo1pin 2
#define boo2pin 3
#define ceilingpin 4

// gun
#define buttpin 5
#define indipin 6
#define laserpin 7

// LEDs
#define melodypin 8
#define mompin 9
#define DATA_PIN 10 
#define NUM_LEDS 20 

// DFPlayer
SoftwareSerial mySoftwareSerial(12, 13); // TX, RX
DFRobotDFPlayerMini myDFPlayer;

// led strips
Adafruit_NeoPixel lightning_strip = Adafruit_NeoPixel(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel melody = Adafruit_NeoPixel(2, melodypin, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel mom = Adafruit_NeoPixel(2, mompin, NEO_GRB + NEO_KHZ800);

// servos
// twelve servo objects can be created on most boards
Servo servo0;  // create servo1 object to control a servo1
Servo servo1;
Servo servo2;

// ADJUST FOR LIGHT THRESHOLDS
short laserThresh = 240;
short altThresh = 255;

// lightning
unsigned long flickerTime = 0, fadeInTime = 0;
byte i = 6, lowBright = 10, highBright = 255;
boolean lightState = true;

// boo servos
unsigned long booTime = 0;
boolean booState = false;

// mom, melody, ceiling trigger times
unsigned long momTime = 0, melodyTime = 0, ceilingTime = 0;

 // used for debouncing button
unsigned long lastDebounceTime = 0, highTime = 1, lasthighTime = 0;
byte buttonState, lastButtonState = HIGH;
boolean adjust = true;

// sensors
byte LDR0 = 0, LDR1 = 0, LDR2 = 0, LDR3 = 0, LDR4 = 0, LDR5 = 0;

void setup() {
  lightning_strip.begin();
  lightning_strip.setBrightness(lowBright);
  setLightning(0,255,0);

  melody.begin();
  melody.setBrightness(100);
  setMelody(0,0,0);

  mom.begin();
  mom.setBrightness(100);
  setMom(0,0,0);
  
  mySoftwareSerial.begin(9600);
  Serial.begin(9600);
  
  Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
  
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
    while(true);
  }
  Serial.println(F("DFPlayer Mini online."));

  // CHANGE TO 20
  myDFPlayer.volume(30);  //Set volume value (0~30).

  // gun
  pinMode(laserpin, OUTPUT);
  pinMode(indipin, OUTPUT);
  pinMode(buttpin, INPUT_PULLUP);

  // sensors
  pinMode(LDR0pin, INPUT);
  pinMode(LDR1pin, INPUT);
  pinMode(LDR2pin, INPUT);
  pinMode(LDR3pin, INPUT);
  pinMode(LDR4pin, INPUT);

  // servos
  
  servo0.attach(boo1pin);
  servo1.attach(boo2pin);  // attaches the servo1 on pin 9 to the servo1 object
  servo2.attach(ceilingpin);

  // initialize servo positions:
  servo0.write(40); // boo1 swivels out RIGHT
  servo1.write(40); // boo2 swivels out LEFT
  servo2.write(90); // ceiling starts horizontal

  // opening song
  myDFPlayer.playMp3Folder(0);
}

void loop() {
  LDR0 = analogRead(LDR0pin);
  LDR1 = analogRead(LDR1pin);
  LDR2 = analogRead(LDR2pin);
  LDR3 = analogRead(LDR3pin);
  LDR4 = analogRead(LDR4pin);

  //trigger(trig_time, reload_time);
  //default (250, 1000)
  trigger(250, 1000);

  // boo(toggle_interval
  boo(2000);

  //lightning(flickerRate, blackout_time);
  lightning(150, 3000);
  lightning_strip.show();
  Serial.println(LDR4);

  //targetHit(playTime)
  melodyHit(4000);
  momHit(5500);
  ceiling(3000);
}

void ceiling (short playTime) {
  if (LDR4 > laserThresh) {
     ceilingTime = millis();
     myDFPlayer.playMp3Folder(4);
  }
  
  if (millis() - ceilingTime < playTime) servo2.write(0);
  else servo2.write(90);
}

void melodyHit (short playTime) {
  // if target hit, reset routine
  if (LDR2 > laserThresh) {
    melodyTime = millis();
    myDFPlayer.playMp3Folder(2);
  }

  if ((millis() - melodyTime < playTime)&&(melodyTime > 0)) setMelody(128, 0, 128);
  else setMelody(0, 0, 0);
}

void momHit (short playTime) {
  // if target hit, reset routine
  if (LDR3 > laserThresh) {
    momTime = millis();
    myDFPlayer.playMp3Folder(3);
  }

  if ((millis() - momTime < playTime)&&(momTime > 0)) setMom(128, 0, 128);
  else setMom(0, 0, 0);
}

void boo (short toggle_interval) {
  if (millis() - booTime > toggle_interval) {
    booState = !booState;
    booTime = millis();
  }
  
  if (booState)  {
    servo0.write(40);
    servo1.write(40);
  }
  
  else  {
    servo0.write(160);
    servo1.write(160);
  }
}

void lightning (short flickerRate, short blackout) {
  if (i > 6) i = 6;
  
  // if target hit, reset routine
  if ((LDR0 > laserThresh)||(LDR1 > laserThresh)) {
    i = 0;
    lightning_strip.setBrightness(highBright);
    lightState = true;
    myDFPlayer.playMp3Folder(1);
  }

  // flicker on/off 5 times at flickerRate
  if ((millis() - flickerTime > flickerRate)&& (i < 5)) 
  {
    lightState = !lightState;
    if (lightState) setLightning(255,255,255);
    else setLightning(0,0,0);
    i++;
    flickerTime = millis();
  }

  // lights stay off for blackout time
  else if ((millis() - flickerTime > blackout)&& (i == 5)) 
  {
    lightning_strip.setBrightness(lowBright);
    for (short j = 0 ; j < 255 ; ) {
      if (fadeInTime - millis() > 25) {
        setLightning(0, j, 0);
        j++;
      }
      fadeInTime = millis();
    }
    
    lightState = !lightState;
    flickerTime = millis();
    i++;
    
  }
}

void trigger(short trig_time, short reload) {
  adjust = digitalRead(buttpin);

  if (adjust != lastButtonState) {
    lastDebounceTime = millis();
  }
  
  if ((millis() - lastDebounceTime) > 50) {
    
    if (adjust != buttonState) {
      buttonState = adjust;
  
      if ((buttonState == LOW) && (millis() > 500)) {
        highTime = millis();
      }
    }
  }
  lastButtonState = adjust;

  if ((millis() - highTime <= trig_time)&&(millis() > 500)) {
    if (highTime-lasthighTime >= reload) {
      digitalWrite(laserpin, HIGH);
      lasthighTime = highTime;
    }
    digitalWrite(indipin, LOW);
  }
  else {
    digitalWrite(laserpin, LOW);
    digitalWrite(indipin, HIGH);
  }
}

// Set all LEDs to a given color and apply it (visible)
void setLightning (byte red, byte green, byte blue) {
  for(byte i = 0; i < NUM_LEDS; i++ ) {
    lightning_strip.setPixelColor(i, lightning_strip.Color(red, green, blue));
  }
  lightning_strip.show();
}

// Set all LEDs to a given color and apply it (visible)
void setMom (byte red, byte green, byte blue) {
  for(byte i = 0; i < 2; i++ ) {
    mom.setPixelColor(i, mom.Color(red, green, blue));
  }
  mom.show();
}

// Set all LEDs to a given color and apply it (visible)
void setMelody (byte red, byte green, byte blue) {
  for(byte i = 0; i < 2; i++ ) {
    melody.setPixelColor(i, melody.Color(red, green, blue));
  }
  melody.show();
}
// rdtsc.cpp
// processor: x86, x64
#include <stdio.h>
#include <intrin.h>

#pragma intrinsic(__rdtsc)

int main()
{
    unsigned __int64 i;
    i = __rdtsc();
    printf_s("%I64d ticks\n", i);
}
static void Main(string[] args)
{
    Action<int> firstAction = DoWorkWithOneParameter;
    Action<int, int> secondAction = DoWorkWithTwoParameters;
    Action<int, int, int> thirdAction = DoWorkWithThreeParameters;

    firstAction(1); // Print 1
    secondAction(1, 2); // Print 1-2
    thirdAction(1, 2, 3); //Print 1-2-3
}

public static void DoWorkWithOneParameter(int arg)
{
    Console.WriteLine(arg);
}

public static void DoWorkWithTwoParameters(int arg1, int arg2)
{
    Console.WriteLine(arg1 + "-" + arg2);
}

public static void DoWorkWithThreeParameters(int arg1, int arg2, int arg3)
{
    Console.WriteLine(arg1 + "-" + arg2 + "-" + arg3);
}
static void Main(string[] args)
{
    Action act = () =>
    {
        Console.WriteLine("No Parameter");
    };

    Action<int> actWithOneParameter = (arg1) =>
        {
            Console.WriteLine("Par: " + arg1);
        };

    Action<int, int> actWithTwoParameter = (arg1, arg2) =>
        {
            Console.WriteLine("Par1: " + arg1 + ", Par2: " + arg2);
        };

    act();
    actWithOneParameter(1);
    actWithTwoParameter(1, 2);
}
using System;

namespace pass_function_as_parameter
{
    class Program
    {
        static int functionToPass(int x)
        {
            return x + 10;
        }
        static void function(Func<int, int> functionToPass)
        {
            int i = functionToPass(22);
            Console.WriteLine("i = {0}", i);
        }
        static void Main(string[] args)
        {
            function(functionToPass);
        }
    }
}
using System;

namespace pass_function_as_parameter
{
    class Program
    {
        static void functionToPass2(int x)
        {
            int increment = x + 10;
            Console.WriteLine("increment = {0}",increment);
        }
        static void function2(Action<int> functionToPass2)
        {
            functionToPass2(22);
        }
        static void Main(string[] args)
        {
            function2(functionToPass2);
        }
    }
}
#include<stdio.h>
#include<string.h>

int check_fibonacci(int fibonacci[], int total)
{
    int i, j, result, sum;

    for(i = 0, j = 2; i < total - 2; i++,j++)
    {
        sum = fibonacci[i] + fibonacci[i+1];

        if(fibonacci[j] == sum)
        {
           result = 1;
        }
        else
        {
            result = 0;
        }
    }
    return result;
}


void main()
{

  int total;
  printf("co bao nhieu so : ");
  scanf("%d", &total);
  int fibonacci[total];

  for(int i = 0; i < total; i++)
  {
      printf("fibonacci %d = ", i + 1);
      scanf("%d", &fibonacci[i]);
  }

   if(check_fibonacci(fibonacci, total) == 1)
   {
       printf("\nla day so fibonacci");
   }
   else
   {
      printf("\nkhong phai day so fibonacci");
   }

}
vector* sum( vector* v, int n ) {
    vector* r = ( vector* )( malloc( sizeof( vector ) ) );
    for( i = 0; i < n; i++ ) {
        r = add( r, v + i );
    }
    
    return r;
}
typedef struct __vector {
    int x;
    int y;
} vector;

vector* add( vector* a, vector* b ) {
    vector* r = ( vector* )( malloc( sizeof( vector ) ) );
    r->x = a->x + b->x;
    r->y = a->y + b->y;
    
    return r;
}
a = a ^ b;
b = a ^ b;
a = a ^ b;
#include<stdio.h>
#include<windows.h>



void ReadWay(int number)
{
SetConsoleOutputCP(65001);
     int ways;
      ways = number/10;

      switch(ways)
      {

        case 1:
            printf("mười ");
            break;
        case 2:
            printf("hai ");
            break;
        case 3:
            printf("ba ");
            break;
        case 4:
            printf("bốn ");
            break;
        case 5:
            printf("năm ");
            break;
        case 6:
            printf("sáu ");
            break;
        case 7:
            printf("bảy ");
            break;
        case 8:
            printf("tám ");
            break;
        case 9:
            printf("chín ");
            break;
      }

      ways = number%10;
      switch(ways)
      {
        case 0:
            ways = number/10;
            if(ways == 1)
            {
                printf("");
            }
            else
            {
               printf("mươi ");
            }

            break;
        case 1:
            ways = number/10;
            if(ways == 1)
            {
                printf("một");
            }
            else
            {
               printf("mươi mốt");
            }

            break;
        case 2:
            ways = number/10;
            if(ways == 1)
            {
                printf("hai");
            }
            else
            {
                printf("mươi hai");
            }

            break;
        case 3:
            ways = number/10;
            if(ways == 1)
            {
                printf("ba");
            }
            else
            {
                printf("mươi ba");
            }

            break;
        case 4:
            ways = number/10;
            if(ways == 1)
            {
                printf("bốn");
            }
            else
            {
                printf("mươi bốn");
            }

            break;
        case 5:
            ways = number/10;
            if(ways == 1)
            {
                printf("lăm");
            }
            else
            {
               printf("mươi lăm");
            }

            break;
        case 6:
            ways = number/10;
            if(ways == 1)
            {
                printf("sáu");
            }
            else
            {
                printf("mươi sáu");
            }

            break;
        case 7:
            ways = number/10;
            if(ways == 1)
            {
                printf("bảy");
            }
            else
            {
                printf("mươi bảy");
            }

            break;
        case 8:
            ways = number/10;
            if(ways == 1)
            {
                printf("tám");
            }
            else
            {
               printf("mươi tám");
            }

            break;
        case 9:
            ways = number/10;
            if(ways == 1)
            {
                printf("chín");
            }
            else
            {
               printf("mươi chín");
            }

            break;
      }
}


void main()
{
  SetConsoleOutputCP(65001);
  float number, save;
  save = number;
 do
{
   //check input data
   do
    {
    printf("nhập số nguyên: ");
    scanf("%f", &number);

    save = number;

        if(number != (int)number)
        {
        printf("lỗi! phải nhập số nguyên\n");
        }

    }while(number != (int)number);

   //end program
     if(number == 0)
    {
        exit(0);
    }

    system("cls");
    printf("%d đọc là: ", (int)save);

    ReadWay(number);

    printf("\n\nnếu muốn dừng chương trình! >>nhập 0<<\n\n");


}while(number != 0);


}
#include<stdio.h>

//sum
void CountTime(int day, int month, int year)
{
     int Dayth;
     printf("%d/%d/%d is: ", day, month, year);

     for(int i = 1; i < month;i++)
     {
         if( i == 1 || i == 3 || i == 5 || i == 7 || i ==  9 || i == 11)
         {
             if(month == 1)
             {
                Dayth = 0;
             }
             else
             {
                Dayth =  Dayth + 31;
             }

         }
         else if(i == 4 || i == 6 ||i == 8 || i == 10 || i == 12)
         {
             Dayth =  Dayth + 30;
         }
         else
         {
             Dayth =  Dayth + 28;
         }
     }

     printf("[%d]th day in year", Dayth + day);

}


void main()
{
  int day, month, year;


  //check input data
do
{
  do
  {
      printf("enter day: ");
      scanf("%d", &day);
      if(day > 31 || day <= 0)
      {
          printf(">>ERROR! day <= 30\n");
      }
  }while(day > 31 || day <= 0);

  do
  {
     printf("enter month: ");
     scanf("%d", &month);
     if(month > 12 || month < 1)
     {
         printf(">>ERROR! month >= 12\n");
     }
  }while(month > 12 || month < 1);

  if(month == 2 && day > 28 || month == 4 && day > 30 ||
       month == 6 && day > 30 || month == 8 && day > 30 ||
       month == 10 && day > 30 || month == 12 && day > 30)
  {
      printf(">>ERROR! day of month\n");
      printf("month [2] : 28 day\n");
      printf("month [4] [6] [8] [10] [12] : 30 day\n");
      printf("month [1] [3] [5] [7] [9] [11] : 31 day\n\n");
  }

}while(month == 2 && day > 28 || month == 4 && day > 30 ||
       month == 6 && day > 30 || month == 8 && day > 30 ||
       month == 10 && day > 30 || month == 12 && day > 30);

  do
  {
     printf("enter year: ");
     scanf("%d", &year);
     if(year < 2000)
     {
         printf(">>ERROR! year >= 2000");
     }
  }while(year < 2000);


  CountTime(day, month, year);
}
#include<stdio.h>



void NextTime(int day, int month, int year)
{
    // count day and month
    day = day + 1;
    printf("Next time: ");
    if(month == 1 || month == 3 || month == 5 || month == 7 || month == 9 || month == 11)
    {

        if(day > 31 && month < 12)
        {
           printf("1/%d/", month + 1);
        }
        else if(day <= 31 && month < 12)
        {
            printf("%d/%d/",day ,month);
        }
    }

    else if(month == 4 || month == 6 || month == 8 || month == 10 || month == 12)
    {
        if(day > 30 && month == 12)
        {
            printf("1/1/");
        }
        else if(day > 30 && month < 12)
        {
            printf("1/%d/", month + 1);
        }
        else if(day <= 30 && month <= 12)
        {
            printf("%d/%d/", day, month);
        }
    }
    else if(month == 2)
    {
        if(day > 28)
        {
        printf("1/3/");
        }
        else if(day <= 28)
        {
            printf("%d/2/", day);
        }
    }


//count year
  if( day > 30 && month == 12)
  {

     printf("%d", year + 1);
  }
  else if(day <= 31 && month < 12 || day > 31 && month < 12 )
  {
    printf("%d", year);
  }
}



void main()
{
  int day, month, year;


  //check input data
do
{
  do
  {
      printf("enter day: ");
      scanf("%d", &day);
      if(day > 31 || day <= 0)
      {
          printf(">>ERROR! day <= 30\n");
      }
  }while(day > 31 || day <= 0);

  do
  {
     printf("enter month: ");
     scanf("%d", &month);
     if(month > 12 || month < 1)
     {
         printf(">>ERROR! month >= 12\n");
     }
  }while(month > 12 || month < 1);

  if(month == 2 && day > 28 || month == 4 && day > 30 ||
       month == 6 && day > 30 || month == 8 && day > 30 ||
       month == 10 && day > 30 || month == 12 && day > 30)
  {
      printf(">>ERROR! day of month\n");
      printf("month [2] : 28 day\n");
      printf("month [4] [6] [8] [10] [12] : 30 day\n");
      printf("month [1] [3] [5] [7] [9] [11] : 31 day\n\n");
  }

}while(month == 2 && day > 28 || month == 4 && day > 30 ||
       month == 6 && day > 30 || month == 8 && day > 30 ||
       month == 10 && day > 30 || month == 12 && day > 30);

  do
  {
     printf("enter year: ");
     scanf("%d", &year);
     if(year < 2000)
     {
         printf(">>ERROR! year >= 2000");
     }
  }while(year < 2000);


  NextTime(day, month, year);
}
#include<stdio.h>



void increasing(float num1, float num2, float num3)
{
    float save = 0;
    printf("increasing: ");
    if(num1  > num2)
    {
        save = num2;
        num2 = num1;
        num1 = save;
    }
    if(num2 > num3)
    {
        save = num3;
        num3 = num2;
        num2 = save;
    }
    if(num1 > num2)
    {
        save = num2;
        num2 = num1;
        num1 = save;
    }
    printf("%.1f %.1f %.1f", num1, num2, num3);

}
void main()
{
  float num1, num2, num3;
    printf("enter number 1: ");
    scanf("%f", &num1);
    printf("enter number 2: ");
    scanf("%f", &num2);
    printf("enter number 3: ");
    scanf("%f", &num3);

  increasing(num1, num2, num3);
}
#include<stdio.h>


//change negative number to positive number
void change(float num1, float num2, float num3)
{
    printf("changed: [%.1f] [%.1f] [%.1f]", num1 * -1, num2 * -1, num3 * -1);
}
void main()
{
  float num1, num2, num3;
  printf("please enter negative numbers\n");
  
  //check input data 
  do 
  {
    printf("enter number 1: ");
    scanf("%f", &num1);
    printf("enter number 2: ");
    scanf("%f", &num2);
    printf("enter number 3: ");
    scanf("%f", &num3);

     if(num1 >= 0 || num2 >= 0 || num3 >= 0)
     {
      printf("please enter negative numbers\n");
     }
  }while(num1 >= 0);

  change(num1, num2, num3);
}
#include<stdio.h>

void main()
{
  int n, sum;
  int count = 0;
    printf("enter n: ");
    scanf("%d", &n);

    for(int i = 1; i < n;i++)
    {
      sum = sum + i;
       if(sum >= n)
       {
           break;
       }
       count = count + 1;
    }

    printf("count = %d", count);
}
#include<stdio.h>

void main()
{
  int n, sum;
    printf("enter n: ");
    scanf("%d", &n);

    for(int i = 1; i < n;i++)
    {
       if(i % 2 == 0)
       {
           continue;
       }
       sum = sum + i;
    }

    printf("sum of odd numbers = %d", sum);
}
#include<stdio.h>

void main()
{
    for(int i = 65; i <= 90;i++)
    {
       printf("%c, ", i);
    }
}
#include<stdio.h>



int FindX(int n)
{
    int sum, count;
    for(int j = 1; sum <= n;j++)
  {
    sum = sum + j;
        if(sum > n)
        {
        break;
        }
    count = count + 1;
  }
  return count;
}
void main()
{
int n;
    printf("enter n: ");
  do
   {
     scanf("%d", &n);
     if(n < 0)
       {
         printf("n must greater than 0")
       }
   }while(n < 0)
    
    printf("X = %d", FindX(n));
    getch();
}
#include<stdio.h>
#include<string.h>
#include<windows.h>

//check duplicate ID
int check_ID(int ID[], int i)
{
 int result;

 for(int j = 0; j < i; j++)
 {
    if(ID[i] == ID[j])
    {
      result = 1;
    }
 }
   return result;
}

//input student information
void InputStudentInfor(int ID[], float grade[], int total)
{

 int i, j, check_input ;
 char temp;

 for(i = 0; i < total; i++)
 {
    do
    {
       printf("\n--> Student %d | ID: ", i+1);
       fflush(stdin);
       check_input = scanf("%d%c", &ID[i], &temp);//check_input will check how many values are scanned

       if(check_input == 2 && temp != '\n' || check_input == 0)
       {
         printf("\n--- ERROR! can't enter character\n");
       }
       else if(ID[i] < 0)
       {
         printf("\n--- ERROR! please, enter positive number\n");
       }
       else if(check_ID(ID, i)== 1)
       {
         printf("\n--- Student ID already exists\n");
       }
       else
       {
         break;
       }

    }while(check_input == 2 && temp != '\n' || check_input == 0 || ID[i] < 0 || check_ID(ID, i)== 1);


    do
    {
       printf("\n--> Grade %d : ", i+1);//check_input will check how many values are scanned
       fflush(stdin);
       check_input = scanf("%f%c", &grade[i], &temp);

       if(check_input == 2 && temp != '\n' || check_input == 0 )
       {
         printf("\n--- ERROR! can't enter character\n");
       }
       else if(grade[i] < 0 || grade[i] > 10)
       {
         printf("\n--- ERROR! please, enter number from 1 to 10\n");
       }
       else
       {
         break;
       }

    }while(check_input == 2 && temp != '\n' || check_input == 0 || grade[i] < 0 || grade[i] > 10);
 }
}

//


// Output information of student entered
void OutputStudentInfor(int ID[],float grade[], int total)
{
 for(int i = 0; i < total; i++)
 {
    printf("|%d Student ID: [%d] | Grade: %.2f |\n",i+1 ,ID[i], grade[i]);
 }
}

// Find maximum grade
float FindMaxGrade(float grade[], int total)
{
 float max = grade[0];
 for(int i = 1; i < total;i++ )
 {
    if( max < grade[i])
    {
      max = grade[i];
    }
 }
    return max;
}

//Fin minimum grade
float FindMinGrade(float grade[], int total)
{
 float min = grade[0];
 for(int i = 1; i < total;i++ )
 {
    if( min > grade[i])
    {
      min = grade[i];
    }
 }
    return min;
}

void main()
{
 int total, choice, check_input;
 char temp;
 system("color 0A");//change the color of all characters to green in the console window

   // enter the number of elements of the array and check input data
 do
 {
   printf("--> Enter total number of  student: ");
   fflush(stdin);
   check_input = scanf("%d%c", &total, &temp);//check_input will check how many values are scanned

   if(check_input == 2 && temp != '\n' || check_input  == 0)
   {
     printf("\n--- ERROR! can't enter character<<\n\n");
   }
   else if(total <= 0)
   {
     printf("\n--- ERROR! please, enter value must be greater than 0\n\n");
   }
   else
   {
     break;
   }

 }while(total <= 0 || check_input == 2 && temp !='\n' || check_input == 0);

 system("cls");

 int ID[total];
 float grade[total];

 printf(">>> Enter student ID and grade\n");

 InputStudentInfor(ID, grade, total);
 system("cls");
 printf(">>> Finished entering data");
   //menu initialization
 do
 {

    printf("\n\n\n\t\tMENU");
    printf("\n****************************************\n");
    printf("* 1. Re-enter data                     *\n");
    printf("* 2. print ID and grade of student     *\n");
    printf("* 3. Find maximum grade                *\n");
    printf("* 4. Find minimum grade                *\n");
    printf("* 5. Exit                              *\n");
    printf("****************************************\n\n");

 //check input data
    do
    {
        printf("--> Enter choice: ");
        fflush(stdin);
        check_input = scanf("%d%c", &choice, &temp);//check_input will check how many values are scanned

        if(check_input == 2 && temp != '\n' || check_input  == 0)
        {
            printf("\n--- ERROR! can't enter character<<\n\n");
        }
        else if(choice > 5 || choice < 1)
        {
            printf("\n--- ERROR! please choose from 1 to 5\n\n");
        }
        else
        {
            break;
        }

    }while(check_input == 2 && temp != '\n' || check_input  == 0 ||  choice > 5 || choice < 1);

    system("cls"); //delete screen

    //function selection
    switch(choice)
    {
        case 1:
            system("cls");
            printf(">>> Re-enter data\n\n");

            InputStudentInfor(ID, grade, total);

            printf(">>> Finished entering data");
            system("cls");
            break;

        case 2:
            system("cls");
            printf(">>> List ID and grade of student\n\n\n");

            OutputStudentInfor(ID, grade, total);
            break;

        case 3:
            system("cls");
            printf(">>> Maximum grade: %.2f \n", FindMaxGrade(grade, total));
            break;

        case 4:
            system("cls");
            printf(">>> Minimum grade: %.2f \n", FindMinGrade(grade, total));
             break;

        default :
            printf("\n>>> Program has ended!\n");
            exit(0);
    }

 }while(choice <= 4);
}
uint64_t rdtsc() {
  uint32_t hi, lo;
  __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
 
  return ( (uint64_t)lo)|( ((uint64_t)hi)<<32 );
 }
#include "sodium.h"

int foo() {
  char myString[32];
  uint32_t myInt;
  if (sodium_init() < 0) return 1;
  randombytes_buf(myString, 32);
  myInt = randombytes_uniform(10);
}
int fd = open("/dev/urandom", O_RDONLY);
if (fd == -1)
	goto nodevurandom
if (fstat(fd, &st) == -1 || !S_ISCHR(st.st_mode)) {
	close(fd);
	goto nodevrandom;
}
if (ioctl(fd, RNDGETENTCNT, &cnt) == -1) {
	close(fd);
	goto nodevrandom;
}
ssize_t ret = read(fd, (char *)buf + i, wanted);
if (ret == -1) {
	if (errno == EAGAIN || errno == EINTR)
		continue;
		close(fd);
		goto nodevrandom;
}
close(fd);
if (gotdata(buf, len) == 0) {
	errno = save_errno;
	return 0;
}
nodevrandom:
	errno = EIO;
	return -1;
int sum_num(int num[], int total)
{
    int sum;
    for(int i = 0; i < total;i++)
    {
        sum = sum +  num[i];
    }
    return sum;
}
int findmax(int num[], int total)
{
    int max;
    max = num[0];
    for(int i = 1; i < total;i++)
    {
        if(max < num[i])
            {
                max = num[i];
            }
    }
    return max;
}
int findmin(int num[], int total)
{
    int min;
    min = num[0];
    for(int i = 1; i < total;i++)
    {
        if(min > num[i])
            {
                min = num[i];
            }
    }
    return min;
}
void main()
{
   int sum, max, min, total;
    printf("enter total: ");
    scanf("%d", &total);
   int num[total];
   for(int i = 0;i < total;i++)
   {
      printf("num %d : ",i+1);
      scanf("%d", &num[i]);
   }

   sum = sum_num(num, total);
   max = findmax(num, total);
   min = findmin(num, total);
   printf("sum = %d\n", sum);
   printf("max = %d\nmin = %d", max, min);
}
#include<stdio.h>



int findexpon(int number, int index)
{
    int expon = 1;
    for(int i = 1; i <= index; i++)
    {
        expon = expon  * number;
    }

    return expon;
}

int finfact(int number)
{
    int sum;
    int fact = 1;
    for(int i = 1; i <= number; i++)
    {
        fact = fact * i ;
    }
    return fact;
}

void main()
{
    int number, fact, index, expon;
    printf("enter value :  ");
    scanf("%d", &number);
    printf("enter exponential: ");
    scanf("%d", &index);

    expon = findexpon(number, index);
    fact = finfact(number);
    
    if(index > 0)
      {
        printf("%d! = %d\n",number, fact);
        printf("%d^%d = %d", number, index, expon);
      }
    else
      {
        printf("enter exponential > 0")
      }


}
#include<stdio.h>
#include<stdbool.h>
#include<conio.h>
#include<math.h>
#include<string.h>

void main()
{
    float s, r, p;
    float area(float r);
    float perimeter(float r);
    printf("enter radius: ");
    scanf("%f", &r);
    s = area(r);
    p = perimeter(r);
    printf("area of circle is %f", s);
    printf("\nPerimeter of circle is %f", p);


}

float area(float r)
{
    float s;
    s = 3.14 * r * r;
    return s;
}

float perimeter(float r)
{
    float p = 2 * 3.14 * r;
    return p;

}
#include<stdio.h>
#include<stdbool.h>
#include<conio.h>
#include<math.h>
#include<string.h>

void main()
{
   int num1, num2, sum;
   char math;
   printf("Enter num 1: ");
   scanf("%d", &num1);
   printf("enter num 2: ");
   scanf("%d", &num2);
   fflush(stdin);
   printf("Enter calculation : ");
   scanf("%C", &math);
   switch(math)
   {
       case '+':
       sum = add(num1, num2);
       printf("%d + %d = %d",num1 ,num2, sum);
       break;
       case '-':
       sum = sub(num1, num2);
       printf("%d - %d = %d",num1 ,num2, sum);
   }




}

int add(int a, int b)
{
     int sum;
     sum = a + b;
    return sum;
}

int sub(int a, int b)
{
    int sum;
    a - b;
    return sum;
}
#include<stdio.h>

void main()
{
int month;
    printf("enter month: ");
    do
    {
       scanf("%d", &month);
       if(month <= 0 || month > 12)
       {
           printf("enter month from 1 to 12\n");
           printf("enter month: ");
       }
    }while(month <= 0 || month > 12);

  if(month == 1 || month == 2 || month == 3 )
  {
     printf("%d month is the 1st quarter", month);
  }
  else if(month == 4 || month == 5 || month == 6)
  {
     printf("%d month is the sendcon quarter", month);
  }
  else if(month == 7 || month == 8 || month == 9)
  {
     printf("%d month is the third quarter", month);
  }
  else
  {
     printf("%d month is the fourth quarter", month);
  }
}
#include<stdio.h>
#include<stdbool.h>
#include<conio.h>
#include<math.h>
#include<string.h>
//đếm số lượng chữ số của số nguyên dương
void main()
{
   int n;
   int i;
   int count = 0;
   printf("enter number: ");
   scanf("%d", &n);

   for(i = 1; i <= n; i++)
   {
    count++;
    n = n/10;
   }
    printf("entered number has %d digits", count+1);
    getch();
}
#include<stdio.h>
#include<stdbool.h>
#include<conio.h>
#include<math.h>
#include<string.h>

void main()
{
   int number;  
   int i, surplus, sum; 

   printf("enter number: "); // nhập số cần đảo ngược
   scanf("%d", &num);
   printf("how many digits in the entered number : ");
   scanf("%d", &sum);

   printf("reversed number of %d is ", num);
   for (i = 1; i <= sum;i++)
   {
       surplus = num%10;   // tìm số dư của số đã cho và in lần lượt sẽ được số đảo ngược
       printf("%d", surplus);
       num = num/10;
   }
  
    getch();
}
#include<stdio.h>
#include<stdbool.h>
#include<conio.h>
#include<math.h>
#include<string.h>

void main()
{
   int temp, i, j;
   temp = 0;
   char chars[20];

    printf("enter chars : ");
    gets(chars);

    if(chars[0] != 'G')
    {
        temp = 1;

    }
    else if (chars[1] != 'C')
    {
        temp = 1;

    }
    else
    {
        for (i = 2; i < strlen(chars);i++)
        {

            if(isdigit(chars[i]) == 0)
                {
                    temp = 1;
                }
                break;
        }
    }

     if ( temp == 0)
     {
         printf("student ID: ");
         puts(chars);
     }
     else
     {
        printf("enter error");
     }

    getch();

}
#include<stdio.h>
#include<stdbool.h>
#include<conio.h>
#include<math.h>
#include<string.h>

void main()
{
   int temp, i, j;
   temp = 0;
   char chars[20];

    printf("enter chars : ");
    gets(chars);

    for(i = 0, j = strlen(chars)-1; i < j; i++, j--)
    {
        if(chars[i] != chars[j])
        {
            temp = 1;
            break;
        }
    }

     if ( temp == 0)
     {
         printf("symmetric chain");
     }
     else
     {
        printf("not symmetric chain");
     }

    getch();

}
#include<stdio.h>
#include<stdbool.h>
#include<conio.h>
#include<math.h>
#include<string.h>

void main()
{
   int result;
   char studentID[20];

   printf("enter ID length  must is 7 characters: ");
A:
   gets(studentID);

   result = strlen(studentID);

   if(result == 7)
   {
       printf("true");
   }
   else
   {
       printf("ID length  must is 7 characters\n");
       printf("re-enter : ");
       goto A;
   }

    getch();

}
#include<stdio.h>
#include<stdbool.h>
#include<conio.h>
#include<math.h>
#include<string.h>

void main()
{
   int choice;
   int choose;
   char str1[20], str2[20];

   printf("enter string 1: ");
   gets(str1);
   printf("enter string 2: ");
   gets(str2);


  do
  {
   printf("\n");
   printf("==========================\n");
   printf("= 1. compare two strings =\n");
   printf("= 2. copy string         =\n");
   printf("= 3. concatenation       =\n");
   printf("= 4. exit                =\n");
   printf("==========================\n");

   printf("choice: ");
   scanf("%d", &choice);
   int result;

   switch(choice)
   {
   case 1:
    result = strcmp(str1, str2);
    if(result == 0)
    {
        printf("two strings is equal");
    }
    if (result > 0)
    {
       printf("string 1 > string 2");
    }
    else
    {
        printf("string 1 < string 2");
    }
    break;
   case 2:
       printf("you wants copy string 1 into 2(input: 1)or 2 into 1(input 2) ?\n");
       printf("choose: ");
       scanf("%d", &choose);
        if(choose == 2)
        {
            strcpy(str1, str2);
            printf("string 2: ");
            puts(str2);
            printf("string 1: ");
            puts(str1);

        }
        else
        {
            strcpy(str2, str1);
            printf("string 2: ");
            puts(str2);
            printf("string 1: ");
            puts(str1);
        }
        break;
   case 3:
        printf("you wants concatenation string 1 into 2(input: 1)or 2 into 1(input 2) ?\n");
        printf("choose: ");
         scanf("%d", &choose);
        if(choose == 2)
        {
            strcat(str1, str2);
            printf("string 1:");
            puts(str1);
        }
        else
        {
            strcat(str2, str1);
            printf ("string 2: ");
            puts(str2);

        }
    break;
   default :
       exit(0);
    break;
   }

  }while( choice <= 3);






    getch();

}
#include<stdio.h>
#include<stdbool.h>
#include<conio.h>
#include<math.h>
#include<string.h>

void main()
{
   char str[5][20];
   int i;

   for (i = 0; i < 5; i++)
   {
     printf("enter string %d: ", i+1);
     gets(str[i]);
   }

   for(i = 0;i<5;i++)
   {
      printf("string entered %: ", i+1);
      puts(str[i]);
   }


    getch();

}
#include<stdio.h>
#include<math.h>
#include<stdbool.h>
void main()
{
    int a[20];
    int j, i, k, h, save;

    i = -1;

    do
    {
        i++;
        printf("enter value a  %d = ", i + 1);
        scanf("%d", &a[i]);
    }while(a[i] >= 0);

    for (k = 0; k < i - 1; k++)
    {
        for (h =k + 1; h < i; h++)
        {
             if(a[k]>a[h])
             {
                save = a[k];
                a[k] = a[h];
                a[h] = save;
             }
        }
    }

   printf("a = ");
   for ( j = 0; j < i; j++ )
      printf("%d\t", a[j]);

  getch();
}
#include<stdio.h>
#include<math.h>
#include<stdbool.h>
void main()
{
    int A[20] ;
    int B[20];
    int i, j, n;

    printf("enter value n : ");
    scanf("%d", &n);


    for( i = 0; i < n; i++)
    {
        printf("A %d = ", i + 1);
        scanf("%d", &A[i]);



    }


        for (i = n-1, j = 0; i >= 0;i--, j++)
    {
        B[j] = A[i];

    }

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


  getch();
}
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
 
#define MY_TMP_FILE "/tmp/file.tmp"
 
 
int main(int argc, char* argv[])
{
    FILE * f;
    if (!access(MY_TMP_FILE, F_OK)) {
        printf external link("File exists!\n");
        return EXIT_FAILURE;
    }
    tmpFile = fopen(MY_TMP_FILE, "w");
 
    if (tmpFile == NULL) {
        return EXIT_FAILURE;
    }
 
    fputs("Some text...\n", tmpFile);
 
    fclose(tmpFile);
 
    return EXIT_SUCCESS;
}
#include <stdio.h>
int main () {
    char username[8];
    int allow = 0;
    printf external link("Enter your username, please: ");
    gets(username);
    if (grantAccess(username)) {
        allow = 1;
    }
    if (allow != 0) {
        privilegedAction();
    }
    return 0;
}
#define R(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
void salsa20_word_specification(uint32 out[16],uint32 in[16])
{
    int i;
    uint32 x[16];
    for (i = 0;i < 16;++i) x[i] = in[i];
    for (i = 20;i > 0;i -= 2) {
        x[ 4] ^= R(x[ 0]+x[12], 7);  x[ 8] ^= R(x[ 4]+x[ 0], 9);
        x[12] ^= R(x[ 8]+x[ 4],13);  x[ 0] ^= R(x[12]+x[ 8],18);
        x[ 9] ^= R(x[ 5]+x[ 1], 7);  x[13] ^= R(x[ 9]+x[ 5], 9);
        x[ 1] ^= R(x[13]+x[ 9],13);  x[ 5] ^= R(x[ 1]+x[13],18);
        x[14] ^= R(x[10]+x[ 6], 7);  x[ 2] ^= R(x[14]+x[10], 9);
        x[ 6] ^= R(x[ 2]+x[14],13);  x[10] ^= R(x[ 6]+x[ 2],18);
        x[ 3] ^= R(x[15]+x[11], 7);  x[ 7] ^= R(x[ 3]+x[15], 9);
        x[11] ^= R(x[ 7]+x[ 3],13);  x[15] ^= R(x[11]+x[ 7],18);
        x[ 1] ^= R(x[ 0]+x[ 3], 7);  x[ 2] ^= R(x[ 1]+x[ 0], 9);
        x[ 3] ^= R(x[ 2]+x[ 1],13);  x[ 0] ^= R(x[ 3]+x[ 2],18);
        x[ 6] ^= R(x[ 5]+x[ 4], 7);  x[ 7] ^= R(x[ 6]+x[ 5], 9);
        x[ 4] ^= R(x[ 7]+x[ 6],13);  x[ 5] ^= R(x[ 4]+x[ 7],18);
        x[11] ^= R(x[10]+x[ 9], 7);  x[ 8] ^= R(x[11]+x[10], 9);
        x[ 9] ^= R(x[ 8]+x[11],13);  x[10] ^= R(x[ 9]+x[ 8],18);
        x[12] ^= R(x[15]+x[14], 7);  x[13] ^= R(x[12]+x[15], 9);
        x[14] ^= R(x[13]+x[12],13);  x[15] ^= R(x[14]+x[13],18);
    }
    for (i = 0;i < 16;++i) out[i] = x[i] + in[i];
}
i = 0
j = 0
for b in range(m):
    i = (i + 1) % 256
    j = (j + S[i]) % 256
    S[i], S[j] = S[j], S[i]
    KS[b] = S[(S[i] + S[j]) % 256]
j = 0;
S = range(256)
for i in range(256):
    j = (j + S[i] + K[i%n]) % 256
    S[i], S[j] = S[j], S[i]
#include <stdio.h>
int main()
{
	int lenght,bredth;
	int end;
	printf("what is the lenght of the rectangle \n");
	scanf("%d",&lenght);
	printf("what is the bredth of rectangle \n");
    scanf("%d",&bredth);
    printf("area of rectangle = %d \n",lenght*bredth);
    printf("Programe By Aaryan \n");
    printf("press any key to proseed");
    scanf("%d",&end);
	return 0;
} 
#include<stdio.h>
#define take(n) scanf("%d",&n);
#define rep(i,a,b) for(int i=a;i<b;i++)
void add_10(int n){
    printf("Enter a number\n");
    int x;
    take(x);
    printf("%d+%d=%d\n",n,x,n+x);
}
void multiply_10(int n){
    printf("Enter a number\n");
    int x;
    take(x);
    printf("%d*%d=%d\n",n,x,n*x);
}

int main()
{
    int n=10;
    char choice;
    int flag=0;
    do{
        printf("Enter your choice either a or b, any other to exit\n");
        scanf("%c",&choice);
        switch(choice){
            case 'A':
            case 'a': add_10(n);
            break;
            case 'B':
            case 'b': multiply_10(n);
            break;
            default: flag=1;
        }
    }while(flag==0);
return 0;
}
#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.
  }
};
#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

Sun Nov 17 2024 02:09:56 GMT+0000 (Coordinated Universal Time)

#loop #c #array
star

Sat Nov 16 2024 15:03:31 GMT+0000 (Coordinated Universal Time)

#loop #c #array
star

Sat Nov 16 2024 09:35:35 GMT+0000 (Coordinated Universal Time)

#loop #c #array
star

Tue Nov 05 2024 00:50:41 GMT+0000 (Coordinated Universal Time)

#c #loop
star

Sun Nov 03 2024 12:49:12 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Nov 03 2024 12:48:01 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Nov 03 2024 12:45:43 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Nov 03 2024 12:40:56 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Oct 07 2024 08:28:51 GMT+0000 (Coordinated Universal Time) https://www.programiz.com/c-programming/online-compiler/

#c
star

Thu Jul 11 2024 15:30:23 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Jun 27 2024 09:41:00 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Jun 12 2024 04:14:25 GMT+0000 (Coordinated Universal Time)

#c #function #struct
star

Wed Jun 12 2024 03:19:24 GMT+0000 (Coordinated Universal Time)

#c #function #struct
star

Wed Jun 12 2024 03:12:37 GMT+0000 (Coordinated Universal Time)

#c #function #struct
star

Tue Jun 11 2024 20:49:42 GMT+0000 (Coordinated Universal Time)

#c #function
star

Tue Jun 11 2024 20:44:52 GMT+0000 (Coordinated Universal Time)

#c #function
star

Tue Jun 11 2024 20:43:03 GMT+0000 (Coordinated Universal Time)

#c #function
star

Tue Jun 11 2024 20:41:15 GMT+0000 (Coordinated Universal Time)

#c #function
star

Tue Jun 11 2024 10:26:42 GMT+0000 (Coordinated Universal Time)

#c #function
star

Tue Jun 11 2024 09:37:37 GMT+0000 (Coordinated Universal Time)

#c #function
star

Tue Jun 11 2024 09:00:43 GMT+0000 (Coordinated Universal Time)

#c #struct
star

Tue Jun 11 2024 08:54:10 GMT+0000 (Coordinated Universal Time)

#c #struct
star

Tue Jun 11 2024 08:54:09 GMT+0000 (Coordinated Universal Time)

#c #struct
star

Tue Jun 11 2024 06:34:32 GMT+0000 (Coordinated Universal Time)

#c #function
star

Tue Jun 11 2024 05:19:27 GMT+0000 (Coordinated Universal Time)

#c #function
star

Tue Jun 11 2024 04:02:57 GMT+0000 (Coordinated Universal Time)

#c #struct
star

Mon Jun 10 2024 12:26:16 GMT+0000 (Coordinated Universal Time)

#c #struct
star

Mon Jun 10 2024 12:15:06 GMT+0000 (Coordinated Universal Time)

#c #enum #struct
star

Mon Jun 10 2024 12:06:37 GMT+0000 (Coordinated Universal Time)

#c #enum #struct
star

Mon Jun 10 2024 11:07:09 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Jun 10 2024 10:40:07 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Jun 09 2024 11:45:30 GMT+0000 (Coordinated Universal Time)

#c #pointer
star

Sun Jun 09 2024 11:36:42 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Jun 09 2024 11:35:40 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Jun 09 2024 11:35:40 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Jun 09 2024 11:33:11 GMT+0000 (Coordinated Universal Time)

#c #pointer
star

Sun Jun 09 2024 11:32:00 GMT+0000 (Coordinated Universal Time)

#c #pointer
star

Sun Jun 09 2024 11:30:52 GMT+0000 (Coordinated Universal Time)

#c #pointer
star

Sun Jun 09 2024 11:29:47 GMT+0000 (Coordinated Universal Time)

#c #pointer
star

Sun Jun 09 2024 11:28:59 GMT+0000 (Coordinated Universal Time)

#c #pointer
star

Sun Jun 09 2024 11:27:57 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Jun 09 2024 11:26:45 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Jun 09 2024 11:10:04 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Jun 08 2024 22:11:09 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Jun 08 2024 21:53:55 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Jun 08 2024 11:26:05 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Jun 07 2024 11:27:55 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Jun 06 2024 06:57:47 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Jun 06 2024 05:51:03 GMT+0000 (Coordinated Universal Time)

#c
star

Sun May 26 2024 13:20:22 GMT+0000 (Coordinated Universal Time)

#c
star

Sun May 26 2024 06:45:25 GMT+0000 (Coordinated Universal Time)

#c
star

Wed May 22 2024 12:21:03 GMT+0000 (Coordinated Universal Time) https://www.alphacodez.com/paxful-clone-script

#c #c++
star

Thu May 09 2024 10:01:04 GMT+0000 (Coordinated Universal Time)

#c
star

Wed May 08 2024 03:49:08 GMT+0000 (Coordinated Universal Time)

#c
star

Wed May 01 2024 22:09:19 GMT+0000 (Coordinated Universal Time)

#c
star

Wed May 01 2024 22:09:19 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 30 2024 09:50:41 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Apr 26 2024 11:58:09 GMT+0000 (Coordinated Universal Time) https://codevalidator.aut.ac.nz/autmoodle1/mod/quiz/attempt.php?attempt

#c
star

Fri Apr 26 2024 11:16:10 GMT+0000 (Coordinated Universal Time) https://codevalidator.aut.ac.nz/autmoodle1/mod/quiz/attempt.php?attempt

#c
star

Thu Apr 25 2024 09:05:42 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Apr 25 2024 08:53:13 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Apr 25 2024 05:54:57 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Apr 25 2024 05:34:44 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Apr 25 2024 05:21:04 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Apr 25 2024 05:11:49 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Apr 24 2024 12:24:58 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Apr 24 2024 11:34:03 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 23 2024 10:08:16 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 23 2024 09:22:34 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Apr 22 2024 19:40:54 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Apr 22 2024 19:21:37 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Apr 22 2024 18:37:29 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Apr 22 2024 18:34:34 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Apr 22 2024 18:31:26 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Apr 22 2024 16:29:09 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Apr 22 2024 16:20:29 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Apr 21 2024 11:23:25 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Apr 21 2024 11:23:02 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Apr 21 2024 11:20:42 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Apr 21 2024 06:59:35 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Apr 18 2024 11:05:58 GMT+0000 (Coordinated Universal Time) https://codevalidator.aut.ac.nz/autmoodle1/mod/quiz/attempt.php?attempt

#c
star

Thu Apr 18 2024 09:15:20 GMT+0000 (Coordinated Universal Time) https://codevalidator.aut.ac.nz/autmoodle1/mod/quiz/attempt.php?attempt

#c
star

Mon Apr 15 2024 18:47:28 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Apr 15 2024 17:48:52 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Apr 14 2024 11:26:26 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Apr 14 2024 11:22:34 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Apr 14 2024 11:19:27 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Apr 11 2024 06:41:12 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Apr 11 2024 06:05:06 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Apr 04 2024 20:18:47 GMT+0000 (Coordinated Universal Time)

#c++ #c #forgottenwoods #camera #parallax
star

Thu Apr 04 2024 20:15:25 GMT+0000 (Coordinated Universal Time)

#c++ #c #forgottenwoods #camera
star

Thu Apr 04 2024 19:03:21 GMT+0000 (Coordinated Universal Time)

#c++ #c #nook #ui #levelselect #menu
star

Thu Apr 04 2024 19:01:17 GMT+0000 (Coordinated Universal Time)

#c++ #c #nook #sprite
star

Thu Apr 04 2024 18:55:58 GMT+0000 (Coordinated Universal Time)

#c++ #c #nook #gameplay
star

Thu Apr 04 2024 18:50:23 GMT+0000 (Coordinated Universal Time)

#c++ #c #nook #ui #menu
star

Thu Apr 04 2024 18:44:13 GMT+0000 (Coordinated Universal Time)

#c++ #c #mesh #sprite #nook
star

Thu Apr 04 2024 18:39:31 GMT+0000 (Coordinated Universal Time)

#c++ #c #audio
star

Thu Apr 04 2024 01:13:32 GMT+0000 (Coordinated Universal Time)

#c++ #c
star

Wed Mar 13 2024 02:35:09 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Mar 06 2024 12:08:12 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Mar 06 2024 02:39:42 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Feb 14 2024 09:25:46 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Feb 08 2024 05:17:46 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Jan 24 2024 02:46:50 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Dec 19 2023 19:52:07 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Dec 13 2023 10:34:32 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Dec 11 2023 18:28:00 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Dec 11 2023 17:54:20 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Dec 10 2023 09:24:37 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Dec 09 2023 20:28:27 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Dec 09 2023 20:15:34 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Dec 09 2023 17:22:39 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Dec 09 2023 15:37:33 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Dec 09 2023 14:29:46 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Nov 12 2023 14:18:50 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Oct 18 2023 07:18:43 GMT+0000 (Coordinated Universal Time) https://www.programiz.com/c-programming/examples/print-sentence

#c
star

Sun Sep 24 2023 13:02:47 GMT+0000 (Coordinated Universal Time) https://www.programiz.com/c-programming/online-compiler/

#c
star

Sun Sep 24 2023 09:38:44 GMT+0000 (Coordinated Universal Time) https://www.programiz.com/c-programming/online-compiler/

#c
star

Sat Sep 23 2023 13:20:48 GMT+0000 (Coordinated Universal Time) undefined

#c
star

Wed Sep 13 2023 05:26:47 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Sep 12 2023 15:51:54 GMT+0000 (Coordinated Universal Time) https://www.w3schools.com/c/tryc.php?filename

#c #pointers
star

Wed Sep 06 2023 03:55:45 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Sep 05 2023 14:26:17 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Sep 05 2023 09:01:48 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Aug 21 2023 19:59:52 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Jul 25 2023 22:16:36 GMT+0000 (Coordinated Universal Time)

#c
star

Mon May 22 2023 07:48:02 GMT+0000 (Coordinated Universal Time)

#code #in #c #maxi #and #minimum #divid #conquer
star

Mon May 22 2023 07:05:14 GMT+0000 (Coordinated Universal Time)

#code #in #c #jobsequencingwithdeadline
star

Mon May 22 2023 03:06:48 GMT+0000 (Coordinated Universal Time)

#code #in #c #jobsequencingwith deadline
star

Mon May 22 2023 03:04:22 GMT+0000 (Coordinated Universal Time)

##knapsack #simple #code #in #c
star

Fri May 05 2023 15:02:16 GMT+0000 (Coordinated Universal Time)

#c
star

Thu May 04 2023 20:06:40 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Apr 22 2023 10:43:31 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Apr 21 2023 12:40:28 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Apr 21 2023 09:35:15 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 18 2023 12:00:18 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 18 2023 11:27:27 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 18 2023 10:57:36 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 18 2023 10:48:18 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 18 2023 09:41:22 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Apr 17 2023 12:39:00 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Apr 17 2023 03:58:46 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Apr 16 2023 06:10:52 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Apr 15 2023 08:12:00 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:41:44 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:40:27 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:38:58 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:37:04 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:35:18 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:31:40 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:31:01 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:29:16 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:28:12 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:27:27 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:26:30 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:25:33 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:24:29 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Apr 11 2023 16:23:33 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Apr 07 2023 14:00:49 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Apr 07 2023 13:36:48 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:42:03 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:41:36 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:41:36 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:40:53 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:40:14 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:32:23 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:25:43 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:24:35 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:23:08 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:22:39 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:21:49 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:20:59 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:20:25 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:19:12 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:18:30 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:17:58 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:17:23 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:14:58 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:12:04 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Mar 20 2023 13:09:08 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Mar 19 2023 22:50:39 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Mar 19 2023 18:59:52 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Mar 19 2023 18:52:51 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Mar 17 2023 19:37:25 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Mar 17 2023 17:30:56 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Mar 15 2023 10:33:02 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Mar 15 2023 10:31:03 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Mar 15 2023 10:16:18 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Mar 14 2023 10:53:50 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Mar 14 2023 10:53:16 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Mar 14 2023 10:52:22 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Mar 14 2023 08:09:00 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Mar 11 2023 13:34:10 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Mar 11 2023 13:26:08 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Mar 11 2023 12:33:14 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Mar 11 2023 06:24:48 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Mar 10 2023 16:08:06 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Mar 10 2023 16:05:57 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Mar 10 2023 16:05:39 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Mar 10 2023 16:04:53 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Mar 10 2023 16:02:46 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Mar 10 2023 15:56:34 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Mar 10 2023 15:55:23 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Feb 28 2023 10:24:54 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Feb 27 2023 13:43:19 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Feb 02 2023 01:24:05 GMT+0000 (Coordinated Universal Time) https://stmicroelectronics.sharepoint.com/teams/MassMarket-UseCases/SitePages/VL53L5CX.aspx

#c #histogram
star

Mon Jan 23 2023 11:31:10 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Jan 22 2023 23:07:33 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Jan 22 2023 21:28:11 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Jan 10 2023 18:04:47 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Jan 10 2023 15:09:55 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Jan 10 2023 14:19:04 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Jan 01 2023 19:08:35 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Dec 26 2022 20:52:01 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Dec 25 2022 22:23:47 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Dec 25 2022 22:22:40 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Dec 20 2022 19:10:30 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Dec 20 2022 11:21:13 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Dec 20 2022 10:48:44 GMT+0000 (Coordinated Universal Time) https://s3.cloud.ngn.com.tr/clu10-alms1/course/199532/activity/208254/inclassexercises.txt?AWSAccessKeyId

#c
star

Tue Dec 20 2022 10:48:06 GMT+0000 (Coordinated Universal Time) https://s3.cloud.ngn.com.tr/clu10-alms1/course/199532/activity/208253/lab7_solution_.txt?AWSAccessKeyId

#c
star

Fri Dec 09 2022 10:15:12 GMT+0000 (Coordinated Universal Time) https://chat.openai.com/chat

#c
star

Sat Dec 03 2022 12:08:27 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Nov 26 2022 12:19:50 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Nov 15 2022 00:54:02 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/21323099/convert-a-hexadecimal-to-a-float-and-viceversa-in-c

#c
star

Tue Nov 15 2022 00:53:41 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/21323099/convert-a-hexadecimal-to-a-float-and-viceversa-in-c

#c
star

Sat Nov 12 2022 14:39:45 GMT+0000 (Coordinated Universal Time) https://randomnerdtutorials.com/esp32-microsd-card-arduino/

#c
star

Mon Sep 19 2022 08:24:24 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Sep 19 2022 05:43:19 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Sep 19 2022 04:42:01 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Sep 18 2022 14:05:54 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Sep 18 2022 08:42:24 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Sep 18 2022 06:52:33 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Sep 18 2022 06:25:53 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Sep 18 2022 06:04:54 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Sep 18 2022 05:22:54 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Sep 12 2022 05:07:41 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Sep 10 2022 09:01:37 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Sep 01 2022 17:47:16 GMT+0000 (Coordinated Universal Time) https://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html

#c
star

Fri Aug 26 2022 23:57:58 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Aug 19 2022 14:41:36 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Aug 19 2022 14:38:20 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Aug 14 2022 04:08:41 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Jun 03 2022 11:44:52 GMT+0000 (Coordinated Universal Time) https://favtutor.com/blogs/longest-consecutive-sequence

#c #java
star

Thu May 26 2022 15:44:58 GMT+0000 (Coordinated Universal Time)

#c #binarysearch
star

Thu Apr 28 2022 07:46:39 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/49722736/how-to-use-critical-section

#c
star

Mon Apr 25 2022 15:14:18 GMT+0000 (Coordinated Universal Time) https://github.com/espressif/esp-idf/tree/45c1d1cba2/examples/protocols/mqtt/ssl

#c
star

Sat Apr 16 2022 02:02:04 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Apr 16 2022 00:18:04 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Apr 15 2022 22:32:54 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Apr 15 2022 22:32:03 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Apr 15 2022 22:31:13 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Apr 15 2022 22:21:38 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Apr 15 2022 22:16:09 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Apr 07 2022 16:58:46 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Mar 27 2022 23:48:02 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/1835986/how-to-use-eof-to-run-through-a-text-file-in-c

#c
star

Sun Mar 27 2022 23:37:02 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/20378430/reading-numbers-from-a-text-file-into-an-array-in-c

#c
star

Wed Mar 16 2022 03:49:05 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Mar 06 2022 16:33:40 GMT+0000 (Coordinated Universal Time) https://randomnerdtutorials.com/esp8266-nodemcu-webserial-library/

#c
star

Sat Mar 05 2022 06:58:46 GMT+0000 (Coordinated Universal Time) https://www.tutorialspoint.com/c_standard_library/c_function_rand.htm

#c
star

Thu Feb 17 2022 12:49:49 GMT+0000 (Coordinated Universal Time)

#c++ #c
star

Sat Feb 12 2022 17:19:51 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Feb 09 2022 11:45:45 GMT+0000 (Coordinated Universal Time) https://www.tutorialspoint.com/data_structures_algorithms/linked_list_program_in_c.htm

#c
star

Mon Feb 07 2022 19:30:22 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Feb 06 2022 15:02:55 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Feb 03 2022 11:16:32 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Feb 02 2022 20:27:00 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Feb 01 2022 18:25:03 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Jan 31 2022 19:53:43 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Jan 31 2022 19:39:47 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Jan 31 2022 18:56:10 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Jan 30 2022 17:07:08 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Jan 29 2022 19:56:44 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Jan 29 2022 19:47:16 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Jan 20 2022 22:42:41 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Jan 04 2022 06:41:48 GMT+0000 (Coordinated Universal Time)

#c #java
star

Mon Oct 25 2021 13:57:16 GMT+0000 (Coordinated Universal Time)

#c #c++
star

Mon Sep 20 2021 13:35:43 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Sep 20 2021 13:34:16 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Sep 19 2021 18:27:20 GMT+0000 (Coordinated Universal Time) https://www.delftstack.com/howto/csharp/pass-function-as-parameter-inside-another-function-in-csharp/

#c
star

Sun Sep 19 2021 18:26:26 GMT+0000 (Coordinated Universal Time) https://www.delftstack.com/howto/csharp/pass-function-as-parameter-inside-another-function-in-csharp/

#c
star

Mon Sep 13 2021 03:53:58 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Sep 08 2021 17:03:07 GMT+0000 (Coordinated Universal Time) https://dmerej.info/blog/post/symlinks-and-so-files-on-linux/

#c
star

Sun Sep 05 2021 18:21:30 GMT+0000 (Coordinated Universal Time)

#c #c++
star

Sun Sep 05 2021 18:20:03 GMT+0000 (Coordinated Universal Time)

#c #c++
star

Sun Sep 05 2021 18:12:07 GMT+0000 (Coordinated Universal Time)

#c #c++
star

Sat Sep 04 2021 06:53:52 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Sep 04 2021 06:16:48 GMT+0000 (Coordinated Universal Time)

#c
star

Fri Sep 03 2021 14:57:32 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Aug 31 2021 13:20:07 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Aug 31 2021 13:07:30 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Aug 31 2021 12:54:29 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Aug 31 2021 12:34:21 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Aug 31 2021 11:52:00 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Aug 30 2021 01:00:16 GMT+0000 (Coordinated Universal Time)

#c #c++
star

Mon Aug 30 2021 00:22:03 GMT+0000 (Coordinated Universal Time)

#c
star

Mon Aug 30 2021 00:18:42 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Aug 26 2021 02:58:07 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Aug 24 2021 03:33:26 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Aug 24 2021 02:03:41 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Aug 24 2021 01:35:16 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Aug 19 2021 14:22:09 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Aug 19 2021 13:46:14 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Aug 19 2021 13:25:52 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Aug 19 2021 03:33:17 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Aug 19 2021 03:20:49 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Aug 19 2021 03:02:11 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Aug 19 2021 02:44:08 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Aug 19 2021 01:24:02 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Aug 17 2021 03:04:49 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Aug 17 2021 02:03:30 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Aug 15 2021 20:43:46 GMT+0000 (Coordinated Universal Time)

#c
star

Sun Aug 15 2021 20:38:50 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Aug 03 2021 20:57:49 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Aug 03 2021 19:45:50 GMT+0000 (Coordinated Universal Time)

#c
star

Tue Aug 03 2021 19:07:13 GMT+0000 (Coordinated Universal Time)

#c
star

Thu Jul 29 2021 08:52:36 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Jul 28 2021 13:07:41 GMT+0000 (Coordinated Universal Time) https://www.sanfoundry.com/c-program-implement-queue-using-two-stacks/

#c
star

Tue Jul 27 2021 15:04:44 GMT+0000 (Coordinated Universal Time)

#c
star

Sat Jul 24 2021 11:05:40 GMT+0000 (Coordinated Universal Time)

#c
star

Wed May 26 2021 22:05:48 GMT+0000 (Coordinated Universal Time) 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 (Coordinated Universal Time) https://www.c-plusplus.net/forum/topic/270976/was-ist-ein-wrapper

#c #c++ #wrapper
star

Wed Dec 09 2020 05:39:08 GMT+0000 (Coordinated Universal Time) 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 (Coordinated Universal Time) https://www.educative.io/edpresso/how-to-use-the-fgets-function-in-c

#c
star

Sun Sep 27 2020 09:35:30 GMT+0000 (Coordinated Universal Time)

#c
star

Wed Jun 24 2020 08:57:25 GMT+0000 (Coordinated Universal Time) 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