0% found this document useful (0 votes)
2 views5 pages

OS Lab - 2

The document contains multiple C programming examples demonstrating basic operations such as printing text, arithmetic calculations, finding prime numbers, reversing digits, checking for palindromes, and generating Fibonacci series. Each code snippet illustrates different programming concepts and functionalities. The examples are structured to provide hands-on experience with fundamental programming tasks.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

OS Lab - 2

The document contains multiple C programming examples demonstrating basic operations such as printing text, arithmetic calculations, finding prime numbers, reversing digits, checking for palindromes, and generating Fibonacci series. Each code snippet illustrates different programming concepts and functionalities. The examples are structured to provide hands-on experience with fundamental programming tasks.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

OS Lab – 2

1.
#include <stdio.h>
int main(){
printf("My name is Sandipan\n");
printf("I am doing OS LAB\n");
}

2.
#include <stdio.h>
int main(){
int n1,n2;
scanf("%d %d",&n1,&n2);
printf("Sum:%d\n",n1+n2);
printf("Sub:%d\n",n1-n2);
printf("Mul:%d\n",n1*n2);
printf("Div:%d\n",n1/n2);
}

3.
#include <stdio.h>

int main() {
int start, end, i, j, isp;
scanf("%d %d", &start, &end);

printf("Prime numbers ending with 7 in the range:\n");

for (i = start; i <= end; i++) {


if (i <= 1) continue;
isp = 1;
for (j = 2; j * j <= i; j++) {
if (i % j == 0) {
isp = 0;
break;
}
}
if (isp && (i % 10 == 7)) {
printf("%d\n", i);
}
}
}

4.
#include <stdio.h>
int main() {
int n1, n2 = 0, i, j;
scanf("%d", &n1);
for (i = 0; i < 4; i++) {
j = n1 % 10;
n2 = n2 * 10 + j;
n1 = n1 / 10;
}
printf("%d\n", n2);
}

5. #include <stdio.h>

int main() {
int num, originalNum, reversedNum = 0, remainder, sum = 0, maxDigit =
0;
scanf("%d", &num);
originalNum = num;
while (num != 0) {
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
sum += remainder;
if (remainder > maxDigit) {
maxDigit = remainder;
}
num /= 10;
}
if (originalNum == reversedNum) {
printf("The number is a palindrome. Biggest digit: %d\n",
maxDigit);
} else {
printf("The number is not a palindrome. Sum of digits: %d\n",
sum);
}
}
6.
#include <stdio.h>
int fibonacci(int n) {
if (n <= 1) {
return n;
} else {
return fibonacci(n - 1) + fibonacci(n - 2);
}
}
int main() {
int n, i;
printf("Enter the number of terms: ");
scanf("%d", &n);

printf("Fibonacci series:\n");
for (i = 0; i < n; i++) {
printf("%d ", fibonacci(i));
}
printf("\n");
}

You might also like