Snippets Collections
#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

Thu Feb 02 2023 01:24:05 GMT+0000 (UTC) https://stmicroelectronics.sharepoint.com/teams/MassMarket-UseCases/SitePages/VL53L5CX.aspx

#c #histogram
star

Mon Jan 23 2023 11:31:10 GMT+0000 (UTC)

#c
star

Sun Jan 22 2023 23:07:33 GMT+0000 (UTC)

#c
star

Sun Jan 22 2023 21:28:11 GMT+0000 (UTC)

#c
star

Tue Jan 10 2023 18:04:47 GMT+0000 (UTC)

#c
star

Tue Jan 10 2023 15:09:55 GMT+0000 (UTC)

#c
star

Tue Jan 10 2023 14:19:04 GMT+0000 (UTC)

#c
star

Sun Jan 01 2023 19:08:35 GMT+0000 (UTC)

#c
star

Mon Dec 26 2022 20:52:01 GMT+0000 (UTC)

#c
star

Sun Dec 25 2022 22:23:47 GMT+0000 (UTC)

#c
star

Sun Dec 25 2022 22:22:40 GMT+0000 (UTC)

#c
star

Tue Dec 20 2022 19:10:30 GMT+0000 (UTC)

#c
star

Tue Dec 20 2022 11:21:13 GMT+0000 (UTC)

#c
star

Tue Dec 20 2022 10:48:44 GMT+0000 (UTC) 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 (UTC) 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 (UTC) https://chat.openai.com/chat

#c
star

Sat Dec 03 2022 12:08:27 GMT+0000 (UTC)

#c
star

Sat Nov 26 2022 12:19:50 GMT+0000 (UTC)

#c
star

Tue Nov 15 2022 00:54:02 GMT+0000 (UTC) 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 (UTC) 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 (UTC) https://randomnerdtutorials.com/esp32-microsd-card-arduino/

#c
star

Mon Sep 19 2022 08:24:24 GMT+0000 (UTC)

#c
star

Mon Sep 19 2022 05:43:19 GMT+0000 (UTC)

#c
star

Mon Sep 19 2022 04:42:01 GMT+0000 (UTC)

#c
star

Sun Sep 18 2022 14:05:54 GMT+0000 (UTC)

#c
star

Sun Sep 18 2022 08:42:24 GMT+0000 (UTC)

#c
star

Sun Sep 18 2022 06:52:33 GMT+0000 (UTC)

#c
star

Sun Sep 18 2022 06:25:53 GMT+0000 (UTC)

#c
star

Sun Sep 18 2022 06:04:54 GMT+0000 (UTC)

#c
star

Sun Sep 18 2022 05:22:54 GMT+0000 (UTC)

#c
star

Mon Sep 12 2022 05:07:41 GMT+0000 (UTC)

#c
star

Sat Sep 10 2022 09:01:37 GMT+0000 (UTC)

#c
star

Thu Sep 01 2022 17:47:16 GMT+0000 (UTC) https://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html

#c
star

Fri Aug 26 2022 23:57:58 GMT+0000 (UTC)

#c
star

Fri Aug 19 2022 14:41:36 GMT+0000 (UTC)

#c
star

Fri Aug 19 2022 14:38:20 GMT+0000 (UTC)

#c
star

Sun Aug 14 2022 04:08:41 GMT+0000 (UTC)

#c
star

Fri Jun 03 2022 11:44:52 GMT+0000 (UTC) https://favtutor.com/blogs/longest-consecutive-sequence

#c #java
star

Thu May 26 2022 15:44:58 GMT+0000 (UTC)

#c #binarysearch
star

Thu Apr 28 2022 07:46:39 GMT+0000 (UTC) https://stackoverflow.com/questions/49722736/how-to-use-critical-section

#c
star

Mon Apr 25 2022 15:14:18 GMT+0000 (UTC) https://github.com/espressif/esp-idf/tree/45c1d1cba2/examples/protocols/mqtt/ssl

#c
star

Sat Apr 16 2022 02:02:04 GMT+0000 (UTC)

#c
star

Sat Apr 16 2022 00:18:04 GMT+0000 (UTC)

#c
star

Fri Apr 15 2022 22:32:54 GMT+0000 (UTC)

#c
star

Fri Apr 15 2022 22:32:03 GMT+0000 (UTC)

#c
star

Fri Apr 15 2022 22:31:13 GMT+0000 (UTC)

#c
star

Fri Apr 15 2022 22:21:38 GMT+0000 (UTC)

#c
star

Fri Apr 15 2022 22:16:09 GMT+0000 (UTC)

#c
star

Thu Apr 07 2022 16:58:46 GMT+0000 (UTC)

#c
star

Sun Mar 27 2022 23:48:02 GMT+0000 (UTC) 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 (UTC) 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 (UTC)

#c
star

Sun Mar 06 2022 16:33:40 GMT+0000 (UTC) https://randomnerdtutorials.com/esp8266-nodemcu-webserial-library/

#c
star

