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...
5. Write a C++ statement or statements that will:       Print the first two digits and the  last...
5. Write a C++ statement or statements that will:       Print the first two digits and the  last two digits of any 4 digit number stored in an integer variable n.         For example, given int n = 5623, print 56    23. 6. Write  C++ statements that will align the following three lines as printed in two 20 character columns. Name                                                 Years President Abraham Lincoln                                 1860-1865 Thomas Jefferson                               1801-1809 7.  Write a C++ statement or statements that will Output if a string has a length greater than 10, equal...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT