C Programs - Updated - Docx1
C Programs - Updated - Docx1
#include <stdio.h>
#include <string.h>
void reverseString(char str[]) {
int start = 0;
int end = strlen(str) - 1;
int main() {
char str[100];
return 0;
}
2. Prime Number Check: Write a C function int is Prime(int num) that returns 1 if num
is prime, and 0 otherwise
#include <stdio.h>
int main() {
int num;
return 0;
}
3. Palindrome Check: Write a C program that checks if a string is a palindrome.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
return 1; // Is a palindrome
}
int main() {
char str[100];
return 0;
}
4. Matrix Multiplication: Write a C program that multiplies two matrices.
#include <stdio.h>
#define MAX 10
int main() {
int first[MAX][MAX], second[MAX][MAX], result[MAX][MAX];
int firstRows, firstCols, secondRows, secondCols;
// Multiply matrices
multiplyMatrices(first, second, result, firstRows, firstCols, secondRows,
secondCols);
return 0;
}
5. Array Sorting (Bubble/Insertion): Write a Java program that takes an array of
integers as input and sorts it in ascending order using Bubble Sort.
import java.util.Scanner;
scanner.close();
}
}
6. Simple Calculator: Write a Java program that takes two numbers and an operator (+,
-, *, /) as input and prints the result of the operation.
import java.util.Scanner;
double result;
scanner.close();
}
}
7. Fibonacci sequence (Iteration): Write a Java program that takes an integer 'n' as
input and prints the Fibonacci sequence up to 'n' terms.
import java.util.Scanner;
// Validate input
if (n <= 0) {
System.out.println("Please enter a positive integer.");
} else {
System.out.println("Fibonacci sequence up to " + n + " terms:");
printFibonacci(n);
}
scanner.close();
}
# Find intersection
intersection = set1 & set2 # or use set1.intersection(set2)
# Find union
union = set1 | set2 # or use set1.union(set2)
# Print results
print("Intersection:", intersection)
print("Union:", union)
O/p:
Intersection: {4, 5}
Union: {1, 2, 3, 4, 5, 6, 7, 8}
10.Prime Number Generation: Write a Python function that generates a list of prime
numbers up to a given limit.
def generate_primes(limit):
if limit < 2:
return []
primes = []
is_prime = [True] * (limit + 1)
is_prime[0], is_prime[1] = False, False # 0 and 1 are not prime numbers
return primes
# Example usage
limit = int(input("Enter the limit: "))
print("Prime numbers up to", limit, ":", generate_primes(limit))
Note:
ID card is mandatory
Electronics devices are not allowed
If a student is found involved in malpractices, they may face disqualification from
the competition.