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

Capusi_JohnPatrick_MachineProblem1

The document outlines a series of machine problems for a Data Structure course at the University of Perpetual Help System – Laguna, focusing on programming in C. It includes objectives, algorithms, and sample code for tasks such as inputting and displaying customer names, determining array elements greater than 10, and checking if a string is a palindrome. Each problem requires students to implement the code and demonstrate the output to an instructor.

Uploaded by

edzroogaming041
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Capusi_JohnPatrick_MachineProblem1

The document outlines a series of machine problems for a Data Structure course at the University of Perpetual Help System – Laguna, focusing on programming in C. It includes objectives, algorithms, and sample code for tasks such as inputting and displaying customer names, determining array elements greater than 10, and checking if a string is a palindrome. Each problem requires students to implement the code and demonstrate the output to an instructor.

Uploaded by

edzroogaming041
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

University of Perpetual Help System – Laguna

College of Computer Studies

Data Structure

Machine Problem # 1

By

John Patrick D. Capusi

20-1529-248

BSCS – J2S

September 3, 2021
Laboratory Machine Problem #1:

Objective(s)

1. To recall program development in C environment


2. To show the output of the given problem

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

2. Input first name

3. Input middle initial

4. Input last name

5. Print the last name, first name and middle initial in one line

6. 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.

#include <string.h> // importing the capabilities of manipulating strings

int main (){ //indicates that the main() can return integer type data

char firstName[30], middleInitial[4], lastName[30]; // Char declaration

printf ("Enter your First Name: "); // Print

scanf("%[^%s\n]", firstName); // Input first name


printf ("Enter your Middle Initial: "); // Print

scanf("%s", middleInitial); // Input middle initial

printf ("Enter your Last Name: "); // Print

scanf("%s", lastName); // Input last name

printf("Full Name: %s %s %s", lastName, firstName, middleInitial); // Display the final output

return 0;

// End of the program

Output: (print screen the output)

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

2. Declare int size = 10, int a[20], int I;

3. Check FOR condition

4. Print “Input any numbers “

5. Check if a < 10 back to step 5

6. If a > size

7. Display elements who’s greater than 10

8. 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 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
}

Output: (print screen the output)

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

2. Declare int a[1000],i,j,n=1000;

3. Declare int* point=a;

4. Print " Enter elements in the array enter 0 to exit "

5. Input integer

6. If the number is not 0 jump to step 5

7. Check if the inputted number is less than or greater than to 10

8. If yes display The Array is greater than 10:

9. If no display The Array is less than 10:

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
}

Output: (print screen the output)


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 if the string inputted in an array list is a palindrome or not.
Algorithm
1. Start

2. Declare char text[20];

3. Declare int loop, length, value = 0;

4. Print "Enter a string: "

5. Input string

6. Check if the string is palindrome or not palindrome

7. If yes display is a palindrome

8. If no display is not a palindrome

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
}
}

if (value == 1) { // if condition statement


printf("%s is not a palindrome",text); // Display text and char text
}
else { // else condition statement
printf("%s is a palindrome",text); // Display text and char text
}

return 0; //End of the program


}
Output: (print screen the output)

SAMPLE PROGRAMS
(Students are to code the following programs in the laboratory and must show the output to
instructor).

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy