You are on page 1of 12

College of Science and Computer Studies

(+6346) 416-4524 (+632) 8447832 local 3073


www.dasma.dlsu.edu.ph

COMPUTER FUNDAMENTALS &PROGRAMMING 1


(COMP 805L)
FINAL PROJECT

Machine Problem Set I

Submitted by:
Pascual, Michael Angel B.
Medina, Dan Esjay
Monzales, Christian Paul

Submitted to:
Ms. Azenith Rollan- Mojica

October 13, 2015

discovering. inventing. nurturing.

College of Science and Computer Studies

(+6346) 416-4524 (+632) 8447832 local 3073


www.dasma.dlsu.edu.ph

Introduction about the C Language

What is C?

C is a computer programming language. That means that you can use C


to create lists of instructions for a computer to follow. C is one of thousands of
programming languages currently in use. C has been around for several decades
and has won widespread acceptance because it gives programmers maximum
control and efficiency. C is an easy language to learn. It is a bit more cryptic in its
style than some other languages, but you get beyond that fairly quickly.

C is what is called a compiled language. This means that once you write
your C program, you must run it through a C compiler to turn your program into an
executable that the computer can run (execute). The C program is the humanreadable form, while the executable that comes out of the compiler is the machinereadable and executable form. What this means is that to write and run a C
program, you must have access to a C compiler (Brain, n.d.).

C is an imperative (procedural) language. It was designed to be compiled


using a relatively straightforward compiler, to provide low-level access to memory,
to provide language constructs that map efficiently to machine instructions, and to
require minimal run-time support. C was therefore useful for many applications that
had formerly been coded in assembly language, such as in system programming.

discovering. inventing. nurturing.

College of Science and Computer Studies

(+6346) 416-4524 (+632) 8447832 local 3073


www.dasma.dlsu.edu.ph

Despite its low-level capabilities, the language was designed to encourage


cross-platform programming. A standards-compliant and portably written C program
can be compiled for a very wide variety of computer platforms and operating
systems with few changes to its source code. The language has become available on
a very wide range of platforms, from embedded microcontrollers to supercomputers.

C was originally developed by Dennis Ritchie between 1969 and 1973 at AT&T
Bell Labs, and used to re-implement the UNIX operating system. It has since
become one of the most widely used programming languages of all time, with
C compilers from various vendors available for the majority of existing computer
architectures and operating systems. C has been standardized by the American
National Standards Institute (ANSI) since 1989 and subsequently by
the International Organization for Standardization (ISO) (C programming language,
2015).

Programming Questions
1. Write a program that will display a pattern depending on n. Assume n as a one
digit odd number.
Example: if n = 9, display
*000*000*
0*00*00*0
00*0*0*00
000***000

discovering. inventing. nurturing.

College of Science and Computer Studies

(+6346) 416-4524 (+632) 8447832 local 3073


www.dasma.dlsu.edu.ph

2. Given an input n assumed one-digit, display a pattern.


Example: if n = 4, display
1
2
3
4

1
2

1
2

3. Write a program that reads in a number n, and then reads in n numbers. The
numbers will be alternately added and subtracted.
Example: if n = 5 and the numbers entered are 4, 14, 5, 6, 1
Then compute for 4 + 14 5 + 6 1 = 18

discovering. inventing. nurturing.

College of Science and Computer Studies

(+6346) 416-4524 (+632) 8447832 local 3073


www.dasma.dlsu.edu.ph

Hardcopy of the Program


1.
#include<stdio.h>
main()
{
int n, v, w, x, y, z;
clrscr();

printf("Set I, no. 1\n\n");


printf("Enter a number (n)\n");
printf("Note that it must only be a one-digit positive odd number.\n\n");
printf("n = ");
scanf("%d", &n);
printf("\nDisplay:\n\n");
if((n>=10)||(n<=0)||(n%2==0))
{
printf("Error! Enter only a one-digit positive odd number.\n");
printf("Please try again.\n");
printf("Thank you :)");
}

else
{
for (x=n;x>=n-(x-2); x--)
{
for (z=1; z<=n-x; z++)
{
printf("0");
}
for (y=1; y<=1; y++)
{
printf("*", y);
}
for (w=((n-3)/2)-z+1; w>=1; w--)
{
printf("0");
}
for (v=1; v<=1; v++);
{
printf("*");
}
for (w=((n-3)/2)-z+1; w>=1; w--)
{
printf("0");
}
for (y=1; y<=1; y++)
{
printf("*", y);
}
for (z=1; z<=n-x; z++)
{
printf("0");
}
printf("\n");
}
}
getch();

discovering. inventing. nurturing.

College of Science and Computer Studies

(+6346) 416-4524 (+632) 8447832 local 3073


www.dasma.dlsu.edu.ph

2.
#include<stdio.h>
main()
{
int n, x, y, z;
clrscr();
printf("Set I, no. 2\n\n");
printf("Enter a number (n)\n");
printf("Note that it must only be a one-digit positive number.\n\n");
printf("n = ");
scanf("%d", &n);
printf("\nDisplay:\n\n");
if((n>=10)||(n<=0))
{
printf("Error! Enter only a one-digit positive number.");
printf("\nPlease try again.");
printf("\nThank you. :)");
}

else
{
for (x=1;x<=n; x++)
{
for (z=1; z<=n-x; z++)
{
printf(" ");
}
for (y=x; y>=1; y--)
{
printf(" %d", y);
}
printf("\n");
}
}
getch();

discovering. inventing. nurturing.

College of Science and Computer Studies

(+6346) 416-4524 (+632) 8447832 local 3073


www.dasma.dlsu.edu.ph

3.
#include<stdio.h>
main()
{
int n, a[10000], x, sum=0,dif=0, ans;
clrscr();

printf("Set I, no. 3\n\n");


printf("Enter a number (n)");
printf("\nNote that it must only be a positive number.\n\n");
printf("n = ");
scanf("%d", &n);
printf("\n");
if(n<=0)
{
printf("\nError! Enter only positive number.");
printf("\nPlease try again.");
printf("\nThank you. :)");
}
else
{
printf("\nEnter %d numbers. \n", n);
printf("Note that it will be alternately added and subtracted.\n\n");
for(x=1; x<=n; x++)
{
scanf("%d", &a[x]);
{
if (x==1||x%2==0)
sum=sum+a[x];
else
dif=dif-a[x];
}
ans=sum+dif;
}
printf("\nComputing for %d ",a[1]);
for(x=2;x<=n;x++)
{
if(x%2==0)
{
printf("+ %d ",a[x]);
}
else
{
printf("- %d ",a[x]);
}
}
printf("= %d", ans);
printf("\nTherefore, the answer is %d.", ans);
}
getch();

discovering. inventing. nurturing.

College of Science and Computer Studies

(+6346) 416-4524 (+632) 8447832 local 3073


www.dasma.dlsu.edu.ph

Sample output for each program (3 screens for each output)


1.

discovering. inventing. nurturing.

College of Science and Computer Studies

(+6346) 416-4524 (+632) 8447832 local 3073


www.dasma.dlsu.edu.ph

2.

discovering. inventing. nurturing.

College of Science and Computer Studies

(+6346) 416-4524 (+632) 8447832 local 3073


www.dasma.dlsu.edu.ph

discovering. inventing. nurturing.

College of Science and Computer Studies

(+6346) 416-4524 (+632) 8447832 local 3073

3.

www.dasma.dlsu.edu.ph

discovering. inventing. nurturing.

College of Science and Computer Studies

(+6346) 416-4524 (+632) 8447832 local 3073


www.dasma.dlsu.edu.ph

References
Brain, M. (n.d.). The basics of C programming. Retrieved October 11, 2015 from
http://computer.howstuffworks.com/c1.htm
C programming language . (2015). In Wikipedia. Retrieved October 11, 2015 from
https://en.wikipedia.org/wiki/C_(programming_language)

discovering. inventing. nurturing.

You might also like