Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C program help 1. Write a program to compute the Mileage given by a vehicle. Mil

ID: 3698480 • Letter: C

Question

C program help
1. Write a program to compute the Mileage given by a vehicle.
Mileage = (new_odometer – old_odometer)/(gallons_gas) // illustrating how ‘for’ loop works.

2. How to initialize an array of size 5 using an initializer list and to compute it’s sum How to initialize an array of size 5 with even numbers starting from 2 using ‘for’ loop and to compute it’s sum
3. Program to compute the car insurance premium for a person based on their age and the number of tickets they have received. The following table explains how to perform the ticket computation: If Person's Age Is
Then Insurance Cost Is
Less than 21
$1500 + $250 x number of tickets
From 21 through 24
$1200 + $250 x number of tickets
25 or older
$1000 + $200 x number of tickets
Print the person’s age, number of tickets and the computed insurance cost. C program help
1. Write a program to compute the Mileage given by a vehicle.
Mileage = (new_odometer – old_odometer)/(gallons_gas) // illustrating how ‘for’ loop works.

2. How to initialize an array of size 5 using an initializer list and to compute it’s sum How to initialize an array of size 5 with even numbers starting from 2 using ‘for’ loop and to compute it’s sum
3. Program to compute the car insurance premium for a person based on their age and the number of tickets they have received. The following table explains how to perform the ticket computation: If Person's Age Is
Then Insurance Cost Is
Less than 21
$1500 + $250 x number of tickets
From 21 through 24
$1200 + $250 x number of tickets
25 or older
$1000 + $200 x number of tickets
Print the person’s age, number of tickets and the computed insurance cost. C program help
1. Write a program to compute the Mileage given by a vehicle.
Mileage = (new_odometer – old_odometer)/(gallons_gas) // illustrating how ‘for’ loop works.

2. How to initialize an array of size 5 using an initializer list and to compute it’s sum How to initialize an array of size 5 with even numbers starting from 2 using ‘for’ loop and to compute it’s sum
2. How to initialize an array of size 5 using an initializer list and to compute it’s sum How to initialize an array of size 5 with even numbers starting from 2 using ‘for’ loop and to compute it’s sum
3. Program to compute the car insurance premium for a person based on their age and the number of tickets they have received. The following table explains how to perform the ticket computation: If Person's Age Is
Then Insurance Cost Is
Less than 21
$1500 + $250 x number of tickets
From 21 through 24
$1200 + $250 x number of tickets
25 or older
$1000 + $200 x number of tickets
Print the person’s age, number of tickets and the computed insurance cost.

Explanation / Answer

1.

#include <stdio.h>

int main(){
double oldOdometer, newOdometer, gallonsGas;
printf("Enter the old odometer reading: ");
scanf("%lf", &oldOdometer);
printf("Enter the new odometer reading: ");
scanf("%lf", &newOdometer);
printf("Enter the number of gallons: ");
scanf("%lf", &gallonsGas);
double mileage = (newOdometer - oldOdometer) / gallonsGas;

printf("The mileage is: %lf ", mileage);
}

2.

#include <stdio.h>

int main(){
int arr[] = {1, 2, 3, 4, 5};
int sum = 0, i;
for(i = 0; i < 5; i++) {
sum += arr[i];
}
printf("Sum is: %d ", sum);
}

---------------------------------------------

#include <stdio.h>

int main(){
int arr[5];
int sum = 0, i;
for(i = 0; i < 5; i++) {
arr[i] = 2 * (i + 1);
sum += arr[i];
}
printf("Sum is: %d ", sum);
}

3.

#include <stdio.h>

int main(){
int tickets, age;
printf("Enter the age: ");
scanf("%d", &age);
printf("Enter the number of tickets received: ");
scanf("%d", &tickets);
double totalCost = 0;
if(age < 21){
totalCost = 1500 + 250 * tickets;
} else if(age < 24) {
totalCost = 1200 + 250 * tickets;
} else {
totalCost = 1000 + 200 * tickets;
}
printf("Age: %d, Insurance cost: %lf ", age, totalCost);
}