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

8 mark

The document outlines the process of compilation and linkage in programming, where source code is converted to object code and then linked with libraries to create an executable. It evaluates two expressions using operator precedence, providing the final results. Additionally, it includes C programs for checking prime numbers, generating Fibonacci series, string manipulation, and sorting arrays in both ascending and descending order.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

8 mark

The document outlines the process of compilation and linkage in programming, where source code is converted to object code and then linked with libraries to create an executable. It evaluates two expressions using operator precedence, providing the final results. Additionally, it includes C programs for checking prime numbers, generating Fibonacci series, string manipulation, and sorting arrays in both ascending and descending order.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Got it!

Let's get straight to the point with brief answers:


6. Explain the process of Compilation and linkage.
●​ Compilation: Source code is translated into object code (machine-readable instructions).
●​ Linkage: Object code is combined with library code and other object files to create an
executable program.
7. Evaluate the following expression using operator precedence rule.
●​ i) (8 * 3 - 4) + (5 % 5 ? 3 : -9) + 5 - 20 / 10
○​ (24 - 4) + (0 ? 3 : -9) + 5 - 2
○​ 20 + (-9) + 5 - 2
○​ 14
●​ ii) a * b + (c / d) - 2^2 - (e + 4) where a=2, b=3, c=8, d=2, e=5.
○​ 2 * 3 + (8 / 2) - 4 - (5 + 4)
○​ 6 + 4 - 4 - 9
○​ -3
8. Write a simple C program for the following
●​ i) To check whether a number is prime number or not.​
#include <stdio.h>​
int main() {​
int n, i, flag = 0;​
printf("Enter a positive integer: ");​
scanf("%d", &n);​
if (n <= 1) flag = 1;​
for (i = 2; i <= n / 2; ++i) {​
if (n % i == 0) {​
flag = 1;​
break;​
}​
}​
if (flag == 0) printf("%d is a prime number.", n);​
else printf("%d is not a prime number.", n);​
return 0;​
}​

●​ ii) To generate Fibonacci series.​


#include <stdio.h>​
int main() {​
int n, first = 0, second = 1, next, i;​
printf("Enter the number of terms: ");​
scanf("%d", &n);​
printf("Fibonacci Series: ");​
for (i = 0; i < n; i++) {​
printf("%d ", first);​
next = first + second;​
first = second;​
second = next;​
}​
return 0;​
}​
9. Explain in detail about string manipulation function with example.
●​ String Manipulation Functions: Functions in string.h library to perform various
operations on strings.
●​ Examples:
○​ strlen(str): Returns the length of str.
○​ strcpy(dest, src): Copies src to dest.
○​ strcat(dest, src): Appends src to dest.
○​ strcmp(str1, str2): Compares str1 and str2.
#include <stdio.h>​
#include <string.h>​
int main() {​
char str1[20] = "Hello";​
char str2[20] = "World";​
printf("Length of str1: %d\n", strlen(str1));​
strcat(str1, str2);​
printf("Concatenated string: %s\n", str1);​
return 0;​
}​

10. Generate a C program to sort the elements of array in ascending and descending
order.
#include <stdio.h>​
void sortArray(int arr[], int size, int ascending) {​
for (int i = 0; i < size - 1; i++) {​
for (int j = 0; j < size - i - 1; j++) {​
if (ascending ? arr[j] > arr[j + 1] : arr[j] < arr[j + 1])
{​
int temp = arr[j];​
arr[j] = arr[j + 1];​
arr[j + 1] = temp;​
}​
}​
}​
}​
int main() {​
int arr[] = {5, 2, 8, 1, 9};​
int size = sizeof(arr) / sizeof(arr[0]);​
sortArray(arr, size, 1); // Ascending​
printf("Ascending order: ");​
for (int i = 0; i < size; i++) printf("%d ", arr[i]);​
printf("\n");​
sortArray(arr, size, 0); // Descending​
printf("Descending order: ");​
for (int i = 0; i < size; i++) printf("%d ", arr[i]);​
return 0;​
}​
Let me know if you need any further clarification on any of these!

You might also like