Question

In: Electrical Engineering

a) Write C code initialize an array of ints to the last four digits of your...

a) Write C code initialize an array of ints to the last four digits of your phone number. Use a loop to add the digits. Calculate and display the average of the digits.

b) Write C code using a struct to hold student information:

integer id

integer number of hours taken

integer number of hours passed

double gpa

Solutions

Expert Solution

for part a

#include <stdio.h>

int main()
{
    int arr[4], i=0, sum=0;
    printf("Enter last 4 digit of your phone number");
    for (i=0; i<4; i++)
    {
      scanf("%d",&arr[i]);
    }
    for (i=0; i<4; i++)
    {
        sum = sum + arr[i];
    }
    printf(" Average is :" , sum/4);
    return 0;
}

for b part

#include<stdio.h>
#include<string.h>
struct student
{
    char name[20];
    int id;
    int hour_taken;
    int hour_passed;
    double gpa;
};
int main(void)
{
    printf(" Enter student name , id , hours taken, hours passed, GPA");
    scanf("%s %d %d %d %f", stu3.name, &stu3.id,stu3.hour_taken, stu3.hour_passed, stu3.gpa );
}


Related Solutions

For c++ Write the code to initialize an array such that each element gets two times...
For c++ Write the code to initialize an array such that each element gets two times the value of its index (e.g. 0, 2, 4, 6, …)
C Language - Programming Write a function that takes an array of ints, and the size...
C Language - Programming Write a function that takes an array of ints, and the size of the array – another int. It also returns a double. Call this one ‘average.’ Return a double that is the average of the values in the array. Demonstrate that it works by finding the average of an array with these values {78, 90, 56, 99, 88, 68, 92} Write a function that takes one double parameter, and returns a char. The parameter represents...
In C++ Write a function which takes two parameters: an array of ints and an int...
In C++ Write a function which takes two parameters: an array of ints and an int size of the array and prints every element greater than 5 to the screen. As an example, if the array has the following 10 elements: 2 5 8 9 7 1 0 2 6 3, your function should print out 8 9 7 6. You may assume that the parameters passed to the function are valid. Your function must have the following signature: void...
C Write a function that takes as input an array of int pointers, multiplies the ints...
C Write a function that takes as input an array of int pointers, multiplies the ints the pointers point to by -1, and then sorts the array such that the values pointed to by the pointers are in decreasing order. For example, if the array is size 10 the pointer at index 0 will point to the largest value after multiplying by -1 and the pointer at index 9 will point to the smallest value after multiplying by -1. If...
Declare and initialize an array to store the course name or code.
Declare and initialize an array to store the course name or code.
Consider the following C code: (10 marks) // write a MIPS instruction to initialize s0 to...
Consider the following C code: // write a MIPS instruction to initialize s0 to 6 t0 = ((s03 - 93)2 + s0 ) << 2 t1 = t0 / 4 Q2.1: Write a MIPS program that performs the operation of the above C program. Q2.2: What is the value of $t0 and $t1 after running your MIPS program (write your answer in a comment at the end of the code). Submit your answer to Q2 in a file named A2_Q2.asm
Write a code using c# Maximum Sub Array.
Write a code using c# Maximum Sub Array.
Write a code in c++ using dynamic array of structure and dynamic array list. Make a...
Write a code in c++ using dynamic array of structure and dynamic array list. Make a dummy list for a company which stores following information about its customers. Customer ID Customer Name Gender Total items purchased Item category 20% discount in percentage of total purchase amount. Use dynamic array to save at least 20 items by dividing them into 3 different categories. Make a dummy list of items that company sells by dividing them into two categorizes. Items has following...
Let A be the sum of the last four digits and let B be the last...
Let A be the sum of the last four digits and let B be the last digit of your 8-digit student ID. (Example: For 20245347, A = 19 and B = 7) On a road trip, a driver achieved an average speed of (48.0+A) km/h for the first 86.0 km and an average speed of (43.0-B) km/h for the remaining 54.0 km. What was her average speed (in km/h) for the entire trip? Round your final answer to three significant...
Please Solve with c language Create 5-by-5 integer array. Initialize the elements of the array starting...
Please Solve with c language Create 5-by-5 integer array. Initialize the elements of the array starting from 1. Your element [0][0] should be equal to 1; element[4][4] should be equal 25. Print the array. The output should have 5 rows and 5 columns. Specify the width for each output to demonstrate the table in a formatted view. Change the value of the elements: 2nd row 4th column to 24, 1st row 3rd column to 13. Print the array again. Find...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT