Capusi_JohnPatrick_MachineProblem1
Capusi_JohnPatrick_MachineProblem1
Data Structure
Machine Problem # 1
By
20-1529-248
BSCS – J2S
September 3, 2021
Laboratory Machine Problem #1:
Objective(s)
Program
Write an array program to input a customer lastname, firstname, mi, extension name (if applicable)
and display it on one single line.
Algorithm
1. Start
5. Print the last name, first name and middle initial in one line
6. Stop
Flowchart
#include <stdio.h> //required to get input from input devices and show output on output screen of
C Program.
int main (){ //indicates that the main() can return integer type data
printf("Full Name: %s %s %s", lastName, firstName, middleInitial); // Display the final output
return 0;
SAMPLE PROGRAMS
(Students are to code the following programs in the laboratory and must show the output to
instructor).
Machine Problem #1 - Array Implementation
Objective(s)
1. To recall program development in C environment
2. To show the output of the given problem
Program
Determine how many array number larger than 10 are inputted by the users.
Algorithm
1. Start
6. If a > size
8. Stop
Flowchart
#include <stdio.h> // required to get input from input devices and show output on output
screen of C Program.
int main(){ // indicates that the main() can return integer type data
int larger = 10, loop[20], a; //Declaring integer variables
printf("How many array number larger than 10 \n"); // Display text
printf("Input any numbers \n"); // Display text
for( a = 0; a < 10; a++) //looping statement where in user asks to enter 10 numbers
scanf("%d", &loop[a]); //input element/numbers
printf("Array elements number that greater than %d are \n", larger); //Display text and array
elements
// Greater than 10 for loop
for( a = 0; a < 10; a++) // loop statement to check the inputted numbers
{
if(loop[a] > larger) // Condition statement that will check if element is greater that 10
printf("%d ", loop[a]); // Display elements who’s greater than 10
}
return 0; // End of the program
}
SAMPLE PROGRAMS
(Students are to code the following programs in the laboratory and must show the output to
instructor).
Machine Problem #1 - Array Implementation
Objective(s)
1. To recall program development in C environment
2. To show the output of the given problem
Program
Detect an input value inputted by end- user, if the user input 0, program will exit and
determine the number of list an array have together with the number of its elements,
otherwise number will placed in an array "lessthan10".
Algorithm
1. Start
5. Input integer
10. Stop
Flowchart
Code: (Use comments wherever applicable)
#include <stdio.h> // required to get input from input devices and show output on output screen
of C Program.
int main(){ // indicates that the main() can return integer type data
int a[1000],i,j,n=1000; // Integer Declaration and array
int* point=a; // Pointer Declaration
printf("Enter elements in the array enter 0 to exit \n"); // Display text
for(i=0;i<n;i++){ // for looping to user input
scanf("%d", &a[i]); // Input number
if(a[i]==0){ // if statement to terminate the loop
break; // break statement
}
}
printf("\nElements in array are: "); // Display text
for(j=0;j<i;j++){ // For loop to display all the input number
if (a[j]<10){ // if else statement to check if its less than or greater than
printf("\nThe Array is less than 10: %d", a[j]); // Display text and the int
}else{ // else statement
printf("\nThe Array is greater than 10: %d", a[j]); // Display text and the int
}
}
return 0; // End of the program
}
Objective(s)
1. To recall program development in C environment
2. To show the output of the given problem
Program
Determine if the string inputted in an array list is a palindrome or not.
Algorithm
1. Start
5. Input string
9. Stop
Flowchart
Code: (Use comments wherever applicable)
#include <stdio.h>// required to get input from input devices and show output on output
screen of C Program.
int main(){ // indicates that the main() can return integer type data
char text[20]; // Char array declaration
int loop, length, value = 0; // Declaring integer variables
printf("Enter a string: "); // Display enter string
scanf("%s", text); // Input string
length = strlen(text); // Check the length of string
for(loop=0; loop < length ; loop++){ // for looping for checking
if(text[loop] != text[length - loop - 1]){ // if statement wherein it will check the string, and see
if it is still the
//same when reversed
value = 1; //value will be 1 if true
break; // Break statement
}
}
SAMPLE PROGRAMS
(Students are to code the following programs in the laboratory and must show the output to
instructor).