0% found this document useful (0 votes)
13 views66 pages

C Program

The document contains a series of C programming exercises aimed at various tasks such as finding the smallest and largest character, identifying character types, calculating sums, and checking for palindromes and pangrams. Each exercise includes a brief description, coding examples, and results indicating successful execution. The exercises cover basic programming concepts including loops, conditionals, and array manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views66 pages

C Program

The document contains a series of C programming exercises aimed at various tasks such as finding the smallest and largest character, identifying character types, calculating sums, and checking for palindromes and pangrams. Each exercise includes a brief description, coding examples, and results indicating successful execution. The exercises cover basic programming concepts including loops, conditionals, and array manipulation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

SMALLEST AND LARGEST NUMBER

EX NO : 1
DATE : 21.07.25

Write a program to get 25 character from the user at the end, display the largest
character, smallest character at the end.

AIM:

To Write a program to get 25 character from the user at the end, display the largest
character, smallest character at the end.

FLOW CHART:
CODING:

#include <stdio.h>

int main() {

char ch[26]; // to store 25 characters + 1 for '\0'

int i;

char smallest, largest;

printf("Enter 25 characters (no spaces): ");

scanf("%s", ch); // take all characters together as a string

smallest = largest = ch[0]; // start with the first character

for(i = 1; i < 25; i++) {

if(ch[i] == '\0') // stop if string ends early

break;

if(ch[i] < smallest)

smallest = ch[i];

if(ch[i] > largest)

largest = ch[i];

printf("\nSmallest character = %c", smallest);

printf("\nLargest character = %c\n", largest);

return 0;

}
RESULT:

The above c program to get 25 character from the user at the end, display the largest
character, smallest character at the end has been executed successfully.
LOWERCASE AND UPPERCASE
EX NO : 2
DATE : 22.07.25

Write a program to get characters from until zero is given as à input. the user Display
whether the character is a lowercase, uppercase alphabet or a digit.

AIM:

To Write a program to get characters from until zero is given as à input. the user Display
whether the character is a lowercase, uppercase alphabet or a digit.

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

char ch;

printf("Enter characters :\n");

while (1) {

scanf(" %c", &ch); // read one character (skip whitespace)

if (ch == '0') // stop when user enters 0

break;

if (ch >= 'A' && ch <= 'Z')

printf("%c is an Uppercase letter.\n", ch);

else if (ch >= 'a' && ch <= 'z')

printf("%c is a Lowercase letter.\n", ch);

else if (ch >= '0' && ch <= '9')

printf("%c is a Digit.\n", ch);

else

printf("%c is not a letter or digit.\n", ch);

printf("\n");

return 0;

}
RESULT:

The above c program to get characters from until zero is given as à input. the user
Display whether the character is a lowercase, uppercase alphabet or a digit has been
executed successfully.
GETTING CHARACTER UNITIL ! MARK
EX NO : 3
DATE : 23.07.25

Write a c program to get character from the user, Until an ! mark is entered at the end
display whether a number lowercase entered is less than or greater than number of
equal to or uppercase character. Display the error message if any other character is
entered.

AIM:

To write a c program to get character from the user, Untill an ! mark is entered at the end
display whether a number lowercase entered is less than or greater than number of
equal to or uppercase character. Display the error message if any other character is
entered.

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

char ch;

int lower = 0, upper = 0;

printf("Enter characters (enter ! to stop):\n");

scanf(" %c", &ch); // get first character

while (ch != '!') { // repeat until '!' is entered

if (ch >= 'A' && ch <= 'Z')

upper++;

else if (ch >= 'a' && ch <= 'z')

lower++;

else

printf("Error: %c is not a letter.\n", ch);

scanf(" %c", &ch); // get next character

printf("\nLowercase letters = %d", lower);

printf("\nUppercase letters = %d\n", upper);

if (lower > upper)

printf("Lowercase > Uppercase\n");

else if (lower < upper)

printf("Lowercase < Uppercase\n");

else

printf("Lowercase = Uppercase\n");

return 0;

}
RESULT:

The above program to get character from the user, Until an ! mark is entered at the end
display whether a number lowercase entered is less than or greater than number of
equal to or uppercase character. Display the error message if any other character is
entered has ben executed successfully.
PRINT A CHARACTER IN A GIVEN FORMAT
EX NO : 4
DATE : 29.07.25

Printing a character in a given format like


C

CC

CCC etc… up to C (24 times).

AIM:

To print character c in a given format.

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

char ch = 'C'; // character to print

int i, j;

for (i = 1; i <= 24; i++) { // loop 24 times

for (j = 1; j <= i; j++) { // print 'C' i times

printf("%c", ch);

printf("\n"); // move to next line

return 0;

}
RESULT:

The above c program print the character c in a given format has been executed
successfully
FIND THE SUM OF ENTERED
EX NO :5
DATE :11.08.25

Write a program to find sum of number the program should get input until number 999
is entered or 10 numbers has been entered

AIM:

To Write a program to find sum of number the program should get input until number
999 is entered or 10 numbers has been entered.

FLOCHART:
CODING:

#include <stdio.h>

int main() {

int num, sum = 0;

printf("Enter numbers (enter 999 to stop):\n");

while (1) {

scanf("%d", &num);

if (num == 999) // stop when 999 is entered

break;

sum += num; // add number to sum

printf("\nSum of numbers = %d\n", sum);

return 0;

}
RESULT:

The above c program to find sum of number the program should get input until number
999 is entered or 10 numbers has been entered has been executed successfully .
LOWERCASE AND UPPERCASE
EX NO : 6
DATE :11.08.25

Write a program to find sum of positive numbers, the program should get input untill the
number 999 is entered or 10 numbers has been entered

AIM:

Write a program to find sum of positive numbers, the program should get input untill the
number 999 is entered or 10 numbers has been entered.

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

int num, sum = 0, count = 0;

printf("Enter positive numbers (enter 999 to stop):\n");

while (count < 10) { // stop after 10 numbers

scanf("%d", &num);

if (num == 999) // stop when 999 is entered

break;

if (num > 0) // only add positive numbers

sum += num;

else

printf("Invalid! Only positive numbers are added.\n");

count++;

printf("\nSum of positive numbers = %d\n", sum);

return 0;

}
RESULT:

The above c program to find sum of positive numbers, the program should get input
untill the number 999 is entered or 10 numbers has been entered has been executed
successfully.
ARRAY OF CHARACTER AND ITS SUM OF INTEGER
EX NO : 7
DATE :18.08.25

Print sum of n integer

AIM:

Print sum of n integer

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

int n, i, num, sum = 0;

printf("Enter how many numbers (n): ");

scanf("%d", &n);

printf("Enter %d numbers:\n", n);

for(i = 1; i <= n; i++) {

scanf("%d", &num);

sum += num;

printf("\nSum of %d numbers = %d\n", n, sum);

return 0;

}
RESULT:

The above c program Print sum of n integer has been executed successfully.
SUM OF POSITIVE NUMBER
EX NO : 8
DATE : 18.08.25

write a c program to read n number into an array and display them in reverse order

AIM:

To write a c program to read n number into an array and display them in reverse order

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

int n, i;

int arr[100]; // array to store numbers (max 100

printf("Enter how many numbers (n): ");

scanf("%d", &n);

printf("Enter %d numbers:\n", n);

for(i = 0; i < n; i++) {

scanf("%d", &arr[i]);

printf("\nNumbers in reverse order:\n");

for(i = n - 1; i >= 0; i--) {

printf("%d ", arr[i]);

printf("\n");

return 0;

}
RESULT:

The above c program to read n number into an array and display them in reverse order
has been executed successfully.
SUM OF N INTEGER IN ARRAY
EX NO : 9
DATE : 19.08.25

Find the maximum and minimum numbers given in a set of array and position where it is
found.

AIM:

To write a c program the maximum and minimum numbers given in a set of array and
position where it is found.

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

int n, i;

int arr[100];

int max, min;

int maxPos = 0, minPos = 0;

printf("Enter how many numbers (n): ");

scanf("%d", &n);

printf("Enter %d numbers:\n", n);

for(i = 0; i < n; i++) {

scanf("%d", &arr[i]);

max = min = arr[0]; // assume first element is both max and min

for(i = 1; i < n; i++) {

if(arr[i] > max) {

max = arr[i];

maxPos = i;

if(arr[i] < min) {

min = arr[i];

minPos = i;

printf("\nMaximum number = %d (Position = %d)", max, maxPos + 1);

printf("\nMinimum number = %d (Position = %d)\n", min, minPos + 1);

return 0;
RESULT:

The above c program maximum and minimum numbers given in a set of array and
position where it is found has been executed successfully.
OCCURANCE OF AN INTEGER
EX NO: 10
DATE : 21.08.25

write a c program to search occurrence (multiple occurrences also) of an integer in an


array.

AIM:

To write a c program to search occurrence (multiple occurrences also) of an integer in


an array.

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

int n, i, key, found = 0;

int arr[100];

printf("Enter how many numbers (n): ");

scanf("%d", &n);

printf("Enter %d numbers:\n", n);

for (i = 0; i < n; i++) {

scanf("%d", &arr[i]);

printf("Enter number to search: ");

scanf("%d", &key);

printf("\nSearching for %d...\n", key);

for (i = 0; i < n; i++) {

if (arr[i] == key) {

printf("Found at position %d\n", i + 1);

found = 1;

if (!found)

printf("Number %d not found in the array.\n", key);

return 0;

}
RESULT:

The above c program to search occurrence (multiple occurrences also) of an integer in


an array has been executed successfully.
TO GET AN ARRAY AND DISPLAY THE CHARACTER
EX NO : 11
DATE : 21.08.25

Write a program to get an array (character) from the user and display the characters.
element by element.

AIM:

Write a program to get an array (character) from the user and display the characters.
element by element.

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

char arr[100];

int i;

printf("Enter a word (character array): ");

scanf("%s", arr); // read string (no spaces)

printf("\nCharacters in the array:\n");

for(i = 0; arr[i] != '\0'; i++) {

printf("Element %d = %c\n", i + 1, arr[i]);

return 0;

}
RESULT:

The above c program to get an array (character) from the user and display the
characters. element by element has been executed successfully.
TO GET A STING AND DISPLAY THE LENGTH
EX NO : 12
DATE : 25.08.25

Write a program to get a string and display it's length (Without using strlen()).

AIM:

To Write a program to get a string and display it's length (Without using strlen()).

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

char str[100];

int i = 0;

printf("Enter a string: ");

fgets(str, sizeof(str), stdin); // reads input safely

// Count characters until '\0' or newline

while (str[i] != '\0' && str[i] != '\n') {

i++;

printf("Length of the string = %d\n", i);

return 0;

}
RESULT:

The above c program to get a string and display it's length (Without using strlen()) has
been executed successfully.
PALINDROME
EX NO : 13
DATE : 25.08.25

Write a program to check whether a given string is palindrome or not

AIM:

To Write a program to check whether a given string is palindrome or not.

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

char str[100];

int i, length = 0, flag = 0;

printf("Enter a string: ");

fgets(str, sizeof(str), stdin); // safe input

// find string length (excluding '\n')

while (str[length] != '\0' && str[length] != '\n') {

length++;

// check palindrome

for (i = 0; i < length / 2; i++) {

if (str[i] != str[length - i - 1]) {

flag = 1; // not palindrome

break;

if (flag == 0)

printf("The string is a palindrome.\n");

else

printf("The string is NOT a palindrome.\n");

return 0;

}
RESULT:

The above c program to check whether a given string is palindrome or not has been
executed successfully.
PANGRAM
EX NO : 14
DATE : 25.08.25

Write a program to check whether given string is a pangram or not and display all
characters which are not present.

AIM:

Write a program to check whether given string is a pangram or not and display all
characters which are not present.

FLOWCHART:
CODING:
#include <stdio.h>

#include <ctype.h> // for tolower()

int main() {

char str[200];

int i;

int present[26] = {0}; // to mark letters found (a-z)

int missing = 0;

printf("Enter a string: ");

fgets(str, sizeof(str), stdin); // read input safely

// mark letters found

for (i = 0; str[i] != '\0'; i++) {

char ch = tolower(str[i]); // convert to lowercase

if (ch >= 'a' && ch <= 'z') {

present[ch - 'a'] = 1; // mark letter as found

// check missing letters

printf("\nMissing letters: ");

for (i = 0; i < 26; i++) {

if (present[i] == 0) {

printf("%c ", i + 'a');

missing++;

if (missing == 0)

printf("\n\nThe string is a PANGRAM (contains all letters A–Z).\n");

else
printf("\n\nThe string is NOT a pangram.\n");

return 0;

RESULT:

The above program to check whether given string is a pangram or not and display all
characters which are not present has been executed successfully.
FIBANACCI SERIES
EX NO :15
DATE : 1.09.25

Display the n- terms of fibonacci series

AIM:

To Display the n- terms of fibonacci series

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

int n, i;

int a = 0, b = 1, next;

printf("Enter the number of terms: ");

scanf("%d", &n);

printf("Fibonacci Series: ");

for (i = 1; i <= n; i++) {

printf("%d ", a);

next = a + b;

a = b;

b = next;

printf("\n");

return 0;

}
RESULT:

Display the n- terms of Fibonacci series has been executed successfully.


SUM OF DIGITS
EX NO :16
DATE :1.09.25

Write a program to find the sum of digits of the given integer

AIM:

To Write a program to find the sum of digits of the given integer

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

int num, sum = 0, digit;

printf("Enter an integer: ");

scanf("%d", &num);

// Make sure we work with positive number

if (num < 0)

num = -num;

while (num > 0) {

digit = num % 10; // get last digit

sum += digit; // add to sum

num = num / 10; // remove last digit

printf("Sum of digits = %d\n", sum);

return 0;

}
RESULT:

Write a program to find the sum of digits of the given integer has been executed
successfully.
Lower and upper triangular matrix
EX NO : 17
Date : 15.09.25

Write a program to print lower and upper triangular matrix of a square matric

AIM:

To Write a program to print lower and upper triangular matrix of a square matric

FLOWCHART:
CODING:

#include <stdio.h>

int main() {

int n, i, j;

int a[10][10];

printf("Enter the size of the square matrix: ");

scanf("%d", &n);

printf("Enter elements of the matrix:\n");

for (i = 0; i < n; i++) {

for (j = 0; j < n; j++) {

scanf("%d", &a[i][j]);

// Display original matrix

printf("\nOriginal Matrix:\n");

for (i = 0; i < n; i++) {

for (j = 0; j < n; j++) {

printf("%d ", a[i][j]);

printf("\n");

// Display Upper Triangular Matrix

printf("\nUpper Triangular Matrix:\n");

for (i = 0; i < n; i++) {

for (j = 0; j < n; j++) {

if (i > j)

printf("0 ");

else
printf("%d ", a[i][j]);

printf("\n");

// Display Lower Triangular Matrix

printf("\nLower Triangular Matrix:\n");

for (i = 0; i < n; i++) {

for (j = 0; j < n; j++) {

if (i < j)

printf("0 ");

else

printf("%d ", a[i][j]);

printf("\n");

return 0;

}
RESULT:

The above c program to print lower and upper triangular matrix of a square matric has
been executed successfully.
MATRIX MULTIPICATION
EX NO : 18
DATE :15.09.25

Get two matrix in input and display the multiplication matric

AIM:

To Get two matrix in input and display the multiplication matric

FLOWCHART:
COADING:

#include <stdio.h>

int main() {

int r1, c1, r2, c2;

int i, j, k;

int a[10][10], b[10][10], mul[10][10];

// Input dimensions of first matrix

printf("Enter rows and columns of first matrix: ");

scanf("%d %d", &r1, &c1);

// Input dimensions of second matrix

printf("Enter rows and columns of second matrix: ");

scanf("%d %d", &r2, &c2);

// Check if multiplication is possible

if (c1 != r2) {

printf("Matrix multiplication not possible!\n");

return 0;

// Input first matrix

printf("Enter elements of first matrix:\n");

for(i = 0; i < r1; i++) {

for(j = 0; j < c1; j++) {

scanf("%d", &a[i][j]);

// Input second matrix

printf("Enter elements of second matrix:\n");

for(i = 0; i < r2; i++) {

for(j = 0; j < c2; j++) {


scanf("%d", &b[i][j]);

// Initialize multiplication matrix to 0

for(i = 0; i < r1; i++) {

for(j = 0; j < c2; j++) {

mul[i][j] = 0;

// Multiply matrices

for(i = 0; i < r1; i++) {

for(j = 0; j < c2; j++) {

for(k = 0; k < c1; k++) {

mul[i][j] += a[i][k] * b[k][j];

// Display result

printf("\nMultiplication Result:\n");

for(i = 0; i < r1; i++) {

for(j = 0; j < c2; j++) {

printf("%d ", mul[i][j]);

printf("\n");

return 0;

}
RESULT:

Get two matrix in input and display the multiplication matric has been executed
successfully.
SEARCH AND SORTING
EX NO : 19
DATE : 15.09.25

Get the strings from the user and finds it's length, string comparison, concatenation,
replace, uppercase to lowercase

AIM:

To Get the strings from the user and finds it's length, string comparison, concatenation,
replace, uppercase to lowercase

FLOWCHART:
CODING:

#include <stdio.h>

#include <ctype.h> // for tolower()

int stringLength(char str[]) {

int i = 0;

while(str[i] != '\0') {

i++;

return i;

int stringCompare(char str1[], char str2[]) {

int i = 0;

while(str1[i] != '\0' && str2[i] != '\0') {

if(str1[i] != str2[i])

return str1[i] - str2[i];

i++;

return str1[i] - str2[i];

void stringConcat(char str1[], char str2[]) {

int i = 0, j = 0;

while(str1[i] != '\0') i++;

while(str2[j] != '\0') {

str1[i++] = str2[j++];

str1[i] = '\0';

void replaceChar(char str[], char oldChar, char newChar) {


int i = 0;

while(str[i] != '\0') {

if(str[i] == oldChar)

str[i] = newChar;

i++;

void toLowerCase(char str[]) {

int i = 0;

while(str[i] != '\0') {

str[i] = tolower(str[i]);

i++;

int main() {

char str1[100], str2[100];

char oldChar, newChar;

printf("Enter first string: ");

fgets(str1, sizeof(str1), stdin);

printf("Enter second string: ");

fgets(str2, sizeof(str2), stdin);

// Remove newline character from fgets

if(str1[stringLength(str1)-1]=='\n') str1[stringLength(str1)-1]='\0';

if(str2[stringLength(str2)-1]=='\n') str2[stringLength(str2)-1]='\0';

// Length

printf("\nLength of first string = %d\n", stringLength(str1));

printf("Length of second string = %d\n", stringLength(str2));

// Compare
int cmp = stringCompare(str1, str2);

if(cmp == 0) printf("Strings are equal\n");

else if(cmp < 0) printf("First string is smaller\n");

else printf("First string is greater\n");

// Concatenate

stringConcat(str1, str2);

printf("After concatenation: %s\n", str1);

// Replace character

printf("Enter character to replace: ");

scanf(" %c", &oldChar);

printf("Enter new character: ");

scanf(" %c", &newChar);

replaceChar(str1, oldChar, newChar);

printf("After replacement: %s\n", str1);

// Uppercase to lowercase

toLowerCase(str1);

printf("After converting to lowercase: %s\n", str1);

return 0;

}
RESULT:

To Get the strings from the user and finds it's length, string comparison, concatenation,
replace, uppercase to lowercase has been executed successfully.
STRING
EX NO : 20
DATE :16.09.25

Get the set of names from the user develop a menu driven program for searching and
sorting the names

AIM:

Get the set of names from the user develop a menu driven program for searching and
sorting the names

FLOWCHART:
CODING:

#include <stdio.h>

#include <string.h>

#define MAX 50

int main() {

int n, choice;

char names[MAX][50], temp[50];

printf("Enter number of names: ");

scanf("%d", &n);

getchar(); // clear newline

// Input names

for (int i = 0; i < n; i++) {

printf("Enter name %d: ", i + 1);

fgets(names[i], sizeof(names[i]), stdin);

// Remove newline

names[i][strcspn(names[i], "\n")] = '\0';

do {

printf("\n--- MENU ---\n");

printf("1. Display Names\n");

printf("2. Sort Names\n");

printf("3. Search Name\n");

printf("4. Exit\n");

printf("Enter your choice: ");

scanf("%d", &choice);

getchar(); // clear newline

switch(choice) {

case 1:
printf("\nNames:\n");

for (int i = 0; i < n; i++)

printf("%d. %s\n", i + 1, names[i]);

break;

case 2:

// Simple bubble sort

for (int i = 0; i < n-1; i++) {

for (int j = i+1; j < n; j++) {

if (strcmp(names[i], names[j]) > 0) {

strcpy(temp, names[i]);

strcpy(names[i], names[j]);

strcpy(names[j], temp);

printf("Names sorted alphabetically.\n");

break;

case 3: {

char key[50];

printf("Enter name to search: ");

fgets(key, sizeof(key), stdin);

key[strcspn(key, "\n")] = '\0';

int found = 0;

for (int i = 0; i < n; i++) {

if (strcmp(names[i], key) == 0) {

printf("Name found at position %d\n", i + 1);

found = 1;

break;
}

if (!found) printf("Name not found.\n");

break;

case 4:

printf("Exiting program.\n");

break;

default:

printf("Invalid choice! Try again.\n");

} while(choice != 4);

return 0;

}
RESULT:

Get the set of names from the user develop a menu driven program for searching and
sorting the names has been executed successfully.

You might also like