BECE320E – Embedded C Programming
LAB ASSESSMENT 1
Experiment – 1
Control loops - Arrays – Strings
Name: KshiBj Shallesh Tater
Reg No: 21BEE0094
Slot: L47+L48
Faculty: Dr Jakeer Hussain
Date: 18th Feb 2024
Q1) Write a C program to accept the basic salary the gross salary on the following basis:
of an employee from the user. Calculate
DA 50% 60% 70% 80%
Basic
1 – 4000 4001 – 8000 8001 – 12000 12000 above
HRA 10% 20% 25% 30%
Example:
If the basic salary is 45000,
then the gross salary = 45000 + 45000 x 0.3 + 45000 x 0.8 = 94500.00
Code:
#include <stdio.h>
int main() {
float basic_salary, gross_salary, da, hra;
prin?("Enter the basic salary of the employee: ");
scanf("%f", &basic_salary);
if (basic_salary <= 4000) {
da = 0.5;
hra = 0.1;
} else if (basic_salary <= 8000) {
da = 0.6;
hra = 0.2;
} else if (basic_salary <= 12000) {
da = 0.7;
hra = 0.25;
} else {
da = 0.8;
hra = 0.3;
}
gross_salary = basic_salary + basic_salary * da + basic_salary * hra;
prin?("Gross salary: %.2f\n", gross_salary);
return 0;
}
Q2) An electricity board charges the following rates for use of electricity For the first 200
units: Rs 1 per unit
For the next 100 units: Rs. 1.5 per unit
For the above 300 units: Rs. 2 per unit
Write a C program to read no of units consumed and printout total charge amount.
Code
#include <stdio.h>
int main() {
int units;
float total_charge = 0;
prin?("Enter the number of units consumed: ");
scanf("%d", &units);
if (units <= 200) {
total_charge = units * 1;
} else if (units <= 300) {
total_charge = 200 * 1 + (units - 200) * 1.5;
} else {
total_charge = 200 * 1 + 100 * 1.5 + (units - 300) * 2;
}
prin?("Total charge amount: Rs. %.2f\n", total_charge);
return 0;
}
Q3) Write a C program which will print two digit numbers whose sum of both digits is
multiple of seven
Example: 16, 25, 34, ....
Code
#include <stdio.h>
int main() {
int tens_digit, ones_digit;
prin?("Two-digit numbers whose sum of digits is a mulYple of seven:\n");
for (int i = 10; i < 100; i++) {
tens_digit = i / 10;
ones_digit = i % 10;
if ((tens_digit + ones_digit) % 7 == 0) {
prin?("%d\n", i);
}
}
return 0;
}
Q4)
Code
#include <stdio.h>
int main() {
int income, tax = 0;
prin?("Enter the income: ");
scanf("%d", &income);
if (income < 2500) {
tax = 0;
} else if (income >= 2500 && income < 5000) {
tax = (income - 2500) * 0.1;
} else if (income >= 5000 && income < 10000) {
tax = 250 + (income - 5000) * 0.2;
} else {
tax = 1450 + (income - 10000) * 0.3;
}
prin?("Total tax payable: %d Rupees\n", tax);
return 0;
}
Q5) A number is called an Armstrong number if the sum of the cubes of the digits of the
number is equal to the number. Write a C program that asks the user to enter a number and
returns if it is Armstrong or not
Example:
If the input number is 153,
13 +53 +33 =1+125+27=153 Output: 153 is Armstrong number
Code
#include <stdio.h>
int isArmstrong(int num) {
int originalNum, remainder, result = 0;
originalNum = num;
while (originalNum != 0) {
remainder = originalNum % 10;
result += remainder * remainder * remainder;
originalNum /= 10;
}
if (result == num) {
return 1; // True, number is Armstrong
} else {
return 0; // False, number is not Armstrong
}
}
int main() {
int num;
prin?("Enter a number: ");
scanf("%d", &num);
if (isArmstrong(num)) {
prin?("%d is an Armstrong number.\n", num);
} else {
prin?("%d is not an Armstrong number.\n", num);
}
return 0;
}