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

coding

The document includes multiple C programming examples, such as calculating factorials and checking for strong numbers, as well as employee salary calculations based on employment status. It also discusses primitive and derived data types in C, emphasizing the importance of choosing the correct data type for memory efficiency, performance, accuracy, and code maintainability. Overall, the document serves as a guide to fundamental programming concepts in C.

Uploaded by

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

coding

The document includes multiple C programming examples, such as calculating factorials and checking for strong numbers, as well as employee salary calculations based on employment status. It also discusses primitive and derived data types in C, emphasizing the importance of choosing the correct data type for memory efficiency, performance, accuracy, and code maintainability. Overall, the document serves as a guide to fundamental programming concepts in C.

Uploaded by

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

9 a,#include <stdio.

h>

// Function to calculate the factorial of a number


int factorial(int n) {
if (n == 0 || n == 1)
return 1;
else
return n * factorial(n - 1);
}

// Function to check if a number is a strong number


int isStrongNumber(int num) {
int originalNum = num;
int sum = 0;

while (num > 0) {


int digit = num % 10; // Extract the last digit
sum += factorial(digit); // Add the factorial of the digit to the sum
num /= 10; // Remove the last digit
}

// Check if the sum of factorials is equal to the original number


return (sum == originalNum);
}

int main() {
int num;

// Input the number from the user


printf("Enter a number: ");
scanf("%d", &num);

// Check if the number is a strong number


if (isStrongNumber(num))
printf("%d is a strong number.\n", num);
else
printf("%d is not a strong number.\n", num);

return 0;
}

b, #include <stdio.h>

int main() {
int result = 5 + (6 + 2) / + 3;
printf("Result: %d\n", result);
return 0;
}

10 a, #include <stdio.h>

int main() {
char id[10], name[50], status;
float basicPay, da, hra, totalSalary;

printf("Enter Employee ID: ");


scanf("%s", id);
printf("Enter Employee Name: ");
scanf("%s", name);
printf("Enter Employee Status (F for Full-time, P for Part-time): ");
scanf(" %c", &status);
printf("Enter Basic Pay: ");
scanf("%f", &basicPay);

if (status == 'F' || status == 'f') {


da = 0.75 * basicPay;
hra = 0.10 * basicPay;
totalSalary = basicPay + da + hra;
} else if (status == 'P' || status == 'p') {
totalSalary = basicPay;
} else {
printf("Invalid status entered.\n");
return 1;
}

printf("Total Salary: %.2f\n", totalSalary);


return 0;
}

b,

Primitive Data Types:

These are the basic data types provided by the C language.

Examples: int, float, char, double, void.

Derived Data Types:

These data types are derived from primitive data types.

Examples: arrays, pointers, structures, unions.

Importance of Choosing the Correct Data Type:

Memory Efficiency: Choosing the correct data type ensures that the program uses
memory efficiently. For example, using an int when a char would suffice wastes
memory.

Performance: Appropriate data types can improve the performance of the program. For
instance, using float for integer calculations can slow down the program.

Accuracy: Correct data types ensure that calculations are accurate. Using an int
for floating-point calculations can lead to loss of precision.

Readability and Maintainability: Using the correct data types makes the code more
readable and easier to maintain.

You might also like