0% found this document useful (0 votes)
19 views

RECORD.pdf

Uploaded by

jeevitha
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)
19 views

RECORD.pdf

Uploaded by

jeevitha
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/ 74

SRI KRISHNA ARTS AND SCIENCE COLLEGE

Coimbatore-641 008

RECORD NOTE

DEPT.: COMPUTER TECHNOLOGY AND DATA SCIENCE

NAME : AKSHAYA S
J ROSAN SAFEEHA ROLL NUMBER : 24BCT106
24BCT152

PROGRAMME : B.Sc. COMPUTER TECHNOLOGY CLASS : I B. Sc CT - B

COURSE : PRACTICAL : PROGRAMMING IN C


SRI KRISHNA ARTS AND SCIENCE COLLEGE
Coimbatore-641 008

ROLL.NO: 24BCT106
24BCT152

Certified bonafide record of work done by JAKSHAYA S


ROSAN SAFEEHA _

during the year 2024 - 2027

Staff In-charge Head of the Department

Submitted to the Sri Krishna Arts & Science College (Autonomous) end semester examination

held on____________________________________________

Internal Examiner External Examiner


DECLARATION

I, AKSHAYA S hereby declare that this record of observations is based on the experiments carried out and

recorded by me during the laboratory classes of “PRACTICAL : PROGRAMMING IN C” conducted by SRI

KRISHNA ARTS AND SCIENCE COLLEGE, Coimbatore-641 008.

___________________

Date: Signature of the Student

Name of the Student : AKSHAYA


J ROSAN SSAFEEHA

Roll Number : 24BCT106


24BCT152

____________________

Countersigned by Staff
CONTENTS

S.No Date Title of the Experiments Page Sign


No
BASIC STRUCTURE, DATA
1
TYPES & CONSTANTS
2 OPERATORS AND
EXPRESSIONS
3 DECISION MAKING
STATEMENTS
4 LOOPING STATEMENTS
5 ARRAY USING MENU DRIVEN
PROGRAMMING
6 STRING HANDLING
FUNCTIONS
7 BUILT IN AND USER DEFINED
FUNCTIONS
8 STRUCTURES AND UNIONS
9 POINTERS
10 FILE MANAGEMENT IN C
11 COMMAND LINE ARGUMENTS
MACROS AND PREPROCESSOR
12 DIRECTIVES
BASIC STRUCTURE

#include <stdio.h>

#define x 20

int sum (int y);

int main(void)

int y =55;

printf("sum : %d", sum (y));

return 0;

int sum (int y)

return y+x;

}
OUTPUT
DATA TYPE

#include <stdio.h>

int main()

short a;

long b;

int c;

float d;

printf("size of short = %d bytes\n", sizeof(a));

printf("size of long = %d bytes\n", sizeof(b));

printf("size of int = %d bytes\n", sizeof(c));

printf("size of float = %d bytes\n", sizeof(d));

return 0;

}
OUTPUT
CONSTANT

#include <stdio.h>

int main()

const float pi = 3.1415926;

float radius, area;

printf("Enter the radius of the circle: ");

scanf("%f", &radius);

area = pi * radius * radius;

printf("The area of the circle is %f\n", area);

return 0;

}
OUTPUT
OPERATORS

#include <stdio.h>

int main() {

int a=10;

int b=20;

prinf(“a+b=%d\n”,a+b);

printf(“a-b=%d\n”,a-b);

printf(“a*b=%d\n”,a*b);

printf(“a/b=%d\n”,a/b);

printf(“a%b=%d\n”,a%b);

return 0; }
OUTPUT
IF STATEMENT

#include <stdio.h>

int main()

int age;

printf("Enter the age: ");

scanf("%d", & age);

if (age>=18)

printf("You are eligible for voting");

return 0;

}
OUTPUT
IF-ELSE STATEMENT

#include <stdio.h>

int main()

int number;

printf("Enter an integer: ");