Sat Mar 05 2022 06:58:46 GMT+0000 (UTC) https://www.tutorialspoint.com/c_standard_library/c_function_rand.htm

#c
star

Thu Feb 17 2022 12:49:49 GMT+0000 (UTC)

#c++ #c
star

Sat Feb 12 2022 17:19:51 GMT+0000 (UTC)

#c
star

Wed Feb 09 2022 11:45:45 GMT+0000 (UTC) https://www.tutorialspoint.com/data_structures_algorithms/linked_list_program_in_c.htm

#c
star

Mon Feb 07 2022 19:30:22 GMT+0000 (UTC)

#c
star

Sun Feb 06 2022 15:02:55 GMT+0000 (UTC)

#c
star

Thu Feb 03 2022 11:16:32 GMT+0000 (UTC)

#c
star

Wed Feb 02 2022 20:27:00 GMT+0000 (UTC)

#c
star

Tue Feb 01 2022 18:25:03 GMT+0000 (UTC)

#c
star

Mon Jan 31 2022 19:53:43 GMT+0000 (UTC)

#c
star

Mon Jan 31 2022 19:39:47 GMT+0000 (UTC)

#c
star

Mon Jan 31 2022 18:56:10 GMT+0000 (UTC)

#c
star

Sun Jan 30 2022 17:07:08 GMT+0000 (UTC)

#c
star

Sat Jan 29 2022 19:56:44 GMT+0000 (UTC)

#c
star

Sat Jan 29 2022 19:47:16 GMT+0000 (UTC)

#c
star

Thu Jan 20 2022 22:42:41 GMT+0000 (UTC)

#c
star

Tue Jan 04 2022 06:41:48 GMT+0000 (UTC)

#c #java
star

Mon Oct 25 2021 13:57:16 GMT+0000 (UTC)

#c #c++
star

Mon Sep 20 2021 13:35:43 GMT+0000 (UTC)

#c
star

Mon Sep 20 2021 13:34:16 GMT+0000 (UTC)

#c
star

Sun Sep 19 2021 18:27:20 GMT+0000 (UTC) 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 (UTC) 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 (UTC)

#c
star

Wed Sep 08 2021 17:03:07 GMT+0000 (UTC) https://dmerej.info/blog/post/symlinks-and-so-files-on-linux/

#c
star

Sun Sep 05 2021 18:21:30 GMT+0000 (UTC)

#c #c++
star

Sun Sep 05 2021 18:20:03 GMT+0000 (UTC)

#c #c++
star

Sun Sep 05 2021 18:12:07 GMT+0000 (UTC)

#c #c++
star

Sat Sep 04 2021 06:53:52 GMT+0000 (UTC)

#c
star

Tue Aug 31 2021 12:54:29 GMT+0000 (UTC)

#c
star

Tue Aug 31 2021 11:52:00 GMT+0000 (UTC)

#c
star

Mon Aug 30 2021 01:00:16 GMT+0000 (UTC)

#c #c++
star

Mon Aug 30 2021 00:22:03 GMT+0000 (UTC)

#c
star

Mon Aug 30 2021 00:18:42 GMT+0000 (UTC)

#c
star

Thu Aug 26 2021 02:58:07 GMT+0000 (UTC)

#c
star

Tue Aug 24 2021 03:33:26 GMT+0000 (UTC)

#c
star

Tue Aug 24 2021 01:35:16 GMT+0000 (UTC)

#c
star

Thu Aug 19 2021 13:25:52 GMT+0000 (UTC)

#c
star

Thu Aug 19 2021 03:20:49 GMT+0000 (UTC)

#c
star

Thu Aug 19 2021 03:02:11 GMT+0000 (UTC)

#c
star

Thu Aug 19 2021 02:44:08 GMT+0000 (UTC)

#c
star

Thu Aug 19 2021 01:24:02 GMT+0000 (UTC)

#c
star

Tue Aug 17 2021 03:04:49 GMT+0000 (UTC)

#c
star

Tue Aug 17 2021 02:03:30 GMT+0000 (UTC)

#c
star

Sun Aug 15 2021 20:43:46 GMT+0000 (UTC)

#c
star

Sun Aug 15 2021 20:38:50 GMT+0000 (UTC)

#c
star

Tue Aug 03 2021 20:57:49 GMT+0000 (UTC)

#c
star

Tue Aug 03 2021 19:45:50 GMT+0000 (UTC)

#c
star

Tue Aug 03 2021 19:07:13 GMT+0000 (UTC)

#c
star

Thu Jul 29 2021 08:52:36 GMT+0000 (UTC)

#c
star

Wed Jul 28 2021 13:07:41 GMT+0000 (UTC) https://www.sanfoundry.com/c-program-implement-queue-using-two-stacks/

#c
star

Tue Jul 27 2021 15:04:44 GMT+0000 (UTC)

#c
star

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

#c
star

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

#c #c++ #wrapper
star

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

#c #c++ #wrapper
star

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

#c
star

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

#c
star

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

#c
star

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

#c

Save snippets that work with our extensions

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