test1_sept_2014_FI_1_eng_SOLUTION.pdf

# test1_sept_2014_FI_1_eng_SOLUTION.pdf - Fundamentals of...

• Test Prep
• 5

This preview shows 1 out of 3 pages.

Fundamentals of Computer Science Test 1 Sept-2014 1º IEM, ITL Sept/2014 1 First Name: Last name: Group: FI_1 ATTENTION: THE STUDENT MUST FILL OUT HIS NAME ON ALL THE PAGES 1. Duration: 50 min. 2. Use of pencil is permitted. 3. Use of the sentences exit, continue, break (apart from its use in switch) is not permitted. Program 1 (4 pts) Program 2 (6 pts) Total Program-1(4 points) Write a full program to calculate the following series: 1 / (1!) + 3 / (2!) + 5 / (3!) + 7 / (4!) + 9 / (5!) + … Initially, you must ask the user to introduce the number of terms to be added (validate to check it is a positive number) Then, the program must calculate and add this number of terms Finally, the program will display on the monitor the result of the series. /*test-1 Problem 1 , series */ #include <stdio.h> int main(void) { int n; //number of terms int i; float sum; //series float term; float fact; //factorial do{ printf("\nNumber of terms: "); scanf("%d",&n); if(n<=0){ printf("\nError, it has to be positive"); } }while(n<=0);

Subscribe to view the full document.

Fundamentals of Computer Science Test 1 Sept-2014 1º IEM, ITL Sept/2014 2 sum=0.0; fact=1.0; for(i=1;i<=n;++i){ fact*=i; /*or it could be another loop*/ term=(2*i-1)/fact; sum+=term; } printf("\n\nThe series for %d number of terms is %f\n",n,sum); return 0; }
You've reached the end of this preview.
• Fall '16
• ITL