0% found this document useful (0 votes)
2 views4 pages

C Programming Solutions

The document provides solutions to three C programming questions: one for reading integers and displaying them in reverse order, another for finding the minimum and maximum values in an array of integers, and the last for computing the sum of four different types of numbers input by the user. Each solution includes the necessary code and input validation. The programs utilize standard input/output functions and handle arrays and different data types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

C Programming Solutions

The document provides solutions to three C programming questions: one for reading integers and displaying them in reverse order, another for finding the minimum and maximum values in an array of integers, and the last for computing the sum of four different types of numbers input by the user. Each solution includes the necessary code and input validation. The programs utilize standard input/output functions and handle arrays and different data types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Solutions for the C Programming Questions

1. Write a program in C to read n integers in an array and display them in reverse order.

Solution:

#include <stdio.h>

int main() {

int n, i;

int arr[100];

printf("Enter the number of elements (10 <= n < 100): ");

scanf("%d", &n);

if (n < 10 || n >= 100) {

printf("Invalid input. n should be between 10 and 99.

");

return 1;

printf("Enter %d integers: ", n);

for (i = 0; i < n; i++) {

scanf("%d", &arr[i]);

printf("Array in reverse order:\n");


for (i = n - 1; i >= 0; i--) {

printf("%d ", arr[i]);

printf("\n");

return 0;

2. Write a program in C to read n integers in an array and find out the minimum and maximum

values.

Solution:

#include <stdio.h>

int main() {

int n, i, min, max;

int arr[100];

printf("Enter the number of elements (0 < n < 100): ");

scanf("%d", &n);

if (n <= 0 || n >= 100) {

printf("Invalid input. n should be between 1 and 99.

");

return 1;

}
printf("Enter %d integers: ", n);

for (i = 0; i < n; i++) {

scanf("%d", &arr[i]);

min = max = arr[0];

for (i = 1; i < n; i++) {

if (arr[i] < min) {

min = arr[i];

if (arr[i] > max) {

max = arr[i];

printf("Min = %d\n", min);

printf("Max = %d\n", max);

return 0;

3. Write a C program that prompts the user to input four different types of numbers and compute

their sum.

Solution:

#include <stdio.h>
int main() {

int int_num;

long long_num;

float float_num;

double double_num, sum;

printf("Enter an integer: ");

scanf("%d", &int_num);

printf("Enter a long integer: ");

scanf("%ld", &long_num);

printf("Enter a floating-point number: ");

scanf("%f", &float_num);

printf("Enter a double-precision floating-point number: ");

scanf("%lf", &double_num);

sum = int_num + long_num + float_num + double_num;

printf("Sum = %.2lf\n", sum);

return 0;

You might also like