Thought I commited this stuff lol
This commit is contained in:
parent
79ea6545b1
commit
1233cd19e8
41 changed files with 668 additions and 0 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
[submodule "Playground/intro-pointers"]
|
||||
path = Playground/intro-pointers
|
||||
url = https://github.com/dbrumbaugh/intro-pointers
|
30
Adding Vectors.c
Normal file
30
Adding Vectors.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* Adding Vectors
|
||||
*
|
||||
* A Program that adds vectors given the components.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
float u1, u2, v1, v2; /* Components */
|
||||
|
||||
/* Prompt user for variables */
|
||||
printf("Enter the first component of vector 𝐮 (𝑢₁): ");
|
||||
scanf("%f", &u1);
|
||||
|
||||
printf("Enter the second component of vector 𝐮 (𝑢₂): ");
|
||||
scanf("%f", &u2);
|
||||
|
||||
printf("Enter the first component of vector 𝐯 (𝑣₁): ");
|
||||
scanf("%f", &v1);
|
||||
|
||||
printf("Enter the second component of vector 𝐯 (𝑣₂): ");
|
||||
scanf("%f", &v2);
|
||||
|
||||
/* Print the sum of the vectors */
|
||||
printf("𝐮 + 𝐯 = <%.2f, %.2f>\n", u1 + v1, u2 + v2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
17
After Decimal.c
Normal file
17
After Decimal.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main () {
|
||||
float n, d; /* Full Number, Decimal */
|
||||
int i; /* Integer */
|
||||
|
||||
printf("Enter decimal number: ");
|
||||
scanf("%f", &n);
|
||||
|
||||
i = (int)n;
|
||||
d = n - i;
|
||||
|
||||
printf("The number after the decimal is %f", d);
|
||||
|
||||
return 0;
|
||||
}
|
65
Angle Between Two Vectors.c
Normal file
65
Angle Between Two Vectors.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
/* Angle Between Two Vectors
|
||||
*
|
||||
* A prgorgam that calculates the angle between to vectors
|
||||
* givien 𝑎 and 𝑏 of each vector.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
int main() {
|
||||
float a1, b1, a2, b2; /* Vector Compenents */
|
||||
|
||||
/* Print the vector forms */
|
||||
printf("Vector form: 𝑎𝐢 + 𝑏𝐣 or <𝑎, 𝑏>\n");
|
||||
|
||||
/* Prompt user for variables */
|
||||
printf("Enter 𝑎₁: ");
|
||||
scanf("%f", &a1);
|
||||
|
||||
printf("Enter 𝑏₁: ");
|
||||
scanf("%f", &b1);
|
||||
|
||||
printf("Enter 𝑎₂: ");
|
||||
scanf("%f", &a2);
|
||||
|
||||
printf("Enter 𝑏₂: ");
|
||||
scanf("%f", &b2);
|
||||
|
||||
/* Sanity Check
|
||||
*
|
||||
* If 𝑎 and 𝑏 equal 0, exit the program.
|
||||
*/
|
||||
if ((a1 == 0 && b1 == 0) || (a2 == 0 && b2 == 0)) {
|
||||
printf("Error: Division by 0\n");
|
||||
|
||||
exit(1);
|
||||
};
|
||||
|
||||
/* Calculate values of additional variables */
|
||||
float cosr = (a1 * a2 + b1 * b2) / (sqrt(a1 * a1 + b1 * b1) * sqrt(a2 * a2 + b2 * b2));
|
||||
float r = acos(cosr); /* Angle in radians */
|
||||
float d = r * (180 / M_PI); /* Angle in degrees */
|
||||
|
||||
/* Sanity Check
|
||||
*
|
||||
* Sometimes the caulculations are not percise enough.
|
||||
*
|
||||
* If variable cosr is greater than or equal to 1 or
|
||||
* less than or equal to -1, r = 0 or pi, and d = 0 or 180.
|
||||
*/
|
||||
if (cosr > 1) {
|
||||
r = d = 0;
|
||||
} else if (cosr < -1) {
|
||||
r = M_PI;
|
||||
d = 180;
|
||||
}
|
||||
|
||||
/* Print angle between the two vectors */
|
||||
printf("Angle in radians: %.2f\n", r);
|
||||
printf("Angle in degrees: %.2f\n", d);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
102
Area of a Triangle.c
Normal file
102
Area of a Triangle.c
Normal file
|
@ -0,0 +1,102 @@
|
|||
/* Area of a Triangle
|
||||
*
|
||||
* A prgorgam that cauclatales the area of a
|
||||
* triangle based on user-provided parameters.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
int main() {
|
||||
int o; /* Option */
|
||||
|
||||
/* Print the options, then prompt */
|
||||
printf("(1) ASA\n");
|
||||
printf("(2) SAS\n");
|
||||
printf("(3) SSS\n");
|
||||
printf("(1|2|3) ");
|
||||
scanf("%d", &o);
|
||||
|
||||
/* Sanity Check
|
||||
*
|
||||
* If the user provides an argument that
|
||||
* is not 1, 2, or 3, exit the program.
|
||||
*/
|
||||
if (o != 1 && o != 2 && o != 3) {
|
||||
printf("Error: Invalid Argument\n");
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* ASA */
|
||||
if (o == 1) {
|
||||
float a1, s, a2;
|
||||
|
||||
/* Prompt user for variables */
|
||||
printf("Enter the first angle: ");
|
||||
scanf("%f", &a1);
|
||||
|
||||
printf("Enter the side: ");
|
||||
scanf("%f", &s);
|
||||
|
||||
printf("Enter the second angle: ");
|
||||
scanf("%f", &a2);
|
||||
|
||||
/* Convert degrees to radians */
|
||||
a1 = a1 * (M_PI / 180);
|
||||
a2 = a2 * (M_PI / 180);
|
||||
|
||||
/* Print the area */
|
||||
printf("Area = %.2f", (s * s * sin(a1) * sin(a2)) / (2 * sin(a1 + a2)));
|
||||
|
||||
}
|
||||
|
||||
/* SAS */
|
||||
if (o == 2) {
|
||||
float s1, a, s2;
|
||||
|
||||
/* Prompt user for variables */
|
||||
printf("Enter the first side: ");
|
||||
scanf("%f", &s1);
|
||||
|
||||
printf("Enter the angle: ");
|
||||
scanf("%f", &a);
|
||||
|
||||
printf("Enter the second side: ");
|
||||
scanf("%f", &s2);
|
||||
|
||||
/* Convert degrees to radians */
|
||||
a = a * (M_PI / 180);
|
||||
|
||||
/* Print the area */
|
||||
printf("Area = %.2f", 0.5 * s1 * s2 * sin(a));
|
||||
}
|
||||
|
||||
/* SSS */
|
||||
if (o == 3) {
|
||||
float s1, s2, s3;
|
||||
|
||||
/* Prompt user for variables */
|
||||
printf("Enter the first side: ");
|
||||
scanf("%f", &s1);
|
||||
|
||||
printf("Enter the second side: ");
|
||||
scanf("%f", &s2);
|
||||
|
||||
printf("Enter the third side: ");
|
||||
scanf("%f", &s3);
|
||||
|
||||
/* Calculate the value of the additional variable, 𝑧 */
|
||||
float z = (s1 + s2 + s3) / 2; /* 𝑧 */
|
||||
|
||||
/* Print the area */
|
||||
printf("Area = %.2f", sqrt(z * (z - s1) * (z - s2) * (z - s3)));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
20
Arithmetic Sum.c
Normal file
20
Arithmetic Sum.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main () {
|
||||
float a1, d; /* Initial Term and Difference */
|
||||
int n; /* Number of Element */
|
||||
|
||||
printf("Enter the initial term (a1): ");
|
||||
scanf("%f", &a1);
|
||||
|
||||
printf("Please enter the difference in the arithmetic sequence: ");
|
||||
scanf("%f", &d);
|
||||
|
||||
printf("Please enter the number of elements the arithmetic sequence: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
printf("The sum of the terms is in the arithmetic sequence is %.2f\n", ((a1 + (a1 + (n - 1) * d)) / 2) * n);
|
||||
|
||||
return 0;
|
||||
}
|
BIN
Binaries/Adding Vectors
Executable file
BIN
Binaries/Adding Vectors
Executable file
Binary file not shown.
BIN
Binaries/After Decimal
Executable file
BIN
Binaries/After Decimal
Executable file
Binary file not shown.
BIN
Binaries/Angle Between Two Vectors
Executable file
BIN
Binaries/Angle Between Two Vectors
Executable file
Binary file not shown.
BIN
Binaries/Area of a Triangle
Executable file
BIN
Binaries/Area of a Triangle
Executable file
Binary file not shown.
BIN
Binaries/Arithmetic Sum
Executable file
BIN
Binaries/Arithmetic Sum
Executable file
Binary file not shown.
BIN
Binaries/Caulculator2
Executable file
BIN
Binaries/Caulculator2
Executable file
Binary file not shown.
BIN
Binaries/Complex to Trig Form
Executable file
BIN
Binaries/Complex to Trig Form
Executable file
Binary file not shown.
BIN
Binaries/Even Or Odd
Executable file
BIN
Binaries/Even Or Odd
Executable file
Binary file not shown.
BIN
Binaries/Fahr-to-Celc
Executable file
BIN
Binaries/Fahr-to-Celc
Executable file
Binary file not shown.
BIN
Binaries/If
Executable file
BIN
Binaries/If
Executable file
Binary file not shown.
BIN
Binaries/Inupt-to-Output
Executable file
BIN
Binaries/Inupt-to-Output
Executable file
Binary file not shown.
BIN
Binaries/Max
Executable file
BIN
Binaries/Max
Executable file
Binary file not shown.
BIN
Binaries/Max Min
Executable file
BIN
Binaries/Max Min
Executable file
Binary file not shown.
BIN
Binaries/Max Min 3 Numbers
Executable file
BIN
Binaries/Max Min 3 Numbers
Executable file
Binary file not shown.
BIN
Binaries/Pointers
Executable file
BIN
Binaries/Pointers
Executable file
Binary file not shown.
BIN
Binaries/Pointers1
Executable file
BIN
Binaries/Pointers1
Executable file
Binary file not shown.
BIN
Binaries/Reverse
Executable file
BIN
Binaries/Reverse
Executable file
Binary file not shown.
BIN
Binaries/Sum Of Three Digit Number
Executable file
BIN
Binaries/Sum Of Three Digit Number
Executable file
Binary file not shown.
BIN
Binaries/ncurses
Executable file
BIN
Binaries/ncurses
Executable file
Binary file not shown.
BIN
Binaries/tetris
Executable file
BIN
Binaries/tetris
Executable file
Binary file not shown.
66
Caulculator2.c
Normal file
66
Caulculator2.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
/* Display a message before the program initiates */
|
||||
printf("Preform an operation on two numbers.\n\n");
|
||||
|
||||
float n1, n2, r; /* Number One, Number Two, and Result */
|
||||
char o; /* Operator */
|
||||
|
||||
/* Prompt the user for the numbers */
|
||||
printf("Enter the first number: ");
|
||||
scanf("%f", &n1);
|
||||
|
||||
printf("Enter the second number: ");
|
||||
scanf("%f", &n2);
|
||||
|
||||
/* Prompt the user for the operator */
|
||||
printf("Enter the operator (+|-|*|/): ");
|
||||
scanf("\n%c", &o);
|
||||
|
||||
|
||||
/* Preform the operation */
|
||||
switch (o) {
|
||||
case '+':
|
||||
r = n1 + n2;
|
||||
|
||||
break;
|
||||
case '-':
|
||||
r = n1 - n2;
|
||||
|
||||
break;
|
||||
case '*':
|
||||
r = n1 * n2;
|
||||
|
||||
break;
|
||||
case '/':
|
||||
/* Sanity Check
|
||||
*
|
||||
* If n2, the second number, equals 0,
|
||||
* exit the program.
|
||||
*/
|
||||
if (n2 == 0) {
|
||||
printf("Error: Cannot devide by 0\n");
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
r = n1 / n2;
|
||||
|
||||
break;
|
||||
/* If the provided value of the operator
|
||||
* is not (+|-|*|/), exit the program.
|
||||
*/
|
||||
default:
|
||||
printf("Error: Invalid argument\n");
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Print the result */
|
||||
printf("Result: %.2f", r);
|
||||
|
||||
return 0;
|
||||
}
|
63
Complex Form To Trig Form.c
Normal file
63
Complex Form To Trig Form.c
Normal file
|
@ -0,0 +1,63 @@
|
|||
/* Complex Form to trig Form
|
||||
*
|
||||
* A prgorgam that converts complex form to trig form
|
||||
* givien 𝑎 and 𝑏.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
int main() {
|
||||
float a, b; /* First Nomial and Coeficient to 𝑖 */
|
||||
|
||||
/* Print formulas */
|
||||
printf("Complex Form --> Trig Form\n");
|
||||
printf("Complex Form: 𝑎 + 𝑏𝑖\n");
|
||||
printf("Trig Form: 𝑟(cosθ + 𝑖sinθ)\n");
|
||||
printf("𝑎, 𝑏 != 0\n");
|
||||
|
||||
/* Prompt user for variables */
|
||||
printf("Enter 𝑎: ");
|
||||
scanf("%f", &a);
|
||||
|
||||
printf("Enter 𝑏: ");
|
||||
scanf("%f", &b);
|
||||
|
||||
/* Sanity Check
|
||||
*
|
||||
* If 𝑎 or 𝑏 equal 0, exit the program.
|
||||
*/
|
||||
if (a == 0 || b == 0) {
|
||||
printf("Error: 𝑎 or 𝑏 cannot = 0\n");
|
||||
|
||||
exit(1);
|
||||
};
|
||||
|
||||
/* Calculate values of additional variables */
|
||||
float r = sqrt(a * a + b * b); /* 𝑟 */
|
||||
float t = atan(b / a); /* θ */
|
||||
|
||||
/* Check for the quadrent of the number,
|
||||
* and add the appropriate value to θ.
|
||||
*
|
||||
* Quadrent I: Add nothing
|
||||
* Quadrent II or III: Add pi
|
||||
* Quadrent IV: Add 2 * pi
|
||||
*/
|
||||
if (a < 0) {
|
||||
/* Add pi */
|
||||
t = t + M_PI;
|
||||
} else {
|
||||
if (b < 0) {
|
||||
/* Add 2 * pi */
|
||||
t = t + 2 * M_PI;
|
||||
}
|
||||
}
|
||||
|
||||
/* Print number in trigonomic form */
|
||||
printf("%.2f(cos(%.2f) + 𝑖sin(%.2f))\n", r, t, t);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
26
Even Or Odd.c
Normal file
26
Even Or Odd.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
int n; /* Number */
|
||||
|
||||
/* Prompt the user */
|
||||
printf("Enter an integer: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
/* Determin whether or not the number is odd */
|
||||
if (n / 2 != n / 2.0) /* Should have used remainder */
|
||||
printf("%d is odd.\n", n);
|
||||
else {
|
||||
printf("%d is not odd.\n", n);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
20
Fahr-to-Celc.c
Normal file
20
Fahr-to-Celc.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#define LOWER 0
|
||||
#define UPPER 300
|
||||
#define STEP 20
|
||||
|
||||
/* Print Fahrenheit-Celcius table
|
||||
for fahr = 0, 20, ..., 300 */
|
||||
main() {
|
||||
float f, c; /* Fahrenheit and Celcuis Temperature */
|
||||
|
||||
/* Heading */
|
||||
printf("Fahrenheit to Celcius\n");
|
||||
|
||||
for (f = UPPER; f >= LOWER; f = f - STEP) {
|
||||
c = 5.0 / 9.0 * (f - 32);
|
||||
printf("%6.1f\t%6.1f\n", f, c);
|
||||
}
|
||||
}
|
||||
|
26
If.c
Normal file
26
If.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
float g; /* Grade */
|
||||
|
||||
/* Prompt the user */
|
||||
printf("Enter the grade in percentage: ");
|
||||
scanf("%f", &g);
|
||||
|
||||
/* Check if grade is > 60% */
|
||||
if (g >= 60)
|
||||
printf("Congratulations, your grade is passing.\n");
|
||||
else {
|
||||
printf("Sorry, try again.");
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
8
Inupt-to-Output.c
Normal file
8
Inupt-to-Output.c
Normal file
|
@ -0,0 +1,8 @@
|
|||
#include <stdio.h>
|
||||
|
||||
main() {
|
||||
int c; /* Character */
|
||||
|
||||
while ((c = getchar()) != EOF)
|
||||
putchar(c);
|
||||
}
|
65
Max Min 3 Numbers.c
Normal file
65
Max Min 3 Numbers.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
float n1, n2, n3; /* Numbers */
|
||||
|
||||
/* Prompt the user */
|
||||
printf("Enter a number: ");
|
||||
scanf("%f", &n1);
|
||||
|
||||
printf("Enter another number: ");
|
||||
scanf("%f", &n2);
|
||||
|
||||
printf("Enter another number: ");
|
||||
scanf("%f", &n3);
|
||||
|
||||
/* Find and print the maximum and minimum numbers
|
||||
*
|
||||
* n1 > n2 > n3
|
||||
*/
|
||||
if (n1 >= n2 && n2 >= n3) {
|
||||
printf("The maximum is %.2f.\n", n1);
|
||||
printf("The minimum is %.2f.\n", n3);
|
||||
|
||||
exit(0);
|
||||
/* n1 > n3 > n2 */
|
||||
} if (n1 >= n3 && n3 > n2) {
|
||||
printf("The maximum is %.2f.\n", n1);
|
||||
printf("The minimum is %.2f.\n", n2);
|
||||
|
||||
exit(0);
|
||||
/* n2 > n1 > n3 */
|
||||
} if (n2 >= n1 && n1 > n3) {
|
||||
printf("The maximum is %.2f.\n", n2);
|
||||
printf("The minimum is %.2f.\n", n3);
|
||||
|
||||
exit(0);
|
||||
/* n2 > n3 > n1 */
|
||||
} if (n2 >= n3 && n3 > n1) {
|
||||
printf("The maximum is %.2f.\n", n2);
|
||||
printf("The minimum is %.2f.\n", n1);
|
||||
|
||||
exit(0);
|
||||
/* n3 > n1 > n2 */
|
||||
} if (n3 >= n1 && n1 > n2) {
|
||||
printf("The maximum is %.2f.\n", n3);
|
||||
printf("The minimum is %.2f.\n", n2);
|
||||
|
||||
exit(0);
|
||||
/* n3 > n2 > n1 */
|
||||
} if (n3 >= n2 && n2 > n1) {
|
||||
printf("The maximum is %.2f.\n", n3);
|
||||
printf("The minimum is %.2f.\n", n1);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
29
Max Min.c
Normal file
29
Max Min.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
float n1, n2; /* Numbers */
|
||||
|
||||
/* Prompt the user */
|
||||
printf("Enter a number: ");
|
||||
scanf("%f", &n1);
|
||||
|
||||
printf("Enter another number: ");
|
||||
scanf("%f", &n2);
|
||||
|
||||
/* Find and print the maximum and minimum numbers */
|
||||
if (n1 >= n2) {
|
||||
printf("The maximum is %.2f.\n", n1);
|
||||
printf("The minimum is %.2f.\n", n2);
|
||||
} else {
|
||||
printf("The maximum is %.2f.\n", n2);
|
||||
printf("The minimum is %.2f.\n", n1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
26
Max.c
Normal file
26
Max.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
float n1, n2; /* Numbers */
|
||||
|
||||
/* Prompt the user */
|
||||
printf("Enter a number: ");
|
||||
scanf("%f", &n1);
|
||||
|
||||
printf("Enter another number: ");
|
||||
scanf("%f", &n2);
|
||||
|
||||
/* Find and print the maximum number */
|
||||
if (n1 >= n2)
|
||||
printf("The maximum is %.2f.\n", n1);
|
||||
else
|
||||
printf("The maximum is %.2f.\n", n2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
1
Playground/intro-pointers
Submodule
1
Playground/intro-pointers
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 2847f8b921dbbc772a2f13490af95bb8dc9b202a
|
20
Pointers.c
Normal file
20
Pointers.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* Program 2.1 from PTRTUT10.HTM 6/13/97 */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int my_array[] = {1,23,17,4,-5,100};
|
||||
int *ptr;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
ptr = my_array; /* point our pointer to the first
|
||||
element of the array */
|
||||
printf("\n\n");
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
printf("my_array[%d] = %d ",i,my_array[i]); /*<-- A */
|
||||
printf("ptr + %d = %d\n",i, *(++ptr));
|
||||
}
|
||||
return 0;
|
||||
}
|
20
Pointers1.c
Normal file
20
Pointers1.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* Program 1.1 from PTRTUT10.TXT 6/10/97 */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int j, k;
|
||||
int *ptr;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
j = 1;
|
||||
k = 2;
|
||||
ptr = &k;
|
||||
printf("\n");
|
||||
printf("j has the value %d and is stored at %p\n", j, (void *)&j);
|
||||
printf("k has the value %d and is stored at %p\n", k, (void *)&k);
|
||||
printf("ptr has the value %p and is stored at %p\n", ptr, (void *)&ptr);
|
||||
printf("The value of the integer pointed to by ptr is %d\n", *ptr);
|
||||
|
||||
return 0;
|
||||
}
|
20
Reverse.c
Normal file
20
Reverse.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main() {
|
||||
int n; /* Number to Be Reversed */
|
||||
|
||||
/* Prompt for number */
|
||||
printf("Enter a 3 digit integer: ");
|
||||
scanf("%d", &n);
|
||||
|
||||
/* Define the digits */
|
||||
int d1 = n / 100;
|
||||
int d2 = (int)(n / 10) - d1 * 10;
|
||||
int d3 = n - (d1 * 100 + d2 * 10);
|
||||
|
||||
/* Print the digits in reverse */
|
||||
printf("Reverse of digits: %d%d%d\n", d3, d2, d1);
|
||||
|
||||
return 0;
|
||||
}
|
21
Sum Of Three Digit Number.c
Normal file
21
Sum Of Three Digit Number.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main () {
|
||||
int tdn; /* Three Digit Number */
|
||||
|
||||
printf("Enter a three digit number: ");
|
||||
scanf("%d", &tdn);
|
||||
|
||||
int d1 = tdn / 100;
|
||||
int d2 = (int)(tdn / 10) - d1 * 10;
|
||||
int d3 = tdn - (d1 * 100 + d2 * 10);
|
||||
|
||||
printf("digit 1: %d\n", d1);
|
||||
printf("digit 2: %d\n", d2);
|
||||
printf("digit 3: %d\n", d3);
|
||||
|
||||
printf("The sum of the digits is %d\n", d1 + d2 + d3);
|
||||
|
||||
return 0;
|
||||
}
|
20
ncurses.c
Normal file
20
ncurses.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <curses.h>
|
||||
|
||||
int main() {
|
||||
initscr();
|
||||
cbreak();
|
||||
noecho();
|
||||
|
||||
int x = 40;
|
||||
int y = 60;
|
||||
char ch = 'x';
|
||||
mvaddch(x, y, ch);
|
||||
|
||||
getch();
|
||||
endwin();
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
Loading…
Reference in a new issue