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

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...
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...
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...
C++ Write the code to implement a complete binary heap using an array ( Not a...
C++ Write the code to implement a complete binary heap using an array ( Not a vector ). Code for Max heap. Implement: AddElement, GetMax, HeapSort, ShuffleUp, ShuffleDown, etc Set array size to 31 possible integers. Add 15 elements 1,3,27,22,18,4,11,26,42,19,6,2,15,16,13 Have a default constructor that initializes the array to zeros.. The data in the heap will be double datatype. PART 2 Convert to the program to a template, test with integers, double and char please provide screenshots thank you so...
How do I write a C# and a C++ code for creating a character array containing...
How do I write a C# and a C++ code for creating a character array containing the characters 'p', 'i', 'n','e','P','I','N','E' only and then using these lower and capital case letter character generate all possible combinations like PInE or PinE or PIne or PINE or piNE etc. and only in this order so if this order is created eg. NeIP or EnPi or NeIP or IPnE and on. You can generate all the combinations randomly by creating the word pine...
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