// Online C compiler to run C program online
#include <stdio.h>
int main()
{
int num[3][4];
int i, j, total=0, average=0;
int copynum[3][4];
printf("Enter 12 numbers:");
//Enter 12 numbers and Print the sum and average
for(i=0; i<=2; i++)
{
for(j=0; j<=3; j++)
{
scanf("%d", &num[i][j]);
total=total+num[i][j];
copynum[i][j]=num[i][j];
}
}
average=total/12;
printf("The sum is %d\n", total);
printf("The average is %d\n", average);
//Print 12 numbers
printf("The 12 integers are:\n");
for(i=0; i<=2; i++)
{
for(j=0; j<=3; j++)
printf("%5d", num[i][j]);
printf("\n");
}
//Display Odd numbers
printf("Odd numbers: ");
for(i=0; i<=2; i++)
{
for(j=0; j<=3; j++)
if(num[i][j]%2==1)
printf("%d ", num[i][j]);
}
printf("\n");
//Display Even numbers
printf("Even numbers: ");
for(i=0; i<=2; i++)
{
for(j=0; j<=3; j++)
if(num[i][j]%2==0)
printf("%d ", num[i][j]);
}
printf("\n");
//Display the smallest
int small=num[0][0];
for(i=0; i<=2; i++)
for(j=0; j<=3; j++)
{
if(num[i][j] < small)
small=num[i][j];
}
printf("The smallest number is: %d", small);
printf("\n");
//Display the biggest
int big=num[0][0];
for(i=0; i<=2; i++)
for(j=0; j<=3; j++)
{
if(num[i][j] > big)
big=num[i][j];
}
printf("The biggest number is: %d", big);
printf("\n");
//Display contents of array in reverse order
printf("The 12 integers in reverse:\n");
for(i=2; i>=0; i--)
{
for(j=3; j>=0; j--)
printf("%5d", num[i][j]);
printf("\n");
}
//Copying a two-dimensional array into another
printf("Copy of Two-Dimensional Array to new Array:");
for(i=0; i<=2; i++)
{
for(j=0; j<=3; j++)
printf("%5d", copynum[i][j]);
printf("\n");
}
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter