C Da 2 - Removed
C Da 2 - Removed
Digital Assignment
Submitted by
Full Name: Sudarshan Ravindran
AIM
1. To find the largest number in an array.
2. To move all zeros to the end.
SOFTWARE
Any C compiler or Code blocks.
ALGORITHM:
1. Open your preferred IDE and start a new project.
2. Create a new C source file.
3. Add the file to your project.
4. Write the C program code.
5. Save your work.
6. Compile or build the project.
7. Debug and resolve any errors.
8. Execute the program.
9. Test it with different inputs.
10. Make modifications if needed.
CODE:
#include <stdio.h>
void main() {
int a[10], max, n, i;
max = a[0];
SIMULATION:
2. To move all zeros to the end.
CODE:
#include <stdio.h>
void main() {
int a[10], max, i, n;
int b[n], j = 0;
SIMULATION:
MANUAL CORRECTION:
RESULT:
The C program using sequential statements was successfully written, compiled, and
executed.
EXPERIMENT
NO: 2B
REG.NO:22BEE03
D ATE: 06.02.2025
AIM:
1. To count the number of vowels in a string
2. To count the number of p in a string
3. To take two strings and update the alternate characters
4. To take a string and copy the string only till M occurs
SOFTWARE
Any C compiler or Code blocks.
ALGORITHM:
1. Start a new project in your preferred IDE.
2. Create a new C source file
3. Add the new file to the project
4. Write your C program code
5. Save the file
6. Build or compile the project
7. Fix any errors
8. Run or execute the program
9. Test the program with various inputs
10. Modify the code if necessary
int main() {
char str[10];
int count = 0, i;
printf("Enter a string: ");
scanf("%s", str);
int main() {
char str[10];
int count = 0, i;
CODE:
#include <stdio.h>
#include <string.h>
int main() {
char str1[100], str2[100];
updateAlternateChars(str1, str2);
CODE:
#include <stdio.h>
int main() {
char str[100], newStr[100];
int i;
Aim:
I. To get the status of bit P1.0, save it in bit addressable area, and send it to P2.7
continuously.
II. To perform basic logical operations (AND, OR, XOR, NOT, left shift, right shift).
III. To monitor the door sensor, and when it opens, sound the buzzer. You can sound the
buzzer by sending a square wave of a few hundred Hz.1 The door sensor is connected
to P1.1 pin and a buzzer is connected to P1.7 pin.
IV. To convert unpacked BCD to packed BCD & display the bytes on P1.
V. To calculate the checksum byte for the given data 0x25, 0x3C, 0x45 & 0x98.
Algorithm:
I. Reading a Bit, Storing, and Transferring to Another Bit
1. Start execution.
2. Configure P1.0 as an input pin.
3. Set P2.7 as an output pin.
4. Declare a bit variable in the bit-addressable area.
5. Enter an infinite loop: o Read the state of P1.0. o Store the read value in the bit variable.
o Assign the stored value to P2.7.
6. Repeat continuously.
7. Stop execution. II. Performing Basic Logic Operations
8. Start the process.
9. Declare two variables, A and B, with predefined values.
10.Execute the following operations: o AND: P0 = A & B o OR: P1 = A | B o XOR: P2 =
A^ B o NOT: P0 = ~A and P0 = ~B o Left Shift: P1 = A << n (Shift A left by n bits) o
Right Shift: P2 = A >> n (Shift A right by n bits)
11.Store or display the results.
12.Stop execution. III. Monitoring a Door Sensor and Activating a Buzzer
13.Begin execution.
14.Configure P1.1 as an input (Door Sensor) and P1.7 as an output (Buzzer).
15.Continuously check P1.1: o If P1.1 is HIGH (Door Open): ▪ Generate a square wave on
P1.7 by toggling it HIGH and LOW at a few hundred Hz with a small delay. o If P1.1 is
LOW (Door Closed): ▪ Keep P1.7 LOW (Buzzer OFF).
16.Repeat the process indefinitely.
17.Stop execution when required. IV. Converting Unpacked BCD to Packed BCD
18.Start execution.
19.Configure Port P1 as an output.
20.Input two unpacked BCD digits, x and y (each in 0x0X format).
21.Convert the unpacked BCD to packed BCD: o Left shift x by 4 bits: x = x << 4. o
Combine x and y using the OR operation: u = x | y.
22.Output the packed BCD value to P1.
23.Stop execution. V. Computing a Checksum Byte
24.Start execution.
25.Configure Port P1 as an output.
26.Initialize four data bytes: o A = 0x25, B = 0x3C, C = 0x45, D = 0x98.
27.Calculate the sum: Sum = A + B + C + D.
28.Compute the 2’s complement checksum: o Invert all bits: Checksum = ~Sum. o Add 1 to
the result: Checksum = Checksum + 1.
29.Output the checksum value to P1.
30.Stop execution.
Program:
Output:
Conclusion:
By conducting these experiments, we gained deeper insights into bitwise operations, sensor
interfacing, data formatting, and error detection. These fundamental concepts are crucial for
efficient data processing and real-time embedded system applications, enhancing our ability
to design and optimize reliable embedded solutions.