Arrays, Functions and Strings LAB
Arrays, Functions and Strings LAB
Ureta
BSCS 1A
1.) Give the output of the program and show the process on how the output
values were derived (conversion process and shifts).
30 = 11110
40 = 101000
40 >> 4 = 000010 = 2
// to right shift digits, add zero prefixes and eliminate bits from the right side each time you
do so.
Output:
2.) Create a program to compute sum of array elements of three (3) matrices
(2x2x2). Program must accept input (elements) and displays the sum.
#include<stdio.h>
int main(){
int array1[2][2][2], array2[2][2][2], array3[2][2][2];
int sumarray[2][2][2];
return 0;
}
Erlein Nicole B. Ureta
BSCS 1A
Output:
3.) Type the source code in your editor. Try out the program a few times to
ensure that it accepts only hello as the proper password. Next, eliminate the
match variable from your code and use the strcmp() function directly in the if
comparison. That is how most programmers do it. Then, replace the strcmp()
function with strcasecmp(). Run the program to confirm that both hello and
HELLO are accepted as the password.
#include
int main() {
char password[]="hello";
char input[15];
int match;
printf("Password: ");
scanf("%s",input);
match=strcmp(input,password);
if(match==0){
puts("Password accepted.");
Erlein Nicole B. Ureta
BSCS 1A
}
else {
puts("Invalid password!"); return(0);
}
STEP 2: Eliminate the match variable from your code and use the strcmp() function directly
in the if comparison.
#include<stdio.h>
#include <string.h>
int main(){
char password[] = {"hello"};
char input[15];
printf("Password: ");
scanf("%s", input);
if(strcmp(input,password) == 0){
puts("Password accepted.");
}
else {
puts("Invalid password!");
}
return 0;
}
#include<stdio.h>
#include <string.h>
int main(){
char password[] = {"hello"};
char input[15];
Erlein Nicole B. Ureta
BSCS 1A
printf("Password: ");
scanf("%s", input);
if(strcasecmp(input,password) == 0){
puts("Password accepted.");
}
else {
puts("Invalid password!");
}
return 0;
}
Output:
#include<stdio.h>
#include<conio.h>
int main(){
int size;
int array[10];
printf("Enter number of value in the array: ");
scanf("%d", &size);
testdata(array, size);
}
big = array[0];
for(int j = 1; j < size; j++){
if(big < array[j]){
big = array[j];
}
}
small = array[0];
for(int i = 1; i < size; i++){
if(small > array[i]){
small = array[i];
}
}
printf("\nThe minimum value is %d", small);
Output: