Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write down the output of the following C programs. a) #include float avg(float, float); int main() { float y1, y2, average; y1=5.0; y2=7.0; average

1. Write down the output of the following C programs.

a)

#include

float avg(float, float);

int main()

{ float y1, y2, average;

y1=5.0;

y2=7.0;

average = avg(y1, y2);

printf("y1 = %f y2=%f The average is=

%f", y1, y2, average);

return 0;

}

float avg(float x1, float x2)

{ float result;

result = (x1+x2)/2;

return result;

}

b)

#include

float square ( float x);

void main( )

{ float m, n ;

printf ( " Enter some number for

finding square ");

scanf ( "%f", &m ) ;

n = square ( m ) ;

printf ( " Square of the given

number %f is %f",m,n );

}

float square ( float x )

{

float p ;

p = x * x ;

return p ;

}

c)

#include

void swap(int a, int b);

int main()

{ int m = 22, n = 44;

printf(" values before swap m =

%d and n = %d", m, n);

swap(m, n);

}

void swap(int a, int b)

{ int tmp;

tmp = a;

a = b;

b = tmp;

printf(" values after swap m

= %d and n = %d", a, b);

}

d)

#include

int f(int a)

{ return a%2 ? ++a : a--; }

void main()

{ int i , a = 2;

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

{ a += i;

printf("(%d,%d)",i,f(a));

}

}

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