{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ese cheat sheet - Quizs 9-14 Yellow Design a program in C...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Quizs 9-14 Yellow Design a program in C which will compute, using the method of call by value , the highest grade in an examination. When executed, the program will do the following in sequence: 1. Ask the user to type on the keyboard the number of students taking the examination. 2. Ask the user to type on the keyboard the grades for the class. 3. Display on the console the grades. 4. Compute and display on the console the highest grade in the class. #include<stdio.h> #define max 100 float HighestGrade(float grade[],int number); main(){ int number,i; float grade[max],highest; printf("Enter the # of students: "); scanf("%d",&number); printf("\n"); for(i=0;i<number;i++){ printf("Enter the grade of student %d: ",i+1); scanf("%f",&grade[i]); } printf("\n"); for(i=0;i<number;i++){ printf("The grade of student %d is %.2f\n",i+1,grade[i]); } printf("\n"); highest = HighestGrade(grade,number); printf("The highest grade is %.2f",highest); } float HighestGrade(float grade[],int number){ int i; float highest=grade[0]; for(i=1;i<number;i++){ if(highest<grade[i]){ highest = grade[i]; } } return highest; }
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Design a program in C which will compute, using the method of call by reference , the equivalent resistance to four resistors connected in series . When executed, the program will do the following in sequence: 1. Ask the user to type on the keyboard the values of the individual resistances in floating- point format. Assume all of the resistance values to be in kΩ. 2. Display on the console the names and values of the individual resistances. 3. Compute and display on the console the value of the equivalent resistance. The format of the output is to be one resistance value per line. SOLUTION: #include<stdio.h> float EquResistance(float *R1,float *R2,float *R3,float *R4); main(){ float R1,R2,R3,R4,equR; int i; printf("Enter resistance of resistor 1: "); scanf("%f",&R1); printf("Enter resistance of resistor 2: "); scanf("%f",&R2); printf("Enter resistance of resistor 3: "); scanf("%f",&R3); printf("Enter resistance of resistor 4: "); scanf("%f",&R4); printf("\n"); printf("The resistance of resisotr 1 is %.2f\n",R1); printf("The resistance of resisotr 2 is %.2f\n",R2); printf("The resistance of resisotr 3 is %.2f\n",R3); printf("The resistance of resisotr 4 is %.2f\n",R4); printf("\n"); equR = EquResistance(&R1,&R2,&R3,&R4); printf("The equivalent resistance is %.2f\n",equR); } float EquResistance(float *R1,float *R2,float *R3,float *R4){ return (*R1+*R2+*R3+*R4); } The following statements are part of a C program: int a[10]={68,22,30,25,19,21,66,38,46,23};
Image of page 2
int *ptra; ptra=a; Assuming that the address of a[0] is 256 bytes, and that the compiler uses 2 bytes of RAM to store an integer number, find the values of the following quantities; Quantities Values a 256 ptra 256 &a[2] 260 &a[8] 272 a+5 266 a[5] 21 ptra+3 262 *ptra 68 *(ptra+6) 66 &*(ptra+7) 270 -------------------------------------------------------------------------------------------------------------------------------------- - Write a program in C which takes in the following input array of integer numbers a[4] = {58,22,45,33} and reorders the elements of the array through a swapping process to output the array b[4]={22,58,33,45}.
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern