0% found this document useful (0 votes)
342 views

Pre-Final Exam in Computer Programming

This document contains a pre-final examination for a Computer Programming 1 course taken by Jeva Sanchez for their BSIT degree. The exam consists of two tests - the first involves writing for loops to print various numeric sequences, and the second involves writing programs to find the smallest and largest numbers from a set of user-input integers and to print a diamond shape using nested for loops based on a user-input number of rows. Sample code is provided as answers for the tasks.

Uploaded by

Yheva Sanchez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
342 views

Pre-Final Exam in Computer Programming

This document contains a pre-final examination for a Computer Programming 1 course taken by Jeva Sanchez for their BSIT degree. The exam consists of two tests - the first involves writing for loops to print various numeric sequences, and the second involves writing programs to find the smallest and largest numbers from a set of user-input integers and to print a diamond shape using nested for loops based on a user-input number of rows. Sample code is provided as answers for the tasks.

Uploaded by

Yheva Sanchez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PRE-FINAL EXAMINATION

COMPUTER PROGRAMMING 1
Degree/Program: BSIT, BSCS, ACT
1ST SEMESTER S.Y: 2021-2022

Name: Jeva Sanchez BSIT

Test I. WRITING STATEMENTS


Direction: Write for statements that print the following sequences of values: (6 pts each)
1. 1, 2, 3, 4, 5, 6, 7
Answer:
#include <stdio.h>
#include <stdlib.h>
Int main
(int argc, char *argv[])
{
Int I;
For(i=1;i<=7;i=i+1)
Printf(“%d\n”,i);

Return 0;

2. 3, 8, 13, 18, 23
Answer:
#include<stdio.h>
#include<conio.h>
Int main()
{
Int I;
For(i=3;i<=23;i=i+5)
Printf(“%d\n”,i);

Return 0;
}
3. 20, 14, 8, 2, –4, –10
Answer:
#include<stdio.h>
#include<conio.h>

Int main()
{
Int I;
For(i=20;i>=-10;i=i-6)
Printf(“%d\n”,i);

Return 0;
}
4. 19, 27, 35, 43, 51
Answer:
#include<stdio.h>
#include<conio.h>

Int main()
{
Int I;
For(i=19;i<=51;i=i+8)
Printf(“%d\n”,i);

Return 0;
}
5. 10,20,30,40,50
Answer:
#include<stdio.h>
#include<conio.h>

Int main()
{
Int I;
For(i=10;i<=50;i=i+10)
Printf(“%d\n”,i);

Return 0;
}

TEST II. PROGRAMMING (15 points each)


1. (Find the Smallest and largest)Using for loop, write a program that will let you enter 10
integers and will find the smallest and the largest of several integers. Assume that the first value
read specifies the number of values remaining.
Answer:
2. (Modified Diamond Printing Program) Using nested for loop, Write a program that prints the
following diamond shape. You may use printf statements that print either a single asterisk (*) or
a single blank. Maximize your use of repetition (with nested for statements) and minimize the
number of printf statements. Modify the program you wrote to read an odd number in the range 1
to 19 to specify the number of rows in the diamond. Your program should then display a
diamond of the appropriate size. Below is an example of diamond printing.
Answer:
#include<stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system(“pause”) or input
loop */

Int main(int argc, char *argv[])


{
Int num,I,j;
Printf(“Enter number of lines:”);
Scanf(“%d”,&num);
Int stars=1,space=num/2;
While(stars<=num)
{
For(i=0;i<space;i++)
Printf(“ “);
For(j=0;j<stars;j++)
Printf(“*”);
Printf(“\n”);
Stars=stars+2;
Space--;
}
Stars=stars-2;
Space++;
While(stars>=1)
{
For(i=0;i<space;i++)
Printf(“ “);
For(j=0;j<stars;j++)
Printf(“*”);
Printf(“\n”);
Stars=stars-2;
Space++;
}
}

You might also like