OOPs ASSIGNMENT
OOPs ASSIGNMENT
#include<stdio.h>
int main()
{
int n,c = 0;
printf("Enter a numbe to find prime : ");
scanf("%d",&n);
for(int i = 2 ; i<n ; i++){
if (n%i == 0){
c++;
break;
}
}
if (c > 0){
printf("It is not a Prime Number");
}
else {
printf("It is a Prime Number");
}
return 0;
}
2. Reverse a Number – Reverse the digits of an integer.
#include<stdio.h>
int main()
{
int n,rem,rev = 0;
printf("Enter a number : ");
scanf("%d",&n);
while(n!=0){
rem = n%10;
rev = rev*10 + rem;
n /= 10;
}
#include <stdio.h>
int main() {
int num, i;
int fact = 1;
printf("Enter a number: ");
scanf("%d", &num);
if (num < 0) {
printf("Negative numbers.\n");
} else {
return 0;
}
Character-Based Tasks
6. ASCII Value Finder – Take a character as input and print its ASCII
value.
#include <stdio.h>
int main() {
char ch;
return 0;
}
7. Uppercase to Lowercase – Convert an uppercase letter to lowercase.
#include <stdio.h>
int main() {
char uppercase, lowercase;
return 0;
}
8. Count Vowels and Consonants – Count the number of vowels and
consonants in a string.
#include<stdio.h>
#include <ctype.h>
int main(){
char str[100];
int vowel = 0 , consonant = 0 , i = 0 ;
printf("Enter the string :");
scanf("%s", str);
while(str[i] != '\0'){
char ch = tolower(str[i]);
if((ch >= 'a' && ch <= 'z')){
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u'){
vowel++;
}else{
consonant++;
}
}
i++;
}
return 0;
}
9. Palindrome String Check – Check whether a string is a palindrome.
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int i, len, flag = 1;
printf("Enter a string: ");
scanf("%s", str);
len = strlen(str);
for (i = 0; i < len / 2; i++) {
if (str[i] != str[len - i - 1]) {
flag = 0; break;
}
}
if (flag) {
printf("The string is a palindrome.\n");
} else {
printf("The string is NOT a palindrome.\n");
}
return 0;
}
10. Character Frequency in String – Count occurrences of a specific
character in a string.
#include <stdio.h>
int main() {
char str[100], ch;
int i, count = 0;
return 0;
}
Array-Based Tasks
11. Find Maximum and Minimum – Find the largest and smallest element
in an array.
#include <stdio.h>
int main() {
int arr[100], n, i, max, min;
#include <stdio.h>
int main() {
int arr[100], n, i, temp;
return 0;
}
#include <stdio.h>
void bubbleSort(int arr[], int n) {
int i, j, temp;
for (i = 0; i < n - 1; i++) { // Number of passes
for (j = 0; j < n - i - 1; j++) { // Compare adjacent elements
if (arr[j] > arr[j + 1]) { // Swap if out of order
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
int main() {
int arr[100], n, i;
printf("Enter the number of elements in the array: ");
scanf("%d", &n);
bubbleSort(arr, n);
printf("Sorted array in ascending order: ");
for (i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}
By:
DEEPAK S