0% found this document useful (0 votes)
9 views5 pages

1D_2D Array Program with Problem Statement

The document contains C programs for handling 1D and 2D arrays, including user input, display of elements, and basic operations like sum and average calculations. It provides problem statements and code examples for each scenario, demonstrating how to work with arrays in C. The programs are structured to guide users through inputting data and performing operations effectively.

Uploaded by

Dave
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)
9 views5 pages

1D_2D Array Program with Problem Statement

The document contains C programs for handling 1D and 2D arrays, including user input, display of elements, and basic operations like sum and average calculations. It provides problem statements and code examples for each scenario, demonstrating how to work with arrays in C. The programs are structured to guide users through inputting data and performing operations effectively.

Uploaded by

Dave
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/ 5

Shri Ramdeobaba College of Engineering & Management, Nagpur

Electronics & Communication Engineering Department


Section:L&M

Subject:PPS

Prof. Komal Umare Thool


1D Array Program with Problem Statement:

Problem Statement:

Write a C program that allows the user to input elements into a 1D array and then display those elements.

#include <stdio.h>

int main() {

int n;

printf("Enter the size of the array: ");

scanf("%d", &n);

int arr[n];

// Input elements into the array

printf("Enter %d elements:\n", n);

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

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

// Display elements of the array

printf("Elements in the array:\n");

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

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

return 0;
}

2D Array Program with Problem Statement:

Problem Statement:

Write a C program that allows the user to input elements into a 2D array and then display those elements.

#include <stdio.h>

int main() {

int rows, cols;

printf("Enter the number of rows and columns for the 2D array: ");

scanf("%d %d", &rows, &cols);

int arr[rows][cols];

// Input elements into the 2D array

printf("Enter %d elements for the 2D array:\n", rows * cols);

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

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

// Display elements of the 2D array

printf("Elements in the 2D array:\n");

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

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

printf("\n");

}
return 0;

1D Array Program with Operations:

Problem Statement:

Write a C program that allows the user to input elements into a 1D array and perform basic operations
such as finding the sum and average of the elements.

#include <stdio.h>

int main() {

int n;

printf("Enter the size of the array: ");

scanf("%d", &n);

int arr[n];

int sum = 0;

// Input elements into the array

printf("Enter %d elements:\n", n);

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

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

sum += arr[i];

// Display elements of the array

printf("Elements in the array:\n");

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

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

// Calculate and display the sum and average


float average = (float)sum / n;

printf("\nSum of elements: %d\n", sum);

printf("Average of elements: %.2f\n", average);

return 0;

2D Array Program with Operations:

Problem Statement:

Write a C program that allows the user to input elements into a 2D array and perform basic operations
such as finding the sum and average of the elements in each row.

#include <stdio.h>

int main() {

int rows, cols;

printf("Enter the number of rows and columns for the 2D array: ");

scanf("%d %d", &rows, &cols);

int arr[rows][cols];

// Input elements into the 2D array

printf("Enter %d elements for the 2D array:\n", rows * cols);

for (int i = 0; i < rows; i++) {

for (int j = 0; j < cols; j++) {

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

// Display elements of the 2D array

printf("Elements in the 2D array:\n");

for (int i = 0; i < rows; i++) {


for (int j = 0; j < cols; j++) {

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

printf("\n");

// Calculate and display the sum and average of each row

printf("Sum and Average of each row:\n");

for (int i = 0; i < rows; i++) {

int rowSum = 0;

for (int j = 0; j < cols; j++) {

rowSum += arr[i][j];

float rowAverage = (float)rowSum / cols;

printf("Row %d: Sum = %d, Average = %.2f\n", i + 1, rowSum, rowAverage);

return 0;

You might also like