In: Electrical Engineering
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
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 );
}