C
This commit is contained in:
11
DeitelC/Chapter3/1to10Sum.c
Normal file
11
DeitelC/Chapter3/1to10Sum.c
Normal file
@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int x = 1;
|
||||
int sum = 0;
|
||||
while (x < 11) {
|
||||
sum += x;
|
||||
printf("%d\n", sum);
|
||||
x++;
|
||||
}
|
||||
}
|
15
DeitelC/Chapter3/3over10factoriel.c
Normal file
15
DeitelC/Chapter3/3over10factoriel.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int x;
|
||||
int i = 1;
|
||||
int total = 0;
|
||||
|
||||
while (i <= 10) {
|
||||
x = i * i * i;
|
||||
total += x;
|
||||
i++;
|
||||
}
|
||||
|
||||
printf("%d", total);
|
||||
}
|
20
DeitelC/Chapter3/ArmstrongNumbers.c
Normal file
20
DeitelC/Chapter3/ArmstrongNumbers.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void){
|
||||
int a = 1;
|
||||
int b = 0;
|
||||
int c = 0;
|
||||
int d;
|
||||
|
||||
for(a = 1; a <= 9; a++){
|
||||
for(b = 0; b <= 9; b++){
|
||||
for(c = 0; c <= 9; c++) {
|
||||
d = (100*a)+(10*b)+c;
|
||||
if(d == (a*a*a)+(b*b*b)+(c*c*c)) {
|
||||
printf("%d\n", d);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
29
DeitelC/Chapter3/BinaryToDecimal.c
Normal file
29
DeitelC/Chapter3/BinaryToDecimal.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void){
|
||||
int a;
|
||||
int b;
|
||||
int c = 1;
|
||||
int d;
|
||||
int e = 2;
|
||||
printf("Enter binary!(5 or less!)\n");
|
||||
scanf("%d", &a);
|
||||
while (a > 0) {
|
||||
b = a % 10;
|
||||
if (b > 0 && c == 1) {
|
||||
d = b;
|
||||
a /= 10;
|
||||
c++;
|
||||
|
||||
} else if (b > 0 && c != 1) {
|
||||
d += e*b;
|
||||
e *=2;
|
||||
a/=10;
|
||||
c++;
|
||||
} else {
|
||||
e *=2;
|
||||
a/=10;
|
||||
}
|
||||
}
|
||||
printf("%d\n", d);
|
||||
}
|
24
DeitelC/Chapter3/BonusInstructor.c
Normal file
24
DeitelC/Chapter3/BonusInstructor.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int total = 0;
|
||||
int grade = 0;
|
||||
int pass = 0;
|
||||
int fail = 0;
|
||||
|
||||
while(total < 10) {
|
||||
printf("%s","Enter grade (grades must be 1 or 2 !) ");
|
||||
scanf("%d", &grade);
|
||||
if(grade == 1) {
|
||||
fail = fail + 1;
|
||||
total = total + 1;
|
||||
} else if(grade == 2) {
|
||||
pass = pass + 1;
|
||||
total = total + 1;
|
||||
} else {
|
||||
printf("%s\n","Invalid Number PLEASE ENTER A VALID NUMBER!(1 or 2)");
|
||||
scanf("%d", &grade);
|
||||
}
|
||||
}
|
||||
puts((pass >= 8) ? "Bonus to Instructer!" : "");
|
||||
}
|
30
DeitelC/Chapter3/CheckConstantEOverX.c
Normal file
30
DeitelC/Chapter3/CheckConstantEOverX.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
|
||||
double powerFun(double base, int exponent) {
|
||||
double result = 1.0;
|
||||
for (int i = 0; i < exponent; i++) {
|
||||
result *= base;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int userData;
|
||||
printf("Please Enter x (in E^x): ");
|
||||
scanf("%d", &userData);
|
||||
|
||||
double constant = 2.0; // Initialize constant as a double
|
||||
double counter = 1.0; // Initialize counter to 1.0
|
||||
double data = 1.0; // Initialize data to 1.0
|
||||
|
||||
for (int i = 1; i <= userData; i++) {
|
||||
data *= constant; // Update data by multiplying with constant
|
||||
double term = powerFun(userData, i) / data; // Calculate the term for the current iteration
|
||||
counter += term; // Add the term to the counter
|
||||
printf("counter: %f\n", counter);
|
||||
}
|
||||
|
||||
printf("e^%d = %f\n", userData, counter);
|
||||
|
||||
return 0;
|
||||
}
|
24
DeitelC/Chapter3/CheckerboardPattern.c
Normal file
24
DeitelC/Chapter3/CheckerboardPattern.c
Normal file
@ -0,0 +1,24 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int a = 1;
|
||||
int b = 1;
|
||||
for(a=1;a<9;a++) {
|
||||
if (a % 2 == 1) {
|
||||
while (b <= 8) {
|
||||
printf("%s","* ");
|
||||
b++;
|
||||
}
|
||||
printf("\n");
|
||||
b = 0;
|
||||
} else {
|
||||
while(b <= 8) {
|
||||
printf("%s", " *");
|
||||
b++;
|
||||
}
|
||||
printf("\n");
|
||||
b = 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
12
DeitelC/Chapter3/Circle.c
Normal file
12
DeitelC/Chapter3/Circle.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
float pi = 3.14159;
|
||||
double r;
|
||||
printf("%s\n", "Enter radius of Circle!: ");
|
||||
scanf("%lf", &r);
|
||||
printf("%s %lf\n", "The Diameter of Circle!: ", 2*r);
|
||||
printf("%s %lf\n", "The Circumference of Circle: ", 2*pi*r);
|
||||
printf("%s %lf\n", "The Area of Circle: ", pi*(r*r));
|
||||
|
||||
}
|
31
DeitelC/Chapter3/ClassAvarage.c
Normal file
31
DeitelC/Chapter3/ClassAvarage.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int total = 0;
|
||||
int counter = 0;
|
||||
|
||||
printf("%s","Enter grades!, -1 to End: ");
|
||||
int grade = 0;
|
||||
scanf("%d", &grade);
|
||||
while(grade != -1) {
|
||||
total = total + grade;
|
||||
counter = counter + 1;
|
||||
|
||||
printf("%s", "Enter grades!, -1 to End: ");
|
||||
scanf("%d", &grade);
|
||||
}
|
||||
|
||||
if (counter != 0) {
|
||||
|
||||
double avarage = (double) total / counter;
|
||||
|
||||
printf("Class average is %.2f\n", avarage);
|
||||
printf("%d ", total);
|
||||
printf("%d ", counter);
|
||||
printf("%.0f", avarage);
|
||||
|
||||
|
||||
} else {
|
||||
puts("Enter a valid number!");
|
||||
}
|
||||
}
|
15
DeitelC/Chapter3/ConditionalExpression.c
Normal file
15
DeitelC/Chapter3/ConditionalExpression.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int grade;
|
||||
printf("%s\n", "Enter your grade!");
|
||||
scanf("%d", &grade);
|
||||
if (grade >= 60) {
|
||||
printf("%s\n", "You passed!");
|
||||
|
||||
} else {
|
||||
printf("%s\n", "You failed!");
|
||||
printf("%d\n", grade);
|
||||
}
|
||||
printf((grade <= 60) ? "Fail" : "Passed");
|
||||
}
|
17
DeitelC/Chapter3/ConstantE.c
Normal file
17
DeitelC/Chapter3/ConstantE.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
float constant = 2;
|
||||
float counter = 2;
|
||||
float data = 1;
|
||||
float check = 1;
|
||||
while(constant <= 40) {;
|
||||
data = constant * data;
|
||||
check = 1/data;
|
||||
counter = check + counter;
|
||||
printf("%s %f\n","counter :", counter);
|
||||
|
||||
constant++;
|
||||
}
|
||||
return 0;
|
||||
}
|
30
DeitelC/Chapter3/ConstantEOverX.c
Normal file
30
DeitelC/Chapter3/ConstantEOverX.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdio.h>
|
||||
int powerFun(int userData, int i) {
|
||||
float result = 1.0;
|
||||
while (i > 0) {
|
||||
result *= userData;
|
||||
i--;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
double constant = 2;
|
||||
double counter = 2;
|
||||
double data = 1;
|
||||
float check = 1;
|
||||
int userData;
|
||||
int i = 1;
|
||||
printf("%s\n","Please Enter x (in E^x): ");
|
||||
scanf("%d", &userData);
|
||||
while(i <= userData) {
|
||||
data = constant * data;
|
||||
check = powerFun(userData, i)/data;
|
||||
counter = check + counter;
|
||||
printf("%s %f\n","counter :", counter);
|
||||
printf("%s %d\n","PowerFun:", powerFun(userData, i));
|
||||
i++;
|
||||
constant++;
|
||||
}
|
||||
return 0;
|
||||
}
|
21
DeitelC/Chapter3/Factoriel.c
Normal file
21
DeitelC/Chapter3/Factoriel.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int userData;
|
||||
int counter;
|
||||
int data = 1;
|
||||
puts("Please enter factoriel number !: ");
|
||||
scanf("%d",&userData);
|
||||
|
||||
while(userData > 1) {
|
||||
if (userData == 0) {
|
||||
puts("0! = 1!\n");
|
||||
} else if (userData > 0) {
|
||||
printf("%s %d\n","UserData while", userData);
|
||||
data = userData * data;
|
||||
printf("%s %d\n","data while", data);
|
||||
|
||||
userData--;
|
||||
}
|
||||
}
|
||||
}
|
20
DeitelC/Chapter3/FloydsTriangle.c
Normal file
20
DeitelC/Chapter3/FloydsTriangle.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
int a = 1;
|
||||
int b = 1;
|
||||
int i = 1;
|
||||
|
||||
while(a < 11) {
|
||||
while(b <= a) {
|
||||
printf("%d\t",i);
|
||||
i++;
|
||||
b++;
|
||||
}
|
||||
printf("\n");
|
||||
b = 1;
|
||||
a++;
|
||||
|
||||
}
|
||||
}
|
9
DeitelC/Chapter3/HelloPrint.c
Normal file
9
DeitelC/Chapter3/HelloPrint.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void HelloWorld(char print[]) {
|
||||
printf("%s\n", print);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
HelloWorld("print");
|
||||
}
|
41
DeitelC/Chapter3/HollowSquareOfAsteriks.c
Normal file
41
DeitelC/Chapter3/HollowSquareOfAsteriks.c
Normal file
@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void){
|
||||
int a = 0;
|
||||
int b = 1;
|
||||
int c = 1;
|
||||
|
||||
printf("%s\n","Enter side of asteriks!");
|
||||
scanf("%d", &a);
|
||||
|
||||
while(b == 1) {
|
||||
while(c <= a) {
|
||||
printf("*");
|
||||
c++;
|
||||
}
|
||||
printf("\n");
|
||||
c = 1;
|
||||
b++;
|
||||
}
|
||||
while(b > 1 && b < a) {
|
||||
printf("*");
|
||||
while(c < a) {
|
||||
printf(" ");
|
||||
c++;
|
||||
}
|
||||
printf("*\n");
|
||||
c = 1;
|
||||
b++;
|
||||
}
|
||||
while(b == a) {
|
||||
while(c <= a) {
|
||||
printf("*");
|
||||
c++;
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
c = 1;
|
||||
b++;
|
||||
}
|
||||
return 0;
|
||||
}
|
21
DeitelC/Chapter3/HowMany9.c
Normal file
21
DeitelC/Chapter3/HowMany9.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void){
|
||||
int counter = 0;
|
||||
int data = 0;
|
||||
int nine = 9;
|
||||
int lastData;
|
||||
|
||||
printf("Enter integer!: ");
|
||||
scanf("%d", &data);
|
||||
while(data > 0){
|
||||
lastData = data % 10;
|
||||
if (lastData == 9) {
|
||||
counter++;
|
||||
data /= 10;
|
||||
} else {
|
||||
data /= 10;
|
||||
}
|
||||
}
|
||||
printf("%d\n", counter);
|
||||
}
|
28
DeitelC/Chapter3/IsPrime.c
Normal file
28
DeitelC/Chapter3/IsPrime.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void isPrime(int number) {
|
||||
int a = 1;
|
||||
int count = 0;
|
||||
|
||||
while (a < number) {
|
||||
if(number%a == 0) {
|
||||
count += 1;
|
||||
a++;
|
||||
} else {
|
||||
a++;
|
||||
}
|
||||
}
|
||||
|
||||
if(count == 1) {
|
||||
printf("%s\n", "Yes it's a Prime");
|
||||
|
||||
} else {
|
||||
printf("%s\n", "No it isn't a Prime");
|
||||
}
|
||||
}
|
||||
int main(void) {
|
||||
int number;
|
||||
printf("%s\n", "Enter a integer!");
|
||||
scanf("%d", &number);
|
||||
isPrime(number);
|
||||
}
|
28
DeitelC/Chapter3/LargestNum.c
Normal file
28
DeitelC/Chapter3/LargestNum.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
int main(void) {
|
||||
int number = 0;
|
||||
int counter = 1;
|
||||
int largest = 0;
|
||||
printf("%s\n","Enter 10 positive Integer");
|
||||
scanf("%d", &number);
|
||||
|
||||
while(counter < 10) {
|
||||
printf("%s\n","Enter 10 positive Integer");
|
||||
scanf("%d", &number);
|
||||
|
||||
if(number >= largest) {
|
||||
largest = number;
|
||||
++counter;
|
||||
} else {
|
||||
++counter;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
printf("%s %d\n", "Counter: ",counter);
|
||||
printf("%s %d\n", "Largest: ",largest);
|
||||
printf("%s %d\n", "Number: ",number);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
9
DeitelC/Chapter3/MultiplesOf3WithAnInfiniteLoop.c
Normal file
9
DeitelC/Chapter3/MultiplesOf3WithAnInfiniteLoop.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int three = 3;
|
||||
while (three > 0) {
|
||||
printf("%d\n", three);
|
||||
three *= 3;
|
||||
}
|
||||
}
|
15
DeitelC/Chapter3/MultiplesOfNumber.c
Normal file
15
DeitelC/Chapter3/MultiplesOfNumber.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void){
|
||||
int dollar = 0;
|
||||
for(dollar = 0; dollar < 500; dollar++) {
|
||||
if (dollar % 50 == 0) {
|
||||
printf("\n");
|
||||
printf("$ ");
|
||||
dollar++;
|
||||
} else {
|
||||
printf("$ ");
|
||||
dollar++;
|
||||
}
|
||||
}
|
||||
}
|
5
DeitelC/Chapter3/PseudocodeBonusInstructor.md
Normal file
5
DeitelC/Chapter3/PseudocodeBonusInstructor.md
Normal file
@ -0,0 +1,5 @@
|
||||
1- 10 results must entered!
|
||||
2- Each number 1 or 2 if number none of this than program only checks number = 1 if is not than program thinks
|
||||
it's 2
|
||||
3- Two counters are used one to count the number of students who passed and failed.
|
||||
4- After the results, if 8 students passed the exam and, if so, print "Bonus to Instructer!"
|
5
DeitelC/Chapter3/PsudocodeLargestNum.md
Normal file
5
DeitelC/Chapter3/PsudocodeLargestNum.md
Normal file
@ -0,0 +1,5 @@
|
||||
1- Enter positive 10 integer
|
||||
2- Create 3 different variable counter, number, largest
|
||||
3- Counter checks 10 different num
|
||||
4- number dynamicly changes(uses scanf)
|
||||
5- largest hold biggest number
|
55
DeitelC/Chapter3/RightTriangle.c
Normal file
55
DeitelC/Chapter3/RightTriangle.c
Normal file
@ -0,0 +1,55 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int MaxValue(int number1, int number2, int number3) {
|
||||
int largest = 0;
|
||||
if (number1 <= number2) {
|
||||
largest = number2;
|
||||
} else {
|
||||
largest = number1;
|
||||
}
|
||||
|
||||
if (largest <= number3) {
|
||||
largest = number3;
|
||||
}
|
||||
return largest;
|
||||
}
|
||||
|
||||
void Least(int number4, int number5, int number6, int *Least1, int *Least2) {
|
||||
if (number4 <= number5) {
|
||||
*Least1 = number4;
|
||||
} else {
|
||||
*Least1 = number5;
|
||||
}
|
||||
|
||||
if(number5 <= number6) {
|
||||
*Least2 = number5;
|
||||
} else {
|
||||
*Least2 = number6;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int d;
|
||||
int Least3;
|
||||
int Least4;
|
||||
|
||||
printf("%s\n","Enter first value of Right Triangle!");
|
||||
scanf("%d", &a);
|
||||
printf("%s\n","Enter second value of Right Triangle!");
|
||||
scanf("%d", &b);
|
||||
printf("%s\n","Enter last value of Right Triangle!");
|
||||
scanf("%d", &c);
|
||||
|
||||
d = MaxValue(a,b,c);
|
||||
Least(a,b,c,&Least3,&Least4);
|
||||
if((d*d) == (Least3*Least3)+(Least4*Least4)) {
|
||||
printf("%s\n", "Yes this triangle is a right triangle!");
|
||||
} else {
|
||||
printf("%s\n", "No");
|
||||
}
|
||||
printf("%d\n", d);
|
||||
printf("%d %d\n", Least3, Least4);
|
||||
}
|
46
DeitelC/Chapter3/Salary.c
Normal file
46
DeitelC/Chapter3/Salary.c
Normal file
@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
int main(void) {
|
||||
printf("%s\n", "Enter # of hours worked (-1 to End):");
|
||||
int hours;
|
||||
scanf("%d", &hours);
|
||||
if (hours == -1) {
|
||||
return 0;
|
||||
};
|
||||
printf("%s\n","Enter hourly rate of the worker ($00.00):");
|
||||
float hourly;
|
||||
scanf("%f", &hourly);
|
||||
|
||||
if(hours <= 40) {
|
||||
while(hours != -1){
|
||||
printf("%s %.2f\n", "Salary is: ", hourly*hours);
|
||||
printf("%s\n", "Enter # of hours worked (-1 to End):");
|
||||
scanf("%d", &hours);
|
||||
if (hours == -1) {
|
||||
return 0;
|
||||
};
|
||||
printf("%s\n","Enter hourly rate of the worker ($00.00):");
|
||||
scanf("%f", &hourly);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (hours > 40) {
|
||||
while(hours != -1) {
|
||||
float OneHalf = ((hours - 40)*hourly)*(1,5);
|
||||
printf("%s %.2f\n", "Salary is :", 400+OneHalf);
|
||||
printf("%s\n", "Enter # of hours worked (-1 to End):");
|
||||
scanf("%d", &hours);
|
||||
if (hours == -1) {
|
||||
return 0;
|
||||
}
|
||||
printf("%s\n","Enter hourly rate of the worker ($00.00):");
|
||||
scanf("%f", &hourly);
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
16
DeitelC/Chapter3/SalesCommision.c
Normal file
16
DeitelC/Chapter3/SalesCommision.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
|
||||
printf("%s\n", "Enter sales in dollars (-1 to end):");
|
||||
float sale;
|
||||
scanf("%f", &sale);
|
||||
|
||||
while (sale != -1) {
|
||||
printf("%s %.2f\n", "Salary is:", ((sale*9)/100)+200);
|
||||
printf("%s\n", "Enter sales in dollars (-1 to end):");
|
||||
scanf("%f", &sale);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
26
DeitelC/Chapter3/SalesTax.c
Normal file
26
DeitelC/Chapter3/SalesTax.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
float monthTotal;
|
||||
float total;
|
||||
char month[20];
|
||||
|
||||
printf("%s\n", "Enter total amounth collected (-1 to stop!):");
|
||||
scanf("%f", &monthTotal);
|
||||
|
||||
while (monthTotal != -1) {
|
||||
total += monthTotal;
|
||||
printf("%s %.2f\n", "Current Total", total);
|
||||
printf("%s\n", "Enter total amounth collected (-1 to stop!):");
|
||||
scanf("%f", &monthTotal);
|
||||
}
|
||||
printf("%s\n", "Enter name of month:");
|
||||
scanf("%s", month);
|
||||
printf("The Month: %s\n",month);
|
||||
printf("%s %.2f\n", "Total Collections:", total);
|
||||
printf("%s %.2f\n", "Sales:", (total*91)/100);
|
||||
printf("%s %.2f\n", "County Sales Tax:", (total*5)/100);
|
||||
printf("%s %.2f\n", "State Sales Tax:", (total*4)/100);
|
||||
printf("%s %.2f\n", "Total Sales Tax Collected:", (total*9)/100);
|
||||
|
||||
}
|
43
DeitelC/Chapter3/SideOfATriangle.c
Normal file
43
DeitelC/Chapter3/SideOfATriangle.c
Normal file
@ -0,0 +1,43 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int AbsoluteValue(int number) {
|
||||
if (number < 0) {
|
||||
number *= -1;
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int check = 0;
|
||||
printf("%s\n", "Enter sides of Triangle! (Enter first value!): ");
|
||||
scanf("%d", &a);
|
||||
printf("%s\n", "Enter sides of Triangle! (Enter second value!): ");
|
||||
scanf("%d", &b);
|
||||
printf("%s\n", "Enter sides of Triangle! (Enter last value!): ");
|
||||
scanf("%d", &c);
|
||||
|
||||
|
||||
if(AbsoluteValue(b-a) < c && c < a+b) {
|
||||
check++;
|
||||
} else {
|
||||
printf("%s\n", "Check 1 NOT COMPLETED!");
|
||||
}
|
||||
if(AbsoluteValue(c-a)< b && b < c+a) {
|
||||
check++;
|
||||
} else {
|
||||
printf("%s\n", "Check 2 NOT COMPLETED!");
|
||||
}
|
||||
if(AbsoluteValue(c-b)< a && a < c+b) {
|
||||
check++;
|
||||
} else {
|
||||
printf("%s\n", "Check 3 NOT COMPLETED!");
|
||||
}
|
||||
if(check == 3) {
|
||||
printf("%s\n", "Yes this is a triangle!");
|
||||
} else {
|
||||
printf("%s\n", "No");
|
||||
}
|
||||
}
|
21
DeitelC/Chapter3/SquareOfAsteriks.c
Normal file
21
DeitelC/Chapter3/SquareOfAsteriks.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void){
|
||||
int a = 0;
|
||||
int b = 1;
|
||||
int c = 1;
|
||||
|
||||
printf("%s\n","Enter side of asteriks!");
|
||||
scanf("%d", &a);
|
||||
|
||||
while(b <= a) {
|
||||
while(c <= a) {
|
||||
printf("*");
|
||||
c++;
|
||||
}
|
||||
printf("\n");
|
||||
c = 1;
|
||||
b++;
|
||||
}
|
||||
return 0;
|
||||
}
|
17
DeitelC/Chapter3/TabularOutput.c
Normal file
17
DeitelC/Chapter3/TabularOutput.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int a = 7;
|
||||
|
||||
while(a <= 35) {
|
||||
printf("%d\t", a);
|
||||
printf("%d\t", a+3);
|
||||
printf("%d\t", a+6);
|
||||
printf("%d\n", a*9);
|
||||
a+=7;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
17
DeitelC/Chapter3/TabularOutputPower.c
Normal file
17
DeitelC/Chapter3/TabularOutputPower.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int a = 1;
|
||||
|
||||
while(a <= 10) {
|
||||
printf("%d\t", a);
|
||||
printf("%d\t", a*a);
|
||||
printf("%d\t", a*a*a);
|
||||
printf("%d\n", a*a*a*a);
|
||||
a++;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
27
DeitelC/Chapter3/TwoLargestNumber.c
Normal file
27
DeitelC/Chapter3/TwoLargestNumber.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
int main(void) {
|
||||
int number = 0;
|
||||
int counter = 1;
|
||||
int largest = 0;
|
||||
int SecondLargest = 0;
|
||||
|
||||
while(counter <= 10) {
|
||||
printf("%s\n","Enter 10 positive Integer");
|
||||
scanf("%d", &number);
|
||||
if(number >= largest) {
|
||||
SecondLargest = largest;
|
||||
largest = number;
|
||||
} else if (number > SecondLargest && number != SecondLargest){
|
||||
SecondLargest = number;
|
||||
} counter++;
|
||||
|
||||
}
|
||||
|
||||
printf("%s %d\n", "Counter: ",counter);
|
||||
printf("%s %d\n", "Largest: ",largest);
|
||||
printf("%s %d\n", "SecondLargest: ",SecondLargest);
|
||||
printf("%s %d\n", "Number: ",number);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
22
DeitelC/Chapter3/XPowerY.c
Normal file
22
DeitelC/Chapter3/XPowerY.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int x;
|
||||
int y;
|
||||
|
||||
printf("%s\n","Please Enter a X value!");
|
||||
scanf("%d", &x);
|
||||
printf("%s\n", "Please Enter a Y value!");
|
||||
scanf("%d", &y);
|
||||
|
||||
int i = 1;
|
||||
int power = 1;
|
||||
|
||||
while (i <= y) {
|
||||
power *= x;
|
||||
i++;
|
||||
}
|
||||
|
||||
printf("%s %d", "Variable output:", power);
|
||||
|
||||
}
|
BIN
DeitelC/Chapter3/a.exe
Normal file
BIN
DeitelC/Chapter3/a.exe
Normal file
Binary file not shown.
15
DeitelC/Chapter3/test1.c
Normal file
15
DeitelC/Chapter3/test1.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main( void )
|
||||
{
|
||||
int outer_count = 1; // initialize count
|
||||
while ( outer_count <= 10 ) { // loop 10 times
|
||||
int inner_count = 1;
|
||||
while (inner_count <= outer_count) {
|
||||
printf("* ");
|
||||
inner_count++;
|
||||
} // end inner while
|
||||
printf("\n");
|
||||
outer_count++;
|
||||
} // end outer while
|
||||
} // end main
|
9
DeitelC/Chapter3/test2.c
Normal file
9
DeitelC/Chapter3/test2.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
int i = 4;
|
||||
int a = 3;
|
||||
|
||||
(i > 3) ? printf("Yes") : printf("No");
|
||||
|
||||
}
|
Reference in New Issue
Block a user