scanf("%d", & number);

if (number%2==0)

printf("%d is an even integer", number);

else

printf("%d is an odd integer", number);

return 0;

}
OUTPUT
IF-ELSE IF LADDER STATEMENT
#include <stdio.h>

int main()

int marks;

printf("Enter the marks for C programming : \n");

scanf("%d",& marks);

if (marks >=95)

printf("O Grade");

else if(marks>=85)

printf("S Grade");

else if(marks>=75)

printf("A Grade");

else if( marks>=65)


{

printf("B Grade");

else if( marks=50)

printf("C Grade");

else if(marks >= 40)

printf("P Grade");

else

printf("Fail");

return 0;

}
OUTPUT
SWITCH STATEMENT
#include <stdio.h>

int main()

int mon;

printf("input month number: ");

scanf("%d", & mon);

switch(mon)

case 1:

printf("January\n");

break;

case 2:

printf("February\n");

break;

case 3:

printf("March\n");

break;

case 4:

printf("April\n");
break;

case 5:

printf("May\n");

break;

case 6:

printf("June\n");

break;

case 7:

printf("July\n");

break;

case 8:

printf("August\n");

break;

case 9:

printf("September\n");

break;

case 10:

printf("October\n");

break;

case 11:

printf("November\n");

break;
case 12:

printf("December\n");

break;

default:

printf("invalid month number\n");

break;

return 0;

}
OUTPUT
GOTO STATEMENT
#include <stdio.h>

void cen (int num)

if (num %2==0)

goto even;

else

goto odd;

even:

printf("%d is even", num);

return;

odd:

printf("%d is odd", num);

int main ()

int num=26;

cen(num);

return 0;

}
OUTPUT
WHILE LOOP

#include <stdio.h>

int main()

int i = 1;
while (i <=
10)
{
printf(“%d\n
”, i);
i++;
}
return
0;
}
OUTPUT
DO-WHILE LOOP

#include <stdio.h>
int main()
{
int I = 0;
do
{
printf(“%d\n”, i+1);
i++;
}
while (I < 10);
return 0;
}
OUTPUT
FOR LOOP

#include <stdio.h>

int main()

int a;

for(a = 1; a <= 5; a++)

printf(“a: %d\n”, a);

return 0;

}
OUTPUT
SINGLE DIMENSIONAL ARRAY

#include<stdio.h>

#include<stdlib.h>

int a[10], b, e;

int n = 0;

void create();

void display();

void main()

int choice;

while(1)

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

printf("\n 1. Create an array of N integers");

printf("\n 2. Display of array elements");

printf("\n 3. EXIT");

printf("\nEnter your choice: ");

scanf("%d", &choice);

switch(choice)

{
case 1: create(); break; case 2: display(); break; case 3:

printf("THANKS FOR CHOOSING THIS CHOICE");

break; default: printf("\nPlease enter a valid choice:");

} } } void create() { int i; printf("\nEnter the number of

elements: "); scanf("%d", &n); printf("\nEnter the

elements: "); for(i=0; i<n; i++) {


scanf("%d", &a[i]); } } void display()

{ int i; if(n == 0) { printf("\nNo

elements to display"); return; }

printf("\nArray elements are: ");

for(i=0; i<n;i++) printf("%d\t ",

a[i]); }
OUTPUT
MULTI-DIMENSIONAL ARRAY

#include <stdio.h>

int main()

int r, c, a[100][100], b[100][100], result[100][100], i, j;

int choice;

// Input the number of rows and columns

printf("Enter the number of rows (between 1 and 100): ");

scanf("%d", &r);

printf("Enter the number of columns (between 1 and 100): ");

scanf("%d", &c);

// Input elements of the first matrix

printf("\nEnter elements of 1st matrix:\n");

for (i = 0; i < r; ++i)

for (j = 0; j < c; ++j)

printf("Enter element a%d%d: ", i + 1, j + 1);

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

}
// Input elements of the second matrix

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

for (i = 0; i < r; ++i)

for (j = 0; j < c; ++j)

printf("Enter element b%d%d: ", i + 1, j + 1);

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

while (1)

// Menu for operation choice

printf("\nChoose the operation to perform:\n");

printf("1. Addition\n");

printf("2. Subtraction\n");

printf("3. Exit\n");

printf("Enter your choice (1, 2, or 3): ");

scanf("%d", &choice);

switch (choice)

case 1:

// Addition of matrices

for (i = 0; i < r; ++i)


for (j = 0; j < c; ++j)

result[i][j] = a[i][j] + b[i][j];

printf("\nSum of two matrices: \n");

break;

case 2:

// Subtraction of matrices

for (i = 0; i < r; ++i)

for (j = 0; j < c; ++j)

result[i][j]=a[i][j] - b[i][j];

printf("\nDifference of two matrices: \n");

break;

case 3:

// Exit the program

printf("Exiting the program.\n");

return 0;

default:

printf("Invalid choice! Please enter 1, 2, or 3.\n");

continue;
} // Printing the result

matrix for (i = 0; i < r; ++i) {

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

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

(j == c - 1) { printf("\n\n"); }

} } } return 0; }
OUTPUT
STRING LENGTH

#include <stdio.h>

#include <string.h>

int main()

char a[20] = "SKASC";

printf("Length of string : %d", strlen(a));

return 0;

}
OUTPUT
STRING CONCATENATION

#include <stdio.h>

#include <string.h>

int main()

char a[10] = "Hello";

char b[10] = "World";

strcat(a,b);

printf("Output string after concatenation: %s", a);

return 0;

}
OUTPUT
STRING COMPARISION

#include <stdio.h>

#include <string.h>

int main()

char a[20] = "SKASC";

char b[20] = "INDIA";

if (strcmp(a, b) ==0)

printf(" Both the strings are equal");

else

printf("Both are different");

return 0;

}
OUTPUT
USER DEFINED FUNCTIONS

#include <stdio.h>

int addNumbers(int a, int b);

int main()

int n1,n2,sum;

printf("Enters two numbers: ");

scanf("%d %d",&n1,&n2);

sum = addNumbers(n1, n2);

printf("sum = %d",sum);

return 0;

int addNumbers(int a, int b)

int result;

result = a+b;

return result;

}
OUTPUT
STRUCTURE

#include <stdio.h> struct student {

char name[50]; int roll; float marks; }

