55 Coding Program .Prabhatchaudhary118
55 Coding Program .Prabhatchaudhary118
#include<stdio.h>
int main() {
return 0;
Output:
Integer Value
2
PRABHAT CHAUDHARY 11232767 G1
EXPERIMENT NO.2
C PROGRAM TO PERFORM ALL ARITHMETIC OPERATION
#include <stdio.h>
int main()
float div;
/*
*/
/*
*/
/*
*/
return 0;
OUTPUT:
10
SUM = 20
DIFFERENCE = 0
PRODUCT = 100
QUOTIENT = 1.000000
MODULUS = 0
4
PRABHAT CHAUDHARY 11232767 G1
EXPERIMENT NO.3
C PROGRAM TO MULTIPLY TWO FLOATING POINT NUMBERS.
#include <stdio.h>
int main() {
double a, b, product;
// Calculating product
product = a * b;
return 0;
OUTPUT:
20
Product = 200.00
EXPERIMENT NO.4
5
PRABHAT CHAUDHARY 11232767 G1
FIND THE VALUE OF ASCII CHARACTERS
#include <stdio.h>
int main() {
char c;
scanf("%c", &c);
return 0;
Output:
Enter a character: h
EXPERIMENT NO.5
SWAPPING TWO NUMBERS PROGRAM
#include<stdio.h>
6
PRABHAT CHAUDHARY 11232767 G1
int main() {
scanf("%lf", &first);
scanf("%lf", &second);
temp = first;
first = second;
second = temp;
return 0;
EXPERIMENT NO.6
WRITE A PROGRAM TO CALCULATE SIMPLE INTEREST IN C PROGRAM
#include<stdio.h>
int main()
7
PRABHAT CHAUDHARY 11232767 G1
{
int P,T;
float R, SimpleInterest;
scanf("%d",&P);
scanf("%F",&R);
scanf("%d",&T);
SimpleInterest = (P*R*T)/100;
OUTPUT:
EXPERIMENT NO.7
FIND THE PERIMETER AND AREA OF A TRAINGLE
PERIMETR
#include <stdio.h>
int main() {
8
PRABHAT CHAUDHARY 11232767 G1
float x, y, z, P, A; // Declare variables for side lengths and perimeter
// Prompt user for the side lengths and store in 'x', 'y', and 'z'
scanf("%f", &x);
scanf("%f", &y);
scanf("%f", &z);
if(x < (y+z) && y < (x+z) && z < (y+x)) // Check if the sides can form a triangle
else
return 0;
Output;
Perimeter = 150.0
9
PRABHAT CHAUDHARY 11232767 G1
AREA
#include <stdio.h>
int main() {
scanf("%f", &base);
scanf("%f", &height);
return 0;
Output:
EXPERIMENT NO.8
WRITE A PROGRAM TO CHECK WHETHER A NUMBR IS NEAGATIVE,POSITIVE,ZERO
#include <stdio.h>
int main()
{
10
PRABHAT CHAUDHARY 11232767 G1
int A;
scanf("%d", &A);
if (A > 0)
else if (A < 0)
else if (A == 0)
return 0;
Output:
5 is positive.
-7 is negative.
0 is zero.
EXPERIMENT NO.9
WRITE A PROGRAM TO CHECK HOW WE CAN USE IF ELSE TO “OPEN A DOOR” IF THE
USER ENTER CORRECT CODE
#include <stdio.h>
int main()
{
11
PRABHAT CHAUDHARY 11232767 G1
int A;
scanf("%d", &A);
if (A > 10)
else if (A < 0)
return 0;
Output:
-2 is incorrect code.
EXPERIMENT NO.10
HOW YOU CAN USE IF..ELSE TO FIND OUT IF A NUMBER IS POSITIVE OR NEGATIVE.
#include <stdio.h>
int main() {
double num;
else
return 0;
OUTPUT:
EXPERIMENT NO.11
WAP TO PRINT EVEN/ODD NUMBERS BETWEEN 1 TO 50.
#include<stdio.h>
int main()
int i, count=0, j;
if(i%j==0)
count++;
break;
printf("%d\n", i);
count = 0;
return 0;
OUTPUT:
11
13
17
14
PRABHAT CHAUDHARY 11232767 G1
19
23
29
31
37
41
43
47
EXPERIMENT NO.12
WAP TO PRINT GIVEN NUMBER IS ARMSTRONG OR NOT?
#include <stdio.h>
int main() {
scanf("%d", &num);
15
PRABHAT CHAUDHARY 11232767 G1
originalNum = num;
while (originalNum != 0) {
result += remainder;
originalNum /= 10;
if (result == num)
else
return 0;
Output:
Enter a integer: 1
1 is an Armstrong number.
Enter a integer: 1 2 3 4 5 6 7 8 9
1 is an Armstrong number.
Enter a integer: 10
EXPERIMENT NO.13
WAP TO PRINT THE FIBONACCI SERIES.
#include <stdio.h>
int main() {
int i, n;
int t1 = 0, t2 = 1;
scanf("%d", &n);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
return 0;
OUTPUT:
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597,
2584, 4181,
18
PRABHAT CHAUDHARY 11232767 G1
EXPERIMENT NO.14
C PROGRAM TO MAKE A SIMPLE CALCULATOR
#include <stdio.h>
int main() {
char op;
scanf("%c", &op);
switch (op) {
case '+':
break;
case '-':
break;
case '*':
break;
case '/':
break;
default:
return 0;
OUTPUT:
EXPERIMENT NO.15
LCM OF TWO NUMBERS IN C
#include <stdio.h>
int main() {
while (1) {
21
PRABHAT CHAUDHARY 11232767 G1
if ((max % n1 == 0) && (max % n2 == 0)) {
break;
++max;
return 0;
OUTPUT:
50
EXPERIMENT NO.16
WRITE A PROGRAM TO CHECK A GIVEN NUMBER IS PALIMDROM OR NOT
#include <stdio.h>
int main() {
scanf("%d", &n);
original = n;
while (n != 0) {
remainder = n % 10;
22
PRABHAT CHAUDHARY 11232767 G1
reversed = reversed * 10 + remainder;
n /= 10;
if (original == reversed)
else
return 0;
Output:
123321 is a palindrome.
EXPERIMENT NO.17
FACTORS OF POSITIVE NUMBER
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
if (n < 0)
else {
24
PRABHAT CHAUDHARY 11232767 G1
for (i = 1; i <= n; ++i) {
fact *= i;
return 0;
Output:
Enter an integer: 10
Factorial of 10 = 3628800
EXPERIMENT NO.18
C PROGRAM FACTORIAL EXAMPLE.
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
if (n < 0)
else {
return 0;
Output:
Enter an integer: 10
Factorial of 10 = 3628800
EXPERIMENT NO.19
C PROGRAM TO FIND THE SUM OF FIBONACCI NUMBERS AT EVEN INDEXES UP TO N
TERMS.
#include <stdio.h>
int calculateEvenSum(int n)
if (n <= 0)
return 0;
fibo[0] = 0, fibo[1] = 1;
26
PRABHAT CHAUDHARY 11232767 G1
// Initialize the result
int sum = 0;
if (i % 2 == 0)
sum += fibo[i];
return sum;
// Driver Code
int main()
// Get n
int n = 5;
// display result
n, sum);
return 0;
}
27
PRABHAT CHAUDHARY 11232767 G1
OUTPUT:
EXPERIMENT NO.20
C PROGRAM TO PRINT TRIANGLE
#include <stdio.h>
int main() {
scanf("%d", &rows);
printf(" ");
while (k != 2 * i - 1) {
printf("* ");
++k;
28
PRABHAT CHAUDHARY 11232767 G1
}
printf("\n");
return 0;
***
*****
*******
EXPERIMENT NO.21
WAP TO FIND THE MAXIMUM AND MINIMUM VALUE FROM ARRAY.
#include <limits.h>
#include <stdio.h>
int i;
minE = arr[i];
maxE = arr[i];
printf("\n");
return;
// Driver Code
int main()
// Given array
int arr[] = { 1, 2, 4, -1 };
// Function call
findMinimumMaximum(arr, N);
30
PRABHAT CHAUDHARY 11232767 G1
return 0;
OUTPUT:
EXPERIMENT NO.22
WAP TO PRINT THE SUM OF ALL ARRAY ELEMENT.
#include <stdio.h>
int main() {
int arr[5];
int i;
float sum = 0;
printf("Enter 5 elements:\n");
scanf("%d", &arr[i]);
return 0;
}
31
PRABHAT CHAUDHARY 11232767 G1
OUTPUT:
Enter 5 elements:
12345
EXPERIMENT NO.23
C PROGRAM FOR PRINTING INVERTED PYRAMID
#include <stdio.h>
int main()
int rows = 5;
// spaces
printf(" ");
printf("\n");
OUTPUT:
123456789
1234567
12345
123
1
33
PRABHAT CHAUDHARY 11232767 G1
EXPERIMENT NO.24
C PROGRAM TO PRINT HOLLOW STAR PYRAMID.
#include <stdio.h>
int main()
int rows = 5;
printf(" ");
// space
if (k == 0 || k == 2 * (rows - i) - 2 || i == 0)
34
PRABHAT CHAUDHARY 11232767 G1
printf("* ");
else {
printf(" ");
printf("\n");
return 0;
OUTPUT:
*********
* *
* *
* *
*
35
PRABHAT CHAUDHARY 11232767 G1
EXPERIMENT NO.25
PASS 2D ARRAY AS A PARAMETER IN C
#include <stdio.h>
// Function prototype
int main() {
// Example 2D array
printArray(arr, 2, 3);
return 0;
// Function definition
printf("\n");
OUTPUT:
123
456
EXPERIMENT NO.26
C 2D ARRAY EXAMPLE: STORING ELEMENTS IN A MATRIX AND PRINTING IT.
#include <stdio.h>
#define ROWS 3
#define COLS 3
int main() {
int matrix[ROWS][COLS];
scanf("%d", &matrix[i][j]);
return 0;
printf("%d\t", matrix[i][j]);
printf("\n");
OUTPUT:
11 12 13
21 22 23
31 32 33
EXPERIMENT NO.27
WAP TO PRINT DIAGONAL ELEMENTS OF A MATRIX
#include <stdio.h>
#define ROWS 3
#define COLS 3
int main() {
int matrix[ROWS][COLS] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
printf("Original Matrix:\n");
printf("%d\t", matrix[i][j]);
printf("\n");
}
39
PRABHAT CHAUDHARY 11232767 G1
printf("\nDiagonal Elements:\n");
printDiagonalElements(matrix, ROWS);
return 0;
printf("%d\t", matrix[i][i]);
printf("\n");
OUTPUT:
Original Matrix:
1 2 3
4 5 6
7 8 9
Diagonal Elements:
1 5 9
40
PRABHAT CHAUDHARY 11232767 G1
EXPERIMENT NO.28
WAP TO PRINT RECORD OF A COLLEGE STUDENT USING UNION.
#include <stdio.h>
#include <string.h>
union StudentRecord {
char name[50];
int roll_number;
float cgpa;
};
int main() {
scanf("%d", &student.roll_number);
printf("\nStudent Record:\n");
return 0;
OUTPUT:
Student Record:
CGPA: 6.20
42
PRABHAT CHAUDHARY 11232767 G1
EXPERIMENT NO.29
CALL BY VALUE AND CALL BY REFERENCE.
// C Program to implement
// Call by value
#include <stdio.h>
// Call by value
int c;
c = x + y;
return c;
// Driver Code
int main()
// Integer Declared
int a = 3, b = 2;
43
PRABHAT CHAUDHARY 11232767 G1
// Function Called
return 0;
OUTPUT:
Sum of 3 and 2 : 5
// C Program to implement
// Call by reference
#include <stdio.h>
// Call by reference
*x = *y;
*y = temp;
// Driver Code
int main()
// Declaring Integer
int x = 1, y = 5;
swap(&x, &y);
44
PRABHAT CHAUDHARY 11232767 G1
printf("After Swapping: x:%d , y:%d\n", x, y);
return 0;
OUTPUT:
EXPERIMENT NO.30
WAP TO SWAP TWO NUMBERS USING
CALL BY VALUE
#include <stdio.h>
int temp = x;
x = y;
y = temp;
int main(){
int x = 10;
int y = 11;
swap(x,y);
OUTPUT:
#include <stdio.h>
*x = *y;
*y = temp;
int main(){
int x = 10;
int y = 11;
swap(&x,&y);
OUTPUT:
EXPERIMENT NO.31
CALCULATE THE SUM OF FIRST N NATURAL NUMBERS.
#include <stdio.h>
int main() {
int n, sum = 0;
scanf("%d", &n);
sum += i;
return 0;
OUTPUT:
EXPERIMENT NO.32
POINTER PROGRAM TO SWAP TWO NUMBERS WITHOUT USING THE 3RD VARIABLE.
#include <stdio.h>
*a = *a ^ *b;
*b = *a ^ *b;
*a = *a ^ *b;
int main() {
swap(&num1, &num2);
return 0;
OUTPUT:
30
EXPERIMENT NO.33
HOW TO RETURN A POINTER FROM A FUNCTIONS IN C.
#include <stdio.h>
int* fun()
return (&A);
// Driver Code
int main()
// Declare a pointer
int* p;
// Function call
p = fun();
// Print Address
printf("%p\n", p);
printf("%d\n", *p);
return 0;
}
50
PRABHAT CHAUDHARY 11232767 G1
OUTPUT:
0x404030
10
51
PRABHAT CHAUDHARY 11232767 G1
EXPERIMENT NO.34
HOW TO DECLARE A TWO DIMENSIONAL ARRAY OF POINTERS IN C.
#include <stdio.h>
// Drivers code
int main()
int arr1[5][5] = { { 0, 1, 2, 3, 4 },
{ 2, 3, 4, 5, 6 },
{ 4, 5, 6, 7, 8 },
{ 5, 4, 3, 2, 6 },
{ 2, 5, 4, 3, 1 } };
int* arr2[5][5];
arr2[i][j] = &arr1[i][j];
printf("\n");
return 0;
OUTPUT:
01234
23456
45678
54326
25431
53
PRABHAT CHAUDHARY 11232767 G1
EXPERIMENT NO.35
CONCATENATING TWO STRINGS IN C.
#include <stdio.h>
#include <string.h>
int main() {
return 0;
OUTPUT:
#include <stdio.h>
#include <string.h>
int i, j;
char temp;
temp = str[i];
str[i] = str[j];
str[j] = temp;
int main() {
char str[100];
if (str[strlen(str) - 1] == '\n') {
str[strlen(str) - 1] = '\0';
reverseString(str);
OUTPUT:
Enter a string: 89
Reversed string: 98
EXPERIMENT NO.37
56
PRABHAT CHAUDHARY 11232767 G1
C PROGRAM TO FIND THE LENGTH OF A STRING
#include <stdio.h>
int main() {
char str[100];
int length = 0;
canf("%s", str);
length++;
return 0;
OUTPUT:
Enter a string: 55
EXPERIMENT NO.38
57
PRABHAT CHAUDHARY 11232767 G1
C PROGRAM TO STORE STUDENT RECORDS AS STRUCTURES AND SORT THEM BY
NAME.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
char name[50];
int roll_number;
float marks;
};
int main() {
int n;
scanf("%d", &n);
scanf("%s", students[i].name);
58
PRABHAT CHAUDHARY 11232767 G1
printf("Enter roll number of student %d: ", i + 1);
scanf("%d", &students[i].roll_number);
scanf("%f", &students[i].marks);
printf("Name\t\tRoll Number\tMarks\n");
free(students);
return 0;
OUTPUT:
Enter roll number of student 1: Enter marks of student 1: Enter name of student
2:parv Enter roll number of student 2: 11232762
3: 0 0.00
prabhat 0 0.00
EXPERIMENT NO.39
60
PRABHAT CHAUDHARY 11232767 G1
READ/ WRITE STRUCTURE FROM TO A FILE IN C
#include <stdio.h>
#include <stdlib.h>
struct person {
int id;
char fname[20];
char lname[20];
};
int main()
FILE* outfile;
if (outfile == NULL) {
exit(1);
int flag = 0;
outfile);
if (flag) {
else
// close file
fclose(outfile);
return 0;
OUTPUT:
EXPERIMENT NO.40
COPY CONTENT FROM ONE FILE TO ANOTHER FILE
62
PRABHAT CHAUDHARY 11232767 G1
#include <stdio.h>
int main()
char filename[100];
int c;
scanf("%s", filename);
if (fptr1 == NULL)
exit(1);
scanf("%s", filename);
if (fptr2 == NULL)
exit(1);
}
63
PRABHAT CHAUDHARY 11232767 G1
// Read contents from file
fputc(c, fptr2);
fclose(fptr1);
fclose(fptr2);
return 0;
EXPERIMENT NO.41
C PROGRAM TO CONVERT 24 HOUR TIME TO 12 HOUR TIME
#include <stdio.h>
64
PRABHAT CHAUDHARY 11232767 G1
int main(void)
return 1;
//check am pm
morning = 1;
hour -= 12;
else
morning = 0;
if (morning == 0)
else
return 0;
OUTPUT:
59
07:59 a.m.
EXPERIMENT NO.42
C PROGRAM TO APPEND CONTENT OF ONE TEXT FILE TO ANOTHER.
#include <stdio.h>
char destination[])
// opening files
printf("Unable to open/"
"detect file(s)\n");
return;
char buf[100];
// so to enhance readability.
fprintf(fp2, "\n");
while (!feof(fp1)) {
67
PRABHAT CHAUDHARY 11232767 G1
fgets(buf, sizeof(buf), fp1);
rewind(fp2);
// printing contents of
while (!feof(fp2)) {
printf("%s", buf);
// Driver Code
int main()
destination[] = "file2.txt";
appendFiles(source, destination);
return 0;
OUTPUT:
EXPERIMENT NO.43
IDENTIFY A LEAP YEAR
#include <stdio.h>
int main() {
int year;
69
PRABHAT CHAUDHARY 11232767 G1
printf("Enter a year: ");
scanf("%d", &year);
} else {
return 0;
OUTPUT:
Enter a year: 16
16 is a leap year.
EXPERIMENT NO.44
CHANGING TEXT BACKGROUND COLOR.
#include <stdio.h>
int main() {
printf("\x1b[0m");
return 0;
OUTPUT:
EXPERIMENT NO.45
DISPLAY CURRENT DATE AND TIME
#include<stdio.h>
#include<time.h>
int main()
{
71
PRABHAT CHAUDHARY 11232767 G1
printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
time(&t);
printf("\nThis program has been writeen at (date and time): %s", ctime(&t));
return 0;
OUTPUT:
This program has been writeen at (date and time): Fri Apr 26 04:47:12 2024
Coding is Fun !
EXPERIMENT NO.46
GREATEST COMMON DIVISOR PROGRAM.
#include <math.h>
#include <stdio.h>
break;
result--;
return result;
// Driver code
int main()
return 0;
OUTPUT:
GCD of 9
8 and 56 is 14
73
PRABHAT CHAUDHARY 11232767 G1
EXPERIMENT NO.47
DRAW CIRCLE C GRAPHICS
#include <graphics.h>
//driver code
int main()
// circle function
getch();
// graphics system .
closegraph();
return 0;
OUTPUT:
A module you have imported isn't available at the moment. It will be available soon.
75
PRABHAT CHAUDHARY 11232767 G1
EXPERIMENT NO.48
REVERSE AN ARRAY WITHOUT USING AN ADDITIONAL ARRAY
#include <stdio.h>
int start = 0;
int end = n - 1;
arr[end] = temp;
start++;
end--;
int main() {
reverseArray(arr, n);
return 0;
} #include <stdio.h>
int start = 0;
int end = n - 1;
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
int main() {
reverseArray(arr, n);
return 0;
OUTPUT:
Original array: 1 2 3 4 5
78
PRABHAT CHAUDHARY 11232767 G1
Reversed array: 5 4 3 2 1
EXPERIMENT NO.48
IMPLEMENT LINEAR SEARCH ALGORITHM (ARRAY)
#include <stdio.h>
if (arr[i] == key) {
int main() {
if (result != -1) {
} else {
return 0;
OUTPUT:
EXPERIMENT NO.50
IMPLEMENT BINARY SEARCH ALGORITHM (ARRAY)
#include <stdio.h>
arr[n - i - 1] = temp;
}
81
PRABHAT CHAUDHARY 11232767 G1
int main() {
printf("\n");
reverseArray(arr, n);
printf("\n");
return 0;
OUTPUT:
Original array: 1 2 3 4 5
Reversed array: 5 4 3 2 1
82
PRABHAT CHAUDHARY 11232767 G1
EXPERIMENT NO.51
WRITE A PROGRAM TO IMPLEMENT BUBBLE SORT ALGORITHM
#include <stdio.h>
// Swap function
arr[i] = arr[j];
arr[j] = temp;
int i, j;
// in place
swap(arr, j, j + 1);
int i;
printf("\n");
// Driver code
int main()
int arr[] = { 5, 1, 4, 2, 8 };
bubbleSort(arr, N);
printArray(arr, N);
84
PRABHAT CHAUDHARY 11232767 G1
return 0;
OUTPUT:
Sorted array: 1 2 4 5 8
EXPERIMENT NO.52
WRITE A PROGRAM TO IMPLEMENT INSERTION SORT ALGORITHM
#include <stdio.h>
int i, key, j;
key = arr[i];
j = i - 1;
arr[j + 1] = arr[j];
j = j - 1;
85
PRABHAT CHAUDHARY 11232767 G1
}
arr[j + 1] = key;
int i;
printf("\n");
int main()
printArray(arr, n);
insertionSort(arr, n);
printArray(arr, n);
return 0;
OUTPUT:
Original array:
12 11 13 5 6
Sorted array:
86
PRABHAT CHAUDHARY 11232767 G1
5 6 11 12 13
EXPERIMENT NO.53
WRITE A PROGRAM TO IMPLEMENT SELECTION SORT ALGORITHM
#include <stdio.h>
*xp = *yp;
*yp = temp;
int i, j, min_idx;
min_idx = i;
min_idx = j;
// element
swap(&arr[min_idx], &arr[i]);
int i;
printf("\n");
int main()
selectionSort(arr, n);
return 0;
OUTPUT:
Sorted array:
11 12 22 25 64
EXPERIMENT NO.54
GIVEN AN ARRAY ARR[] OF SIZE N-1 WITH INTEGERS IN THE RANGE OF [1, N], THE
TASK IS TO FIND THE MISSING NUMBER FROM THE FIRST N INTEGERS.
#include <stdio.h>
temp[i] = 0;}
temp[arr[i] - 1] = 1;}
int ans;
if (temp[i] == 0)
ans = i + 1;}
printf("%d", ans);
89
PRABHAT CHAUDHARY 11232767 G1
}
/* Driver code */
int main()
int arr[] = { 1, 3, 7, 5, 6, 2 };
findMissing(arr, n);}
OUTPUT:
EXPERIMENT NO.55
PROGRAM TO CYCLICALLY ROTATE AN ARRAY BY ONE
// to cyclically rotate
// an array by one
#include <stdio.h>
arr[0] = last_el;
int main()
90
PRABHAT CHAUDHARY 11232767 G1
{
int arr[] = { 1, 2, 3, 4, 5 }, i;
// Function Call
rotate(arr, n);
return 0;
OUTPUT:
Given array is
12345
Rotated array is
51234
91
PRABHAT CHAUDHARY 11232767 G1