Cp Programming
Cp Programming
REGISTER NUMBER:243115104062
PROGRAM:
#include <stdio.h>
int main() {
// Calculating areas
a1 = l * b; // Area of rectangle
return 0;
OUTPUT:
REGISTER NUMBER:243115104062
PROGRAM:
#include <stdio.h>
int main() {
int num1, num2, num3;
printf("Enter three numbers: ");
scanf("%d %d %d", &num1, &num2, &num3);
if (num1 >= num2 && num1 >= num3) {
printf("The greatest number is: %d\n", num1);
} else if (num2 >= num1 && num2 >= num3) {
printf("The greatest number is: %d\n", num2);
} else {
printf("The greatest number is: %d\n", num3);
}
return 0;
}
OUTPUT:
Enter three numbers: 12 45 27
The greatest number is:45
Department: CSE-B MSEC R2024
PAGE NO
Meenakshi Sundararajan Engineering College
(An Autonomous Institution, Affiliated to Anna University, Chennai)
U24CS101 - Programming in C - Laboratory Component
REGISTERNUMBER: 243115104062
PROGRAM:
#include <stdio.h>
int main() {
int num, i;
printf("\nEnter the number: ");
scanf("%d", &num);
printf("\nPrint first %d natural numbers:\n", num);
for (i = 1; i <= num; i++) {
printf("%d\n", i);
}
return 0;
}
OUTPUT:
Print first 10 natural numbers
1
2
3
4
5
6
7
8
9
10
Department: CSE-B MSEC R2024
PAGE NO
Meenakshi Sundararajan Engineering College
(An Autonomous Institution, Affiliated to Anna University, Chennai)
U24CS101 - Programming in C - Laboratory Component
REGISTERNUMBER:
{
int pin = 1234; // Predefined PIN
int enteredPin, option;
double balance = 1000.00; // Initial balance
double amount;
if (enteredPin != pin) {
printf("Incorrect PIN. Access denied.\n");
return 1; // Exit the program
}
do {
printf("\nATM Menu:\n");
printf("1. Check Balance\n");
printf("2. Deposit Money\n");
printf("3. Withdraw Money\n");
REGISTERNUMBER: 234115104062
printf("4. Exit\n");
printf("Select an option (1-4): ");
scanf("%d", &option);
switch (option) {
case 1: // Check Balance
printf("Your current balance is: $%.2f\n", balance);
break;
REGISTERNUMBER: 234115104062
balance -= amount;
printf("You have successfully withdrawn: $%.2f\n", amount);
}
else if (amount > balance) {
printf("Insufficient balance.\n");
}
else {
printf("Invalid withdrawal amount.\n");
}
break;
case 4: // Exit
printf("Thank you for using the ATM. Goodbye!\n");
break;
default:
printf("Invalid option. Please select a valid option (1-4).\n");
}
} while (option != 4); // Continue until the user chooses to exit
return 0;
}
OUTPUT:
REGISTERNUMBER: 234115104062
ATM Menu:
1. Check Balance
2. Deposit Money
3. Withdraw Money
4. Exit
Select an option (1-4): 2
Enter amount to deposit: $500
You have successfully deposited: $500.00
ATM Menu:
1. Check Balance
2. Deposit Money
3. Withdraw Money
4. Exit
Select an option (1-4): 4
Thank you for using the ATM. Goodbye!
RESULT:
The program for ATM stimulation was successfully executed and the output was
verified.
REGISTER NUMBER:243115104062
PROGRAM:
#include <stdio.h>
int main() {
scanf("%d", &n);
int arr[n];
scanf("%d", &arr[i]);
scanf("%d", &target);
if (arr[i] == target) {
if (!found) {
return 0;
OUTPUT:
Enter the number of elements in the array: 5
Enter 5 elements:
10 20 30 40 50
REGISTER NUMBER:243115104062
PROGRAM:
#include <stdio.h>
int main() {
int r1, c1, r2, c2;
REGISTER NUMBER:243115104062
REGISTERNUMBER: 234115104062
PROGRAM:
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int len;
return 0;
}
OUTPUT:
Enter a string: Hello
The length of the string "Hello" is: 5
REGISTERNUMBER: 234115104062
PROGRAM:
#include <stdio.h>
#include <string.h>
int main() {
char str1[100], str2[100];
OUTPUT:
Enter the first string: Hello
Enter the second string: World
The concatenated string is: HelloWorld
REGISTERNUMBER: 234115104062
PROGRAM:
#include <stdio.h>
#include <string.h>
int main() {
char str1[100], str2[100];
return 0;
}
OUTPUT:
Enter a string: Hello
The copied string is: Hello
REGISTERNUMBER: 234115104062
PROGRAM:
#include <stdio.h>
#include <string.h>
int main() {
char str1[100], str2[100];
return 0;
}
OUTPUT:
Enter the first string: hello
Enter the second string: hello
The strings are equal.
REGISTERNUMBER: 234115104062
PROGRAM:
#include <stdio.h>
#include <string.h>
#define MAX_USERS 5
// Function declarations
int authenticateUser();
void displayMenu();
void checkBalance(int userIndex);
void deposit(int userIndex);
void withdraw(int userIndex);
int main() {
int userIndex = authenticateUser();
if (userIndex == -1) {
printf("Authentication failed. Exiting...\n");
return 0; // Exit the program if authentication fails
Department: CSE-B MSEC R2024
PAGE NO
Meenakshi Sundararajan Engineering College
(An Autonomous Institution, Affiliated to Anna University, Chennai)
U24CS101 - Programming in C - Laboratory Component
REGISTERNUMBER: 234115104062
}
int choice;
while (1) {
displayMenu();
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
checkBalance(userIndex);
break;
case 2:
deposit(userIndex);
break;
case 3:
withdraw(userIndex);
break;
case 4:
printf("Thank you for using the ATM. Goodbye!\n");
return 0;
default:
printf("Invalid choice. Please try again.\n");
}
}
Department: CSE-B MSEC R2024
PAGE NO
Meenakshi Sundararajan Engineering College
(An Autonomous Institution, Affiliated to Anna University, Chennai)
U24CS101 - Programming in C - Laboratory Component
REGISTERNUMBER: 234115104062
return 0;
}
REGISTERNUMBER: 234115104062
// Function to display the ATM menu
void displayMenu() {
printf("\nATM Menu:\n");
printf("1. Check Balance\n");
printf("2. Deposit\n");
printf("3. Withdraw\n");
printf("4. Exit\n");
}
if (amount > 0) {
balances[userIndex] += amount;
printf("You have successfully deposited $%.2f. New balance: $%.2f\n", amount,
balances[userIndex]);
}
Department: CSE-B MSEC R2024
PAGE NO
Meenakshi Sundararajan Engineering College
(An Autonomous Institution, Affiliated to Anna University, Chennai)
U24CS101 - Programming in C - Laboratory Component
REGISTERNUMBER: 234115104062
else {
printf("Invalid deposit amount.\n");
}
}
REGISTERNUMBER: 234115104062
OUTPUT:
ATM Menu:
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your choice: 1
Your current balance is: $1000.00
ATM Menu:
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your choice: 2
Enter deposit amount: $500
You have successfully deposited $500.00. New balance: $1500.00
ATM Menu:
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your choice: 3
Enter withdrawal amount: $200
You have successfully withdrawn $200.00. New balance: $1300.00
REGISTERNUMBER: 234115104062
ATM Menu:
1. Check Balance
2. Deposit
3. Withdraw
4. Exit
Enter your choice: 4
Thank you for using the ATM. Goodbye!
RESULT:
The program for ATM stimulation was successfully executed and the output
was verified.
REGISTER NUMBER:234115104062
PROGRAM:
#include<stdio.h>
Float cel(float t1);
Float far(float t2)
Int main(){
Float t1,t2,conv1,conv2;
Conv1=cel(t1);
Printf(“\n temperature in farenhiet %f”,conv1);
Conv2=far(t2);
Printf(“\n temperature in celcius %f”,conv2);
return 0;
}
OUTPUT:
Enter temperature in celcius:25
Temperature in farenheit:77
Enter temperature in farenheit:98.6
Temperature in celcius:37
REGISTERNUMBER:234115104062
PROGRAM:
#include<stdio.h>
int main(){
Int a=10,b=7;
Printf(“\n Before swapping: a=%d,b=%d”,a,b);
Swap(&a,&b);
Printf(“\n After swapping: a=%d,b=%d”,a,b);
Return 0;
}