0% found this document useful (0 votes)
18 views1 page

Programming2 Midterm

Uploaded by

c.zikocherki
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)
18 views1 page

Programming2 Midterm

Uploaded by

c.zikocherki
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/ 1

Name, Surname :

Number :
Course Code : SWE102
Course Name : Computer Programming II
Exam : ●Midterm ◌ Make-up ◌ Final
Date :

Please make sure to write your name and student number on each paper that you have used

Question Number 1[40p] 2[10p] 3[20p] 4[30p] Total

Mark

Note: To solve the questions, using any resources(phone,computer, internet, your notes, books ,friends,... etc. ) are NOT ALLOWED . The Midterm effect %20
of total grade

4-[30p] Explain the code according to comment line shown


---------------------------------------------- below. The Explanation must contain the flows of the code.
1-[40p] Write a C function that returns the sum of the Only Line by line code explanations are Not acceped!!.
following series for n terms(x(double) and n(int) are Only General explanations are NOT accepted. Write screen
function parameters) output[5p] and explain how the code works!!.
𝑥2 𝑥3 𝑥4 𝑥𝑛 Explain the code with real example.
𝑆 = 𝑥 + + + + ⋯…+ DO NOT TEST THE CODE IN COMPUTER!!
2 3 4 𝑛 ----------------------------------------------
#include <stdio.h>
[a-Do not use math.h library. For example, If you need to //Prototypes
calculate power of number, write your own function! void q1(int a, int b);
b-Clue: you need one another function to calculate the void q2(int a[ ], int b[ ]);
power void q3(int *a, int *b);
c-make it with functions otherwise you will get zero int main(){
point] //20051XYZT This is your student number, Put real numbers
//instead of X,Y,Z,T numbers
---------------------------------------------- int a[2] = {X, Y};
2-[10p]Write a C function function that calculate the int b[2] = {Z, T};
flowing formula(R,n,S (double) are input V(double) output q1(a[0], b[1]);
and returning value of function) q2(a, b);
q3(&b[0], &a[1]);
1 2⁄ printf("%d, %d, %d, %d \n", a[0], a[1], b[0], b[1]);
𝑉= 𝑅 3 . √𝑆 return 0;}
𝑛 //functions
[a-you can use math.h library] void q1(int a, int b){
int temp = a;
---------------------------------------------- if(a%2==0){a = b;}else{a=b+2;}
3-[20p] Give an example of “struct”,”typedef” and explain b = temp;}
them. void q2(int a[ ], int b[ ]){
[Do not use same examples given before in the lecture ] int temp = a[0];
if(a[0]%2==0){a[0] = b[0]+a[1];}else{a[0]=b[0]+2;}
b[0] = temp;}
void q3(int *a, int *b){
int temp = *a;
*a = *b;
*b = temp;}
----------------------------------------------

You might also like