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

Free

70.2K

Verified Solution

Question

Electrical Engineering

a) Write C code initialize an array of ints to the last fourdigits 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

Answer & Explanation Solved by verified expert
4.5 Ratings (668 Votes)

for part a

#include

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
#include
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 );
}


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students