s; int main() { printf("Enter

information:\n"); printf("Enter name:

"); fgets(s.name, sizeof(s.name),

stdin); printf("Enter roll number: ");

scanf("%d", &s.roll); printf("Enter

marks: "); scanf("%f", &s.marks);

printf("Displaying Information:\n");

printf("Name: "); printf("%s",

s.name); printf("Roll number:

%d\n", s.roll);
printf("Marks: %.1f\n", s.marks);

return 0;

}
OUTPUT
UNION

#include <stdio.h> #include<conio.h> union student { int

rollNo; char name[32]; double marks; }s; union student s; int

main() { printf("Size of the Union = %d bytes\n", sizeof(union

student)); printf("Enter Name:- "); scanf("%s",s.name);

printf("Student name is %s\n",s.name); printf("Enter Roll no:-

"); scanf("%d",&s.rollNo); printf("Student roll no is

%d\n",s.rollNo);
printf("Enter Marks:- ");

scanf("%lf",&s.marks);

printf("Student percentage is %g or %f\n",s.marks);

getch();

}
OUTPUT
STRUCTURE AND UNION

#include <stdio.h>

union faculty {

int staffid;

char name[6];

};

struct student {

int rollno;

char name[32];

int marks;

};

int main() {

union faculty f;

struct student s;

printf("Size of the structure = %lu bytes\n", sizeof(union faculty));

printf("Size of the student union = %lu bytes\n", sizeof(struct


student));
printf("*\n");

printf("\nEnter student name: ");

scanf("%31s", &s.name);
printf("Enter Roll no: "); scanf("%d",

&s.rollno); printf("Enter Marks: ");

scanf("%d", &s.marks); printf("\nEnter

Staffid: "); scanf("%d", &f.staffid);

printf("Enter faculty Name: "); scanf("%5s",

&f.name); printf("\n\nStudent name is

%s\n", s.name); printf("Student roll no is

%d\n", s.rollno); printf("Student marks are

%d\n", s.marks); printf("\nSTAFFID is %d\n",

f.staffid); printf("FACULTY NAME is %s\n",

f.name); return 0; }
OUTPUT
POINTERS

#include <stdio.h>

int main()

int *p, c;

c = 25;

printf("Address of c: %p\n", &c);

printf("Value of c: %d\n\n", c);

p = &c;

printf("Address of pointer p: %p\n", p);

printf("Content of pointer p: %d\n\n", *p);

c = 50;

printf("Address of pointer p: %p\n", p);

printf("Content of pointer p: %d\n\n", *p);

*p = 2;

printf("Address of c: %p\n", &c);

printf("Value of c: %d\n\n", c);

return 0;

}
OUTPUT
OPEN AND WRITE TO A FILE

#include <stdio.h>

#include <stdlib.h>

int main() {

FILE *file;

char *path = "C:\\TURBOC3\\Program1.txt";

char sentence[256];

// Open file in write mode

file = fopen(path, "w");

if (file == NULL) {

printf("Error opening file.\n");

return 1;

// Get user input to write to the file

printf("Enter a sentence to write to the file: ");

fgets(sentence, sizeof(sentence), stdin);

fprintf(file, "%s", sentence);


// Close the file

fclose(file);

printf("Data written to the file successfully.\n");

getchar(); // Waits for user input

return 0;

}
OUTPUT
OPEN AND APPEND TO A FILE

#include <stdio.h>

#include <stdlib.h>

int main() {

FILE *file;

char *path = "C:\\TURBOC3\\Program 10.txt";

char sentence[256];

// Open filnd mode

file = fopen(path, "a");

if (file == NULL) {

printf("Error opening file.\n");

return 1;

// Get user input to append to the file

printf("Enter a sentence to append to the file: ");

fgets(sentence, sizeof(sentence), stdin);

fprintf(file, "%s", sentence);


// Close the file

fclose(file);

printf("Data appended to the file successfully”);

// Prompt user to press any key to exit

printf("\nPress any key to exit...\n");

getchar(); // Waits for user input

return 0;

}
OUTPUT
OPEN AND READ FROM A FILE

#include <stdio.h>

#include <stdlib.h>

int main() {

FILE *file;

char *path = "C:\\TURBOC3\\Program 10.txt";

char ch;

char a;

// Open file in read mode

file = fopen(path, "r");

if (file == NULL) {

printf("Error opening file.\n");

return 1;

// Read and display the file's content


printf("File contents:\n");
while ((ch = fgetc(file)) != EOF) {
putchar(ch);
}
// Close the file
fclose(file);
// Prompt user to press any key to exit
printf("\nPress any key to exit...\n");
getchar(); // Waits for user input
return 0;
}
OUTPUT
COMMAND LINE ARGUMENTS

#include <stdio.h>

int main(int argc, char *argv[]) {

printf("Number of arguments: %d\n", argc);

// Loop through the arguments and print each one

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

printf("Argument %d: %s\n", i, argv[i]);

return 0;

}
OUTPUT
MACROS AND PREPROCESSOR DIRECTIVES

#include <stdio.h>

#define PI 3.1415

#define circleArea(r) (PI*r*r)

int main() {

float radius, area;

printf("Enter the radius: ");

scanf("%f", &radius);

area = circleArea(radius);

printf("Area = %.2f", area);

return 0;

}
OUTPUT

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy