C programming language

Anonymous
timer Asked: Feb 18th, 2019
account_balance_wallet $40

Question Description

please solve the questions on the homework sheet using only C language ( 7 questions) .

Any other language will not be accepted.

Please give me all the C files.

for problems 1 and 3, you need to write a pusodo code.

I am attaching multiple lectures which should help solving the problems.


Attachment preview

1. Create a script that will take user input of 3 vertices to calculate the area of a triangle by using Heron’ Formula. You will need the “pow” function in “math.h” header file.

Your output should have the format of

-With the given vertices (Display Vertices) the area of the triangle is (The result.)  

2. Create a script that will solve a set of simultaneous equations.


1. Create a script that will take user input of 3 vertices to calculate the area of a triangle by using Heron’ Formula. You will need the “pow” function in “math.h” header file. Your output should have the format of -With the given vertices (Display Vertices) the area of the triangle is (The result.) 2. Create a script that will solve a set of simultaneous equations. a, b, c, d, e, and f are user input. Your script should be able to calculate x and y. Also the script should ask the user whether he /she would like to continue on finding answers for other equations and then continue on with the answer “Y”. Your output should have the format of -With given values of “a”, “b”, “c”, “d”, “e”, and “f”, the answer for x is “Answer” and y is “Answer” 3. Create a script that will find the roots of quadratic equations “x2+3.8x+3.25=0” by using continuously changing the value of x within a certain range (I.E: -10<=x<=10. ) 4. Create a script that will find the sum of the all multiples of 3 between two user input integers by using For Loop. 5. Create a script that will find all the prime numbers between user input integers. 6. Create a script with if, else if, and else conditionals to calculate the Total Resistance (R_T) 1) r1 , r2, and r3 are connected in series manner. (R_T= r1+r2+r3) 2) r1, r2, and r3 are connected in parallel manner.(R_T = 1/((1/r1)+(1/r2)+(1/r3)) ) 3) r1 is connected to the parallelly connected r2 and r3 in series manner. (Let’s call this Combination) (R_T = r1 + r2xr3/(r2+r3) ) The output should be What is the resistance of R1? [You type in the value] What is the resistance of R2? [You type in the value] What is the resistance of R3? [You type in the value] What kind of combination result are you looking for? [You type in S, P, or C] The Total Resistance is [your result] ohms since r1, r2, r3 are connected in [series, parallel, combination] manner. Test the result with r1 = 10 Ω, r2 = 20 Ω, and r3 = 30 Ω. 7. Repeat problem 6. This time use “switch”. * Do some reading on issues with scanf() when we have multiple user input Grading: Problems 1 and 3 (2 Points – 1.50 Actual Scripts 0.5 Pseudo Codes) Try to make Pseudo Code as detailed as possible Problems 4,5,,6,7 (1 Points Each Scripts)
Computer Programming Input and Output Retrieving a Single Character • getchar() • Inputting a single Character • This is where getchar() function shines. char gender; gender = getchar(); Code #include //*Sabbath_Day.c*/ int main(void){ char Religion;//Single charactor to store [C]hristianity, [I]slam, [J]udaism, [B]uddism, [A]theist printf("What is your religion?\n Please make a choice \n [C]hristianity, [I]slam, [J]udaism, [B]uddism, [A]theist\n"); Religion = getchar(); switch (Religion) {//This Switch conditional loop will make a decision based on Religion. case 'C': case'c': printf("Do not come to work on Sundays.\n"); break; case 'I': case 'i': printf("Do not come to work on Fridays. \n"); break; case 'J': case 'j': printf("Do not come to work on Saturdays. \n"); break; case 'B': case 'b': case 'A': case 'a': printf("Feel free to choose any day of the week. \n"); break; } // End of switch. getchar(); //Pause for the user to press Enter getchar(); //To make it clear the computer will not close the window. return 0;} What Happens Here? 01 02 03 char Religion;/*Single charactor to store [C]hristianity, [I]slam, [J]udaism, [B]uddism, [A]theist*/ printf("What is your religion?\n Please make a choice \n [C]hristianity, [I]slam, [J]udaism, [B]uddism, [A]theist\n"); getchar(); //Pause for the user to press Enter getchar(); /*To make it clear the computer will not close the window. */ return 0;} Code Religion = getchar(); switch (Religion) {//This Switch conditional loop will make a decision based on Religion. case 'C': case'c': printf("Do not come to work on Sundays.\n"); break; case 'I': case 'i': printf("Do not come to work on Fridays. \n"); break; case 'J': case 'j': printf("Do not come to work on Saturdays. \n"); break; case 'B': case 'b': case 'A': case 'a': printf("Feel free to choose any day of the week. \n"); break; }
Retrieving Whole Word Input • We cannot go far with single character. • Use scanf() function, then. scanf() reads what has been typed into the keyboard and converts it to a particular data type, based on the formatting code given to it. • scanf() is part of stdio.h char word[20]; printf(“Please enter a word: “); scanf(“%s”, word) %c: Single Character %d: Integer %f: Float %s: String %u: Unsigned Integer Cumbersome Parts of scanf() • When %s is used, the function will only read up until the first whitespace character (a space, a tab, or a new line). In other words, it can read only a single word at a time. • If the function encounters input that does not match the formatting signifier, scanf() will not work. It will returns a value, namely the number of items it read in. If nothing was read, it will return a value of 0 or EOF (end of file) or -1 (numeric equivalent of EOF) Cumbersome Parts of scanf() Xibrubyws • You should definitely add the maximum field width parameters to your signifier. This value, which should match the lengh of the variable to which the input is assigned, dictates the maximum number of characters to be read. scanf(“%19s”, word); • If you want to use scanf() for other than a string (an integer or other nonstring value) you must pass the address of the variable to the scanf() function by using ampersand– Will be covered in later modules. scanf(“%d”, &number); Try This Script with Different Names //First_Name.c #include int main(void){ char superhero_name[10];//Character String // Get the Superheor’s name and use it in a sentence. printf("Enter your first name: "); scanf("%9s", first_name); printf("Thanks, %s, \n", first_name); getchar(); getchar(); return 0; } CaptainAmerica BlackPanther Ironman
Numeric Input • Use scanf() function – Still used but not best solution int age: printf(“Enter your age: “); scanf(“%d”, &age); • Use fgets() and sscanf() instead / REVISIT Soon! Code #include main() { // Set up the variables that scanf will fill char firstInitial; char lastInitial; int age; int favorite_number; printf("What letter does your first name begin with?\n"); scanf(" %c", &firstInitial); printf("What letter does your last name begin with?\n"); scanf(" %c", &lastInitial); printf("How old are you?\n"); scanf(" %d", &age); printf("What is your favorite number (integer only)?\n"); scanf(" %d", &favorite_number); printf("\nYour intitials are %c.%c. and you are %d years old", firstInitial, lastInitial, age); printf("\nYour favorite number is %d.\n\n", favorite_number); return 0; } Numeric Input • Each scanf() is partnered with a printf() statement to let the user know what to type. • The first two scanf() statements obtain character values (as you can tell from the %c conversion codes). • The third scanf() gets an integer value from the keyboard and places it into a variable named age. The variables firstInitial, lastInitial, and age will hold whatever the user types before pressing Enter. If the user types more than a single character in the first two examples, it can confuse the program and create problems for the later values. Changing the Previous Example /*Finding the sum of all integers between two integers chosen by user*/ #include int main(void){ unsigned int unsigned int printf("What scanf(" %d", printf("What scanf(" %d", num1, num2, i; result=0; number would you like to start with?\n"); &num1); number would you like to end with?\n"); &num2); for (i=num1;i<=num2; ++i) { result=result+i;//Add the current result to I } // End of loop printf("The Product of all integers between %d result); getchar(); return 0; } and %d is %d.\n",num1 ,num2,
When You Want to Use fgets() and sscanf() • int age; • char input[10]; • printf(“Enter your age: “); • fgets(input, sizeof(input), stdin); • sscanf(input, “%d”, &age) fgets(input, sizeof(input), stdin); 01 02 03 The first argument (input) tells C to which variable the inputted text should be assigned. The second argument dictates how many characters should be read, as a maximum value (most flexible choice is size of(). sizeof(input)-1: Returns the length of variable. ) The third argument tells fgets() from which file the string shoud be read. (stdin:Use standard input (keyboard)) sscanf(input, “%d”, &age) • sscanf() converts a string to another data type. • Same signifiers as printf() and scanf(). • First argument is the existing string (input), the second it the formatting, and the third is the variable to which the value should be assigned. • The variable’s name is preceded by the ampersand so that the address of the variable is referenced. Code /*Celcius_to_Fah.c*/ #include int main(void){ float temp_f, temp_c; char input[10]; //User prompt printf("Enter a temperature in degrees Celsius: "); //Read in the input and assign this to temp_c fgets(input, sizeof(input)-1, stdin); sscanf(input, "%f", &temp_c); //Conversion temp_f = temp_c*9.0/5.0+32; //result print printf("%0.1f degrees Celsius is %0.1f degrees Fahrenheit.\n", temp_c, temp_f); getchar(); getchar(); return 0;}

Tutor Answer

criss53
School: Boston College

Che...

flag Report DMCA
Review

Anonymous
Top quality work from this guy! I'll be back!

Similar Questions
Hot Questions
Related Tags
Study Guides

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors