Question

Write a C program that accepts a single integer N. Your code must then calculate the...

Write a C program that accepts a single integer N. Your code must then calculate the average of all positive integers less than N that are divisible by either 5 or 7, but not both.

When you print your average, truncate the result to three decimal places. Do not print anything else to the screen.

Example input:

19

Example output:

10.200

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code For Above Problem:

 #include <stdio.h> int main() {         int n;//Single Integer  scanf("%d",&n);//reading integer    float sum=0;//to hold the sum   float average;//to hold the average     int count=0;//to count how many numbers that are divisible by either 5 or 7             for(int i=1;i<=n;i++)//Check for all Numbers         {               if(i%5==0 || i%7==0)//check number divisible by either 5 or 7           {                       if(!(i%5==0 && i%7==0))//check if it should not divisible by 5 and 7                    {                               sum+=i;//add number to sum                              count++;//increment the count                   }               }       }       average=sum/count;//finding average     printf("%.3f\n",average);//printing average upto 3 decimals     return 0; }

Input/Output Of Above Code:

Sample Input:

10

Sample Output:

10.200

Image Of Above Code:

1#include <stdio.h> 2 int main() 3{ 4 int n;//Single Integer 5 scanf(%d,&n);//reading integer 6 float sum=0;//to hold the s

Input/Output Image:

apiiit-rkv@apiiitrkv-Travelmate-P243-M:-/Desktops cc sample.c apiiit-rkvapiiitrkv-TravelMate-P243-M:~/Desktop$ ./a.out 19 10.

Add a comment
Know the answer?
Add Answer to:
Write a C program that accepts a single integer N. Your code must then calculate the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Exercise 9.2 Write a Python program that collects from the user a single integer. Have the...

    Exercise 9.2 Write a Python program that collects from the user a single integer. Have the program print “EVEN” if the integer is divisible by 2, and “ODD” if the integer is not divisible by two. [Use the % operator to compute the two’s modulus (remainder of division by two)] Exercise 9.3 Write a Python program that collects from the user two integers. Have the program print “Yes” if the two integers are BOTH greater than 10. Do nothing if...

  • Write a MARIE assembly program that accepts one integer input. Use the the number to calculate...

    Write a MARIE assembly program that accepts one integer input. Use the the number to calculate the factorial. You must use addition not multiplication. Example: 5! = 5x4x3x2x1 Print out the result.

  • Write a complete C++ program to ask the user to enter 4 integers. The program must...

    Write a complete C++ program to ask the user to enter 4 integers. The program must use a function to find the smallest integer among them and print it on the screen. Typical output screen should be as following: Write a complete C++ program to ask the user to enter 4 integers. The program must use a functionto find the smallest integer among them and print it on the screen. Typical output screen should be as following: Note: the code...

  • Write a complete C++ program to ask the user to enter 4 integers. The program must...

    Write a complete C++ program to ask the user to enter 4 integers. The program must use a function to find the LARGEST integer among them and print it on the screen. Typical output screen should be as following: Note: the code must contain function to find the LARGEST number. Enter four integers 1 2 4 0 Largest integer is 4

  • (devC++) Develop a C recursive function that accepts an integer N. The function should calculate and...

    (devC++) Develop a C recursive function that accepts an integer N. The function should calculate and return the result of the following function: f(N) = 1 + 1/2! + 1/3! + ...+1/N! Write a C program that reads an integer value. The program should call the function above and then print the result on the screen with two decimal point format (i.e. 12.34).

  • Write a complete C++ program to ask the user to enter 4 integers. The program must...

    Write a complete C++ program to ask the user to enter 4 integers. The program must use a function to find the largest integer among them and print it on the screen. Typical output screen should be as following: Note: the code must contain function to find the largest number. Enter four integers 1 2 4 0 Largest integer is 4 03 (35 points)

  • Write in C++ program Larger than n In a program, write a function that accepts three...

    Write in C++ program Larger than n In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume the array contains integers. The function should display all of the numbers in the array that are greater than the number n. Input from the keyboard: The filename and path of a list of integer numbers.                                           The number n to test the file numbers. Output to the console: The...

  • Write a program in Python that accepts as input an integer N and a real number...

    Write a program in Python that accepts as input an integer N and a real number c, and outputs the coefficient of the Nth degree term of the Taylor series for the function f(x) = ex centered at c. This process should recur until the user enters a quit code. Erroneous input should be excepted as necessary, and should result in a new prompt.

  • In Python 5. Write a function named listComprehensionDivisors that has 3 integer inputs, N, n1, and...

    In Python 5. Write a function named listComprehensionDivisors that has 3 integer inputs, N, n1, and n2. Using a single list comprehension to make a list of all of the numbers in the range 1..N that are either divisible by n1 or n2, where n1 and n2 can be any positive integers. After creating the list, your code should print out the following 2 lines: “We are printing all numbers from 1 to that are divisible by or ” “These...

  • P.2. Division Write a C program to input an integer n. Then the program asks users...

    P.2. Division Write a C program to input an integer n. Then the program asks users to input n integers. Calculate the sum of all non negative integers and the division of this with every negative integer in the sequence. p3 Write a C program to print all 3-digit abc numbers, satisfying: (a+b+c)=(a.b.c). Example: 3-digit 123 number fulfills requirement as (1+2+3)=1.2.3

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT