0% found this document useful (0 votes)
61 views6 pages

A.sqrt (X+y) B.pow (X, (Y+7) ) F.abs (X-Y) : Area Ss As Bs C S A B C

This document contains questions from a C programming midterm exam. Question 1 asks students to evaluate arithmetic expressions and write them in C code. Question 2 asks students to write a function to calculate the area of a triangle given its side lengths. Question 3 asks students to write a program to add two matrices of size 3x3 and store the result in a third matrix. The document also contains sample code snippets and their expected outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views6 pages

A.sqrt (X+y) B.pow (X, (Y+7) ) F.abs (X-Y) : Area Ss As Bs C S A B C

This document contains questions from a C programming midterm exam. Question 1 asks students to evaluate arithmetic expressions and write them in C code. Question 2 asks students to write a function to calculate the area of a triangle given its side lengths. Question 3 asks students to write a program to add two matrices of size 3x3 and store the result in a third matrix. The document also contains sample code snippets and their expected outputs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

King Saud University

College of Engineering
GE211: Programming in C second Midterm Exam
Question 1:
A !etermine t"e value of eac" of t"e follo#ing arit"metic ex$ressions%
& Convert eac" of t"e follo#ing mat"ematical ex$ressions to a C'' arit"metic
ex$ression.
a.sqrt(x+y);
b.pow(x,(y+7));
f.abs(x-y);
Question 2: using function
A("e area of an ar)itrary triangle can )e com$uted using t"e formula
* +* +* +
* + , 2
area s s a s b s c
s a b c
=
= + +

-"ere a. ). and c are t"e lengt"s of t"e sides. and s is t"e semi $erimeter% -rite a void function
$rogram to com$ute t"e area in e/uation%
#include <iostream
usin! namespace std;
int ssss (int a, int b,int c)
"
int s;
s#(a+b+c)$%;
cout <<&'nter t(e a#& << endl;
cin a;
cout <<&'nter t(e b#& << endl;
cin b;
cout <<&'nter t(e c # & << endl;
cin c;
return (s); )
int main ()
" double area;
area # sqrt(s*(s-a)*(s-b)*(s-c));
cout << &+(e result ,area & << araa;
return -;
)
&
0n cold #eat"er. meteorologists re$ort an index called t"e #ind c"ill factor. #"ic" ta1es into
account t"e #ind s$eed and t"e tem$erature% ("e index $rovides a measure of t"e c"illing
effect of #ind at a given air tem$erature% -ind c"ill may )e a$$roximated )y t"e follo#ing
formula
2%13 2%213
14%2 2%32 11%45 2%6 w t v tv = + +
#"ere .v 7 #ind s$eed in m,sec .t 7 tem$erature in degrees Celsius: t 87 12 .- 7 #ind c"ill
index *in degrees Celsius+. -rite a function t"at returns t"e #ind c"ill index%
#include<iostream
#include<cmat(
usin! namespace std;
int main()
" double w,t,.;
cout<<&inter .alue of . &<< . <<endl;
cin /./
cout<<&inter .alue of t &<< t <<endl;
cin /t/;
-714%2'2%329t11%459v:2%13'2%69t9v:2%213
cout<<&w is #&<<w<<endl;
return -;
Question3:
A0f you "ave matrix P;4<;4< and second matrix /;4<;4<. -rite t"e com$lete C
$rogram to com$ute t"e addition of P;4<;4<and /;4<;4< if t"e result stored in t"e t"ird
matrix r ;4<;4<%
int $;4<;4< 7 = =1. 4. 6>. =1. 1. 2>. =1. 2. ?> >@
int /;4<;4< 7 = =A. 4. 2>. =4. 12. 2>. =2. 2. 3> >@
Binclude 8iostreamC
void multDmatrices*int a;<;4<. int );<;4<. int result;<;4<+@
void $rintDmatrix*int a;<;4<+@
void main*void+ =
int $;4<;4< 7 = =1. 4. 6>. =1. 1. 2>. =1. 2. ?> >@
int /;4<;4< 7 = =A. 4. 2>. =4. 12. 2>. =2. 2. 3> >@
int r;4<;4<@
multDmatrices*$. /. r+@
cout88Dmatrix*r+@
>
void add_matrices(int a[][3], int b[][3], int result[][3])
{
int i, j, k;
or(i!"; i#3; i$$)
{
or(j!"; j#3; j$$)
{
or(k!"; k#3; k$$)
{
result[i][j] ! a[i][k] $ b[k][j];
%
%
%
%
void &rint_matri'(int a[][3])
{
int i, j;
or (i!"; i#3; i$$)
{
or (j!"; j#3; j$$)
{
(out ## result [i][j]);
%

%%
&
-"at #ill t"e follo#ing sni$$et of code out$utE
void foo(int arr[])
{
arr[1]=1;
return;
}
int main()
{
int arr[] = {3, 2, 1};
foo(arr);
cout << arr[0] << " " << arr[1] << " " << arr[2];
return 0;
}
Correct Ans#er: 4 1 1
-"at #ill t"e follo#ing sni$$et of code out$utE
int a[5];
a[0]=1; a[1]=2; a[2]=3;
for (int i=0; i<5; i++) {
cout << arr[i] << end;
}
Correct Ans#er:
1
2
3
<un!no"n vaue#
<un!no"n vaue#
+(e .alues in memory stored in arr012 and arr032 will be treated as
inte!ers and output.
-"at #ill t"e follo#ing $rogram fragment out$utE
void foo(int $)
{
int % = &;
$ = 10;
cout << $ << " " << %;
}
int main()
{
int $=2, %=3;
foo($);
cout << $ << " " << %;
return 0;
}
10 4 2 3
-"at is t"e out$ut of t"e follo#ing $rogramE
int a. ). c@ a 7 12@ ) 7 22@ c 7 42@
figureMeFut*a. ). c+@
cout 88 a 88 G G 88 ) 88 G G 88 c 88 endl@
return 2@ >
void figureMeFut*intH x. int y. intH I+
= cout 88 x 88 G G 88 y 88 G G 88 I 88 endl@
x 7 1@ y 7 2@ I 7 4@
cout 88 x 88 G G 88 y 88 G G 88 I 88 endl@ >
4- %- 1-
4 % 1

You might also like