#include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x) = x*x*x\n"); printf ("c: c(x) = x^2 + 2*x + 7\n"); printf ("q: quit\n"); } void a(float x) { float v = x*x; printf (" a(%.2f) = %.2f^2 = %.2f\n", x, x, v); } // end function a void b(float x) { float v = x*x*x; printf (" a(%.2f) = %.2f^3 = %.2f\n", x, x, v); } // end function b void c(float x) { float v = x*x + 2*x + 7; printf (" c(%.2f) = %.2f^2 + 2*%.2f + 7 = %.2f\n", x, x, x, v); } // end function c int menu () { char selection; float x; printHelp (); scanf ("%s", &selection); if (selection == 'q') return 1; scanf ("%f", &x); if (selection == 'a') a(x); if (selection == 'b') b(x); if (selection == 'c') c(x); return 0; } // end function menu int main() { while (menu() == 0); printf ("... bye ...\n"); return 0; } // end main
Why is the number of x’s different in the printf statements in the functions?
void a(float x) { float v = x*x; printf (" a(%.2f) = %.2f^2 = %.2f\n", x, x, v); // it is equal to a(x) = x^2 = v(=x*x) } // end function a In the above printf statement, x value is used two times and v value is used one time. The expression inside printf statement prints value of function a(x). The expression is : a(x)=x^2=v Hence, two times x value and one time v value is passed. void b(float x) { float v = x*x*x; printf (" b(%.2f) = %.2f^3 = %.2f\n", x, x, v); // it is equal to b(x) = x^3 = v(=x*x*x) } // end function b In the above printf statement, x value is used two times and v value is used one time. The expression inside printf statement prints value of function b(x). The expression is : b(x)=x^3=v Hence, two times x value and one time v value is passed. void c(float x) { float v = x*x + 2*x + 7; printf (" c(%.2f) = %.2f^2 + 2*%.2f + 7 = %.2f\n", x, x, x, v); // it is equal to c(x) = x^2+2*x+7 = v(=x*x + 2*x + 7) } // end function c
In the above printf statement, x value is used three times and v
value is used one time.
The expression inside printf statement prints value of function
c(x).
The expression is : c(x)=x^2+2*x+7
Hence, three times x value and one time v value is passed.
To better understand , count the number of occurrences of x and v in the expression.
#include <stdio.h> void printHelp () { printf ("\n"); printf ("a: a(x) = x*x\n"); printf ("b: b(x)...
include «stdio.h void displaymenu(void) printf(" printf" Enter Choicen") printf Set (a), Clear (c), Toggle (t)\n"): printf(" void printbinaryfunsigned char x) int main (int argc, char argvl) r mask atoi(argv[1): unsigned char maskatoi(argv[11): ensigned ahao data - ateilargvl21): char operation if argc 3 printf(" printf" n" printf("usage: %s FristArg SecondArgin", argle)); return;
Convert the below C code to basic MIPS. Please leave comments for explanation #include <stdio.h> int main(void) { printf("Insert two numbers\n"); int a,b; scanf("%d",&a); scanf("%d",&b); a=a<<2; b=b<<2; printf("%d&%d\n",a,b); return 0; }
PUT INTO PYTHON CODE #include <stdio.h> #include <float.h> int main(void) { float a = 1; float b = 0.5; float c = a + b; int bits = 0; while (c != a) { bits = bits + 1; b = b / 2; c = a + b; } printf("%d\n",bits); return 0; }
Convert the below C code to basic MIPS. Leave comments for explanation please #include <stdio.h> int main(void) { printf("Insert two numbers\n"); int a,b,c; scanf("%d",&a); scanf("%d",&b); c=a|b; printf("%d|%d=%d\n",a,b,c); return 0; }
What is going to be the output of the following program: # include <stdio.h> int main(void) {struct dob {int month; int day; int year;}; struct student {int sid; int yearOfAdmission; float currentGPA; struct dob bday; struct student stdnt = {123, 2015, 8.3, 11, 26, 1993}; printf(" Id is: %d \n", stdnt.sid); printf("Year of admission is: %d \n", stdnt.year OfAdmission); printf("Current GPA is: %.2f\n\n", stdnt.currentGPA); printf("Date of Birth is: %d/%d/%d", stdnt. bday. month, stdnt. bday.day, stdnt. bday.} return 0;}
#include<stdio.h> int main() { int i; printf("Type an integer value: "); scanf("%d",&i); evaluate(i); return(0); } void evaluate(int x) { if(x > 10) printf("Value entered by you is greater than 10"); else if(x < 10) printf("Value entered by you is less than 10"); else printf("Value entered by you is equal 10"); } _______________________________________ report for this in hr ?
#include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here. */ int GetNumOfNonWSCharacters(const char usrStr[]) { int length; int i; int count = 0; char c; length=strlen(usrStr); for (i = 0; i < length; i++) { c=usrStr[i]; if ( c!=' ' ) { count++; } } return count; } int GetNumOfWords(const char usrStr[]) { int counted = 0; // result // state: const char* it = usrStr; int inword = 0; do switch(*it)...
Fix the errors in C code #include <stdio.h> #include <stdlib.h> void insertAt(int *, int); void Delete(int *); void replaceAt(int *, int, int); int isEmpty(int *, int); int isFull(int *, int); void removeAt(int *, int); void printList(int *, int); int main() { int *a; int arraySize=0,l=0,loc=0; int choice; while(1) { printf("\n Main Menu"); printf("\n 1.Create list\n 2.Insert element at particular position\n 3.Delete list.\n4. Remove an element at given position \n 5.Replace an element at given position\n 6. Check the size of...
#include <stdio.h> int function() { int x, y; printf("Enter the value of x:"); scanf("%d", &x); y = 3*x*x*x*x*x + 2*x*x*x*x - 5*x*x*x - x*x + 7*x - 6; printf("%d", y); return y; } int main() { function(); } Modify the program of Programming Project 5 so that the polynomial is evaluated using the following formula: ((((3x+2)x-5)x+7)x-6
#include <stdio.h> #include string.h #define C17_PRICE 12.80 #define F25_PRICE 4.29 #define DN3_PRICE 10.00 #define GG7_PRICE 35.00 #define MV4_PRICE 18.49 #define DISCOUNT 0.05 #define DISC_THRES 10 #define SAME_DAY_DELIVERY = 35.0 #define NEXT_DAY_DELIVERY = 20.0 typedef enum{ WRONG, C17, F25, DN3, GG7, MV4} part /*--- Function Prototypes ------------*/ part getPartType ( void ); int getquantity ( void ); int getDeliveryOption ( void ); float calcPriceOfParts( part orderedPart, int quantity ); float calcTotalCarges ( float orderPrice, char...