194k views
2 votes
Write a complete C program that can perform the following tasks:

a. Input 10 numbers from the keyboard and compute the sum of these numbers. A loop is required to implement this task.
b. Then, code the summation result by extracting the least significant digit (LSD) of the sum using the modulo % operation (e.g., 95%10-5) and then subtracting this LSD from the sum. You are required to define and call a function to do this coding task.

1 Answer

7 votes

Final answer:

The detailed answer provides a C program code that inputs 10 numbers, computes their sum, and then transforms the sum by subtracting its least significant digit using a custom function.

Step-by-step explanation:

C Program for Summation and Coding of Numbers

Here's a complete C program that will:

  1. Input 10 numbers from the user.
  2. Compute the sum of these numbers.
  3. Call a function to code the summation result.

The coding task involves extracting the least significant digit (LSD) using the modulo operation and subtracting it from the sum.

Below is the C program code:

#include

int codeSum(int sum) {
return sum - (sum % 10);
}

int main() {
int numbers[10];
int sum = 0;
printf("Enter 10 numbers:\\");
for (int i = 0; i < 10; i++) {
scanf("%d", &numbers[i]);
sum += numbers[i];
}
printf("Sum of the numbers is: %d\\", sum);
int codedSum = codeSum(sum);
printf("Coded sum by subtracting the LSD: %d\\", codedSum);
return 0;
}

This program uses loops to input numbers and a function to perform the coding task, which is main part of the program's logic.

User Ratnesh Maurya
by
7.6k points