Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Show the contents of the following array declarations. a) int 1[5], N2[5]; N1[2] = 4; N1[0] = N1[2]; N2[4] = N1[0]; b) float prices[5]={1.25,

1. Show the contents of the following array declarations.

a) int 1[5], N2[5];

N1[2] = 4;

N1[0] = N1[2];

N2[4] = N1[0];

b) float prices[5]={1.25, 3.50, 1.20, 2.99, 0.75};

c) float prices[5]={1.25, 3.50};

d) int months[ ]={1,2,3,4,5,6,7,8,9,10,11,12};

e) int x[2][3]={1,2,3,3,2,1};

f) int y[2][3]={{1,2,3},{3,2,1}};

2. What is the output of the following C program fragments?

a) #include

void main()

{

int a[3][3] = {1,3,5,7,9};

int i=0,j,sum=0;

for(j=0; j < 3; j++)

sum += a[1][j];

printf("%d ",sum);

for(j=0; j < 3; j++)

sum += a[j][i++];

printf("%d ",sum);

}

b)

int age[4];

age[0]=2;

age[1]=43;

age[2]=60;

age[3]=46;

printf("%d ", age[0]);

printf("%d ", age[1]);

printf("%d ", age[2]);

printf("%d ", age[3]);

c)

int age[4] = {23, 34, 65, 74};

int same_age[4];

int i;

for(i=0; i<4; i++)

same_age[i]=age[i];

for(i=0; i<4; i++)

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

d)

int i;

float sales[120];

float sum=0.0;

for (i = 0; i < 10; i++)

{

printf(" Enter Sales ($): ");

scanf("%f", &sales[i]);

}

for (i=0;i<10;i++)

sum+=sales[i];

printf(sum of sales is %f, sum);

e)

int n, m;

float x[5][6];

for (n = 0; n < 5; ++n)

for (m = 0; m < 6; ++m)

{

printf(Enter value for x[%d][%d],n,m);

scanf("%f", &x[n][m]);

}

for (n = 0; n < 5; n++)

for (m = 0; m < 6; m++)

printf(" x[%d][%d]=%f", n,m,x[n][m]);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions