Showing posts with label Value. Show all posts
Showing posts with label Value. Show all posts

C Program to Demonstrates changing the keypad size and key values.

How to write a C Program to Demonstrates changing the keypad size and key values ?

Solution:

/* C Program to Demonstrates changing the keypad size and key values.*/
#include <Keypad.h>
#include <stdlib.h>
#include <pitches.h>

double notes[89] = {31,33,35,37,39,41,44,46,49,52,55,58,62,65,69,73,78,82,87,93,98,104,110,117,123,131,139,147,156,165,175,185,196,208,220,233,247,262,277,294,311,330,349,370,392,415,440,466,494,523,554,587,622,659,698,740,784,831,880,932,988,1047,1109,1175,1245,1319,1397,1480,1568,1661,1760,1865,1976,2093,2217,2349,2489,2637,2794,2960,3136,3322,3520,3729,3951,4186,4435,4699,4978};
const byte ROWS = 8; //four rows
const byte COLS = 8; //four columns
//define the cymbols on the buttons of the keypads
byte hexaKeys[ROWS][COLS] = {
  {1, 1, 9, 9, 17, 17, 25, 25},
  {2, 2, 10, 10, 18, 18, 26, 26},
  {3, 3, 11, 11, 19, 19, 27, 27},
  {4, 4, 12, 12, 20, 20, 28, 28},
  {5, 5, 13, 13, 21, 21, 29, 29},
  {6, 6, 14, 14, 22, 22, 30, 30},
  {7, 7, 15, 15, 23, 23, 31, 31},
  {8, 8, 16, 16, 24, 24, 32, 32}

};
byte rowPins[ROWS] = {2, 3, 4, 5, 6, 7, 8, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A8, A9, A10, A11, A12, A13, A14, A15}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad kpd = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

#define trigPin 53
#define echoPin 51

void setup(){
  Serial.begin(9600);
  pinMode(49, HIGH);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop(){
  if (kpd.getKeys()){
        for (int i=0; i<LIST_MAX; i++) {  // Scan the whole key list.
            if ( kpd.key[i].stateChanged ) {  // Only find keys that have changed state.
                char j = kpd.key[i].kchar + 40;
                switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                    case PRESSED:
                    tone(13, (notes[j] * pitchBend()), 0);
                    Serial.print(pitchBend());
                    Serial.print("\n");
                    break;
             
                    case RELEASED:
                    tone(13, 0, 1);
                }
            }
        }
    }
}

double pitchBend(){
  double duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  Serial.print(distance);
  if (distance < 50){
    return distance/200+1;
  }
  else{
    return 1;
  }
}

C Program To Find The Maximum And Minimum Value In An Array

How to write a C Program To Find The Maximum And Minimum Value In An Array in C Programming Language ?


Solution For C Program :

/*C Program To Find The Maximum And Minimum Value In An Array*/

#include<stdio.h>
#include<conio.h>
void main()
    {
    int k;
    int a[5],i,j,max=0,min=0;
    printf("Enter how many numbers in array:=");
    scanf("%d",&k);
    printf("enter the numbers:\n");
    for(i=0;i<k;i++)
        {
        scanf("%d",&a[i]);
        }
        max=a[0];
        min=a[0];
        for(i=1;i<k;i++)
            {
            if(a[i]>max)
            {
            max=a[i];
            }
            if(a[i]<min)
            {
            min=a[i];
            }
            }
    printf("Maximum value of array:=%d\n",max);
    printf("Minimum value of array:=%d",min);
    getch();
    }

C Program To Find Simple Interest

How to write a C Program to find Simple Interest Using function with Parameters and Returning a Value in C Programming Language ?

Solution For C Program :

/*C Program To Find Simple Interest*/

#include <stdio.h>
void main()
{
int p, t;
float r;
float SimpleInterest(int p, int t, float r);
printf("\nEnter the Principle Amount, Term, Rate of Interest : ");
scanf("%d%d%f", &p, &t, &r);
printf("\nThe Simple Interest for the Principle Amount %d for %d Years with an
Interest of %0.2f", p, t, r);
printf("\n is %f.", SimpleInterest(p, t, r));
}
float SimpleInterest(int p, int t, float r)
{
return((p * t * r) / 100);
}


You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

C Program to Calculation of One Number Raised to Another

How to write a C Program to Calculation of One Number Raised to Another in C Programming Language ?

Two numbers are entered through the keyboard. Write a program to find the value of one number raised to the power of another. 


  1. #include<stdio.h>
  2. main()
  3. {
  4. int num1, index, result, temp; /* num2=index*/
  5.  
  6. printf("Enter the number:");
  7. scanf ("%d", &num1);
  8.  
  9. printf("Enter the index:");
  10. scanf("%d", &index);
  11.  
  12. result=1;
  13. temp=1;
  14.  
  15. while(temp<=index)
  16.  
  17. {
  18. result = result*num1;
  19.  
  20. temp++;
  21.  
  22. }
  23.  
  24. printf("%d raised to %d is: %d ", num1, index, result);
  25.  
  26. }


Another C Program to Calculation of One Number Raised to Another:



  1. #include
  2.  
  3. main()
  4. {
  5. int i,n,res;
  6. printf("Enter the Num:");
  7. scanf("%d", &n);
  8. printf("Enter the index:");
  9. scanf("%d", &i);
  10. res=pow(n,i);
  11. printf("The number " %" raised to the power " %"is "%"==" %d, n,i,res );
  12. }
  13. }

C Program to Calculation of One Number Raised to Another:


  1. #include
  2. main()
  3. {
  4. int a,b,c,d;
  5. printf("Enter two numbers separated by space: ");
  6. scanf("%d%d",&a,&b);
  7. = pow(a,b);
  8. printf("The value of, %d raised to the power of %d is %d",a,b,c);
  9. }

C Program to find value of x by Pythagoras Theorem - Complex Number

How to Write a C Program to find value of x by Pythagoras Theorem - Complex Number in C Programming Language ?


Solution:

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <math.h>
  4. void main()
  5. {
  6.  int a,b,c,i,n,j;
  7.  float r,x1,d,x2,e,f,x;
  8.  clrscr();
  9.  printf("Enter Value for a, b and c: ");
  10.  scanf("%d %d %d",&a,&b,&c);
  11.  f=(b/(2*a));
  12.  r=(b*b)-(4*a*c);
  13.  if(r>0)
  14.  {
  15.   d=sqrt(r);
  16.   x=d/(2*a);
  17.   x1=-f+x;
  18.   x2=-f-x;
  19.   printf("x=%.2f, %.2f",x1,x2);
  20.  }
  21.  else
  22.  {
  23.   e=-r;
  24.   d=sqrt(e);
  25.   x=e/(2*a);
  26.   printf("x=(%.2f-i%.2f), (%.2f+i%.2f)",f,x,f,x);
  27.  }
  28.  getch();
  29. }

C Program to find result where value and power are user given

How to Write a C Program to find result where value and power are user given in C Programming Language ?


Solution:

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5.  int a,p,n,r;
  6.  clrscr();
  7.  printf("Enter Number: ");
  8.  scanf("%d",&n);
  9.  printf("\nEnter Power: ");
  10.  scanf("%d",&p);
  11.  for(a=p;a!=0;a--)
  12.  {
  13.   r=n*n;
  14.  }
  15.  printf("%d",r);
  16.  getch();
  17. }