Cse 4
Cse 4
Date of Submission:30-12-2024
Experiment No:12
Experiment name: Write a program that will print the prime numbers in a given
range.
Theory
Source code:
#include <stdio.h>
int main()
scanf("%d", &start);
scanf("%d", &end);
if (i < 2) continue;
isPrime = 1;
if (i % j == 0)
isPrime = 0;
break;
if (isPrime)
printf("\n");
return 0;
}
Output:
Description
1. The program reads the start and end values of the range from the user.
2. It iterates through each number in the range.
3. For each number, a nested loop checks if it is divisible by any number from 2 to the
square root of the number. If it is divisible, it is not a prime number.
4. If the number passes the divisibility test, it is printed as a prime number.
5. The program skips numbers less than 2, as they are not prime.
Experiment No:13
Experiment name: Write a program that will check whether a given number is
palindrome or not.
Theory
A palindrome is a number (or text) that reads the same forward and backward. For example:
Source code:
#include <stdio.h>
int main()
scanf("%d", &n);
original = n;
while (n != 0)
rem = n % 10;
n = n / 10;
}
if (rev == original)
printf("Palindrome\n");
} else
printf("Not Palindrome\n");
return 0;
Output
Description
**
***
****
Theory
The pattern to be printed consists of stars (*) arranged in increasing rows, where each
row contains a number of stars equal to the row number. For example, the first row has
one star, the second row has two stars, and so on.
**
***
****
Source code:
#include <stdio.h>
int main()
int n, i, j;
scanf("%d", &n);
{
for (j = 1; j <= i; j++) {
printf("* ");
printf("\n");
return 0;
Output:
Descriptions
1. The program first prompts the user to input the number of rows (n).
2. The outer loop runs from 1 to n, representing each row of the pattern.
3. The inner loop runs from 1 to the current row number (i), printing the stars in each row.
4. After printing all the stars in a row, the program moves to the next line with the
printf("\n") statement.
Experiment No:15
Theory:
Source code:
#include <stdio.h>
#include <math.h>
int main()
scanf("%d", &n);
temp = n;
while (temp != 0)
{
temp /= 10;
count++;
temp = n;
while (temp != 0)
temp /= 10;
if (sum == n)
} else {
return 0;
}
Output:
Description
Experiment name: Write a program that will print the first n number sequence of
Fibonacci series
Theory:
Source code:
#include <stdio.h>
int main()
int n, a = 0, b = 1, temp, i;
scanf("%d", &n);
{
printf("%d ", a);
temp = a;
a = b;
b = temp + b;
return 0;
Output:
Description
1. The program reads the integer n from the user, which represents the number of terms in
the Fibonacci sequence to print.
2. It initializes the first two terms a = 0 and b = 1.
3. A for loop runs from 1 to n, printing the current term a, then updates the terms: the new a
becomes the old b, and the new b becomes the sum of the previous a and b.
4. The process continues until n terms are printed.