



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The autumn semester 2011-12 phy225 programming in c examination paper. It includes instructions for the exam, five programming questions, and a continuation page. Students are required to answer all questions and write their answers in their answer booklets. The document also includes a pause command at the end.
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!




Autumn Semester 2011-
Answer ALL questions
There are a total of 50 marks to be awarded for this paper. The breakdown on the right-hand side of the paper is meant as a guide to the marks that can be obtained from each part of the question.
Please write all answers to questions in your answer booklet and not on the examination paper.
b) What is a relational operator? Give an example of one.
c) What is the purpose of a function prototype?
d) In the statement int main(void) what does (void) signify?
e) How does the atan2() function differ from the atan() function?
f) What does the strcmp() function do?
#include <stdio.h> #include <stdlib.h>
int main(void) { double r=333.45,s=3.4e-2,t=1.008,u=152.5; int i=34,j=-34,k=808,l=5034 2 ,m=0;
r = (t+r*s/u-u/r); s = s+u/t+r/t-r; t = --u; u = sqrt(abs(r-t/s)); k = (i/j)u; l += k-(i%l)j; m *= i;
printf (“r: %f s: %f t: %f u: %f\n”,r,s,t,u); printf (“k: %d l: %d m: %d\n”,k,l,m);
system(“pause”); return 0; }
#include<stdlib.h> #include<stdio.h>
int main(void) { int i=9, j=1; while (i>0) { if (i%3) { j+=i; j*=i; i--; } else if (i%5) i--; i--; printf("i: %d j: %d\n",i,j); }
system("pause"); return 0; }
CustomerSurname (character string, maximum 20 characters) CustomerNumber (integer, up to 10 digits) CurrentMeterReading (integer, up to 6 digits) LastBill (amount in pounds and pence)
A typical customer record would thus look like:
Brown 4382910395 001789 142.
Ben’s program is incomplete. So far it looks like this:
#include<stdlib.h> #include<stdio.h> #include<math.h>
//TODO I need to define my structure here
int main(void)
{ int NUM_CUSTOMERS; printf(“Enter the number of customers:”); scanf(“%d”,NUM_CUSTOMERS);
//TODO I need to define my array of structures here
FILE* database;
if((database = fopen("customers.db", "r"))==NULL) { printf("Could not open database file”); return 1; }
for(i=0; i<NUM_CUSTOMERS; ++i) {
//TODO This is where my fscanf command goes
} fclose(database); system(“pause”); return(0);
}