Progran
Progran
#include <stdio.h>
#include <string.h>
int main() {
char string[100];
scanf("%s", string);
string[len - i - 1] = temp;
return 0;
Bujna ko lagi
I=0
output: o e l l h
i=1
output: o l l e h
#include <string.h>
int main() {
char str[100];
return 0;
5a)
Write a program to check
whether a given n-digit number is an Armstrong number or not
#include <stdio.h>
#include <math.h>
int main() {
// Input number
scanf("%d", &num);
temp = num;
// Count digits
while (temp) {
temp /= 10;
n++;
temp = num;
while (temp) {
temp /= 10;
if (sum == num)
else
return 0;
while (temp) {
temp /= 10;
n++;
#include <stdio.h>
int main() {
scanf("%d", &N);
isPrime = 0;
break;
}
// If the number is prime, display it and increment count
if (isPrime) {
count++;
num++;
return 0;
The while (count < N) loop continues running until we find N prime numbers. The loop
will stop when count reaches N.
The variable isPrime is initially set to 1 (assuming the number is prime) for each number we
check.
isPrime = 0;
break;
We use a for loop to check if the number num is divisible by any number from 2 to
sqrt(num).
The condition i * i <= num is used because we only need to check divisibility up to the
square root of the number. If a number is divisible by a value larger than its square root,
the corresponding smaller factor would already have been checked.
If we find that num is divisible by any value i (i.e., num % i == 0), num is not prime, so we
set isPrime = 0 and exit the loop with break.
if (isPrime) {
count++;
If isPrime is still 1 after checking all divisors, it means the number is prime, so we print the
number (printf("%d ", num);).
#include <stdio.h>
#include <math.h>
int main() {
scanf("%d", &marks[i]);
sum += marks[i];
scanf("%d", &marks[i]);
sum += marks[i];
At the same time, the sum of the marks is calculated (sum += marks[i];).
The variance is calculated by finding the squared difference of each mark from the
mean and adding these squared differences together.
The formula for variance is:
variance=∑(xi−mean)2/N
int main() {
char str[100], temp;
int i, j, len;
len = strlen(str);
h vs e Swap e h l l o
h vs l No Swap e h l l o
l vs l No Swap e h l l o
l vs o No Swap e h l l o
7b) Write a recursive function to display the terms of the Fibonacci series
from 1 to n.
#include <stdio.h>
fibonacci(n - 1, b, a + b);
int main() {
int n;
scanf("%d", &n);
printf("\n");
return 0;
#include <stdio.h>
return 1; // Prime
int main() {
if (isPrime(i)) {
return 0;
#include <stdio.h>
void countEvenOdd(int num) {
int evenCount = 0, oddCount = 0;
while (num != 0) {
int digit = num % 10;
if (digit % 2 == 0)
evenCount++;
else
oddCount++;
num /= 10; }
printf("Even digits: %d\n", evenCount);
printf("Odd digits: %d\n", oddCount);
}
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
countEvenOdd(num);
return 0;
}
#include <stdio.h>
int sumSeries(int n) {
if (n == 1) {
return 1; }
int term = (2 * n - 1) * (2 * n - 1);
if (n % 2 == 0) {
return -term + sumSeries(n - 1); } else {
return term + sumSeries(n - 1);
}
}
int main() {
int n;
printf("Enter the number of terms (n): ");
scanf("%d", &n);
int result = sumSeries(n);
printf("Sum of the series is: %d\n", result);
return 0;
}
5f)Write a program to display the chess board pattern. [Hint:
Display “\xdb” for white color and blank
for black color]
#include <stdio.h>
void printChessBoard(int size) {
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
if ((i + j) % 2 == 0) {
printf("\xdb ");
} else {
printf(" "); )
}
}
printf("\n");
}
}
int main() {
int size = 8;
printChessBoard(size);
return 0;
}
int main() {
int rows, cols;
printf("Enter number of rows and columns: ");
scanf("%d %d", &rows, &cols);
int arr[rows][cols];