[go: up one dir, main page]

0% found this document useful (0 votes)
17 views83 pages

C Record

The document is a bonafide certificate and practical record for a student in the Computer Science and Engineering branch at PET Engineering College, detailing various C programming experiments conducted during the 2021-2022 academic year. It includes algorithms and code for programs such as checking Armstrong numbers, leap years, even/odd numbers, vowels/consonants, linear search, Fibonacci series, palindrome checking, and total value calculation using loops. Each experiment concludes with a verification of results, demonstrating the practical application of programming concepts.

Uploaded by

asiachu135
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)
17 views83 pages

C Record

The document is a bonafide certificate and practical record for a student in the Computer Science and Engineering branch at PET Engineering College, detailing various C programming experiments conducted during the 2021-2022 academic year. It includes algorithms and code for programs such as checking Armstrong numbers, leap years, even/odd numbers, vowels/consonants, linear search, Fibonacci series, palindrome checking, and total value calculation using loops. Each experiment concludes with a verification of results, demonstrating the practical application of programming concepts.

Uploaded by

asiachu135
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/ 83

PET ENGINEERING COLLEGE

TIRUCHENDUR ROAD, VALLIOOR-627117


TIRUNELVELI DISTRICT.

BONAFIDE CERTIFICATE

Certified that this the bonafide record of practical work done by


Mr/Ms. Of the Second semester in COMPUTER
SCIENCE AND ENGINEERING branch of this institution in the PROGRAMMING IN C
LABORATORY (CS3271) during academic year 2021-2022 In partial fulfillment of the B.E Degree
course of the ANNA UNIVERSITY, CHENNAI.

Staff In-Charge Head of the Department


[Ms.R.Parameshwari, AP/CSE] [ Dr.S.Babu Renga Rajan ]

University Register No: .……………………………


University Examination Held on: ………………………………

Internal Examiner External Examiner


CONTENTS

Page
S. No Date Experiments Sign
No
PROGRAMS USING I/O STATEMENTS AND EXPRESSIONS

EX. No: 1
WRITE A C PROGRAM FOR AMSTRONG OR NOT
DATE :

AIM:

To write a C program to amstrong or not using i/o statement and expressions

ALGORITHM:

Step 1: Start
Step 2: Read an integer input number.
Step 3: Declare andInitialise the variables current_digit, sum = 0, digits = 0 and
num = number.
Step 4: Calculate the number of digits in the input integer number and store it in the
variable number_of_digits.
Step 5: Repeat Steps 5 to 7 Until num > 0
Step 6: current_digit = (num % 10)
Step 7: sum = sum + mnumber_of_digits
Step 8: num = num / 10
Step 9: Check if sum == number
a.ThenPrint “It is an Armstrong Number.”
Else
b.Print “It is not an Armstrong Number.”
Step 10: Stop

PROGRAM:

#include <stdio.h>
#include<conio.h>
int main()
{
int number, originalNumber, remainder, result = 0;
clrscr();
printf("Enter a three digit integer: ");
scanf("%d", &number);
originalNumber = number;
while (originalNumber != 0)
{
remainder = originalNumber%10;
result += remainder*remainder*remainder;
originalNumber /= 10;
}
if(result == number)
printf("%d is an Armstrong number.",number);
else
printf("%d is not an Armstrong number.",number);
getch();
}

RESULT

Thus the C program to amstrong or not using i/o statement and expressions is executed
and the result is verified.

.
DECISION-MAKING CONSTRUCTS: IF-ELSE, GOTO, SWITCH-CASE, BREAK-
CONTINUE

EX. No: 2a
WRITE A C PROGRAM TO CHECK LEAP YEAR USING IF ELSE
DATE : STATEMENT

AIM:

To write a C program to check leap year using if else statement

ALGORITHM

Step 1: Program Start


Step 2: Read Year
Step 3: if year%4=0 and year%100!=0 or if year%4=0 and year%400=0 then go to step4
Else go to step5
Step 4: print a leap year
Step 5: print not a leap year
Step 6: Program End

PROGRAM:

#include<stdio.h>
#include<conio.h>

void main()
{
int year;
clrscr();
/* Input year from user */
printf("Enter year : ");
scanf("%d", &year);

* If year is exactly divisible by 4 and year is not divisible by 100


* or year is exactly divisible by 400 then
* the year is leap year.
* Else year is normal year
if(((year % 4 == 0) && (year % 100 !=0)) || (year % 400==0))

{
printf("LEAP YEAR");
}
else
{
printf("COMMON YEAR");
}

getch();
}

RESULT

Thus the C program to check leap year using if else statement is executed and the
result is verified.
DECISION-MAKING CONSTRUCTS: IF-ELSE, GOTO, SWITCH-CASE, BREAK-
CONTINUE

EX. No: 2b
TO CHECK IF A NUMBER IS EVEN OR NOT USING GOTO
DATE :

AIM:

To write a C program to check if a number is even or not using goto statement

ALGORITHM

Step 1: Program Start


Step 2: Declaration of variable
Step 3: Enter the number
Step 4: Assign the value in variable
Step 5: Check condition if(number%2==0)and using go to statement
Step 6: Give answer according to condition
Step 7: Program End

PROGRAM:

#include <stdio.h>

#include<conio.h>

#include <stdlib.h>

void main()

int num;

printf("Enter a number\n");

scanf("%d", &num);

if (num % 2 == 0)

goto even;
else

goto odd;

even:

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

exit(0);

odd:

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

getch();

RESULT

Thus the C program to check if a number is even or not using goto statement is
executed and the result is verified.
DECISION-MAKING CONSTRUCTS: IF-ELSE, GOTO, SWITCH-CASE, BREAK-
CONTINUE

EX. No: 2c
PROGRAM TO CHECK VOWEL OR CONSONANT USING SWITCH
DATE : CASE STATEMENT

AIM:

To write a C program to check vowels or consonant using switch-case statement

ALGORITHM:

Step 1: Define a character variable ch to check the entered character

Step 2: The program is asked the user to enter an Alphabets to check whether vowel or
consonant

Step 3: Entered character is stored in the ch variable

Step 4: Define cases for the character ch with vowel character both capital and small

Step 5: Next, the program checks every case using the given character.

Step 6 Finally, it displays whether the given character is vowel or consonant

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();

/* Input an alphabet from user */


printf("Enter any alphabet: ");
scanf("%c", &ch);

/* Switch value of ch */
switch(ch)
{
case 'a':
printf("Vowel");
break;
case 'e':
printf("Vowel");
break;
case 'i':
printf("Vowel");
break;
case 'o':
printf("Vowel");
break;
case 'u':
printf("Vowel");
break;
case 'A':
printf("Vowel");
break;
case 'E':
printf("Vowel");
break;
case 'I':
printf("Vowel");
break;
case 'O':
printf("Vowel");
break;
case 'U':
printf("Vowel");
break;
default:
printf("Consonant");
}
getch();
}

RESULT

Thus the C program to check vowels or consonant using switch-case statement is


executed and the result is verified.
DECISION-MAKING CONSTRUCTS: IF-ELSE, GOTO, SWITCH-CASE, BREAK-
CONTINUE

EX. No: 2d
LINEAR SEARCH USING BREAK
DATE :

AIM:

To write a C program to linear search using break statement

ALGORITHM:

Step 1: Find out the length of the data set.


Step 2: Set counter to 0.
Step 3: Examine value held in the list at the counter position.
Step 4: Check to see if the value at that position matches the value searched for.
Step 5: If it matches, the value is found. Send a message and end the search.
Step 6: If not, increment the counter by 1 and go back to step 3 until there are no more
items to search.
Step 7: If all the items have been checked and no match is found, send a message

PROGRAM:

#include<stdio.h>

#include<conio.h>

void main()
{

int a[10], i, item,n;

printf("\nEnter number of elements of an array:\n"); scanf("%d",&n);


printf("\nEnter elements: \n");
for (i=0; i<n; i++)
scanf("%d", &a[i]);
printf("\nEnter item to search: ");
scanf("%d", &item);
for (i=0; i<=9; i++)

if (item == a[i])

{
printf("\nItem found at location %d", i+1);
break;
}
if (i > 9)
printf("\nItem does not exist.");
getch();
}

RESULT

Thus the C program to Linear search Using break statement is executed and the
result is verified.
DECISION-MAKING CONSTRUCTS: IF-ELSE, GOTO, SWITCH-CASE, BREAK-
CONTINUE

EX. No: 2e
PRINT THE NUMBERS FROM 1 TO 10 USING CONTINUE
DATE : STATEMENT

AIM:

To write a C program to print the number from 1 to 10 using continue statement

ALGORITHM:

Step 1 : Start

Step 2 : declare and initialize i=1

Step 3 : do until I<=10 for condition false then goto step 4

3.1 : print the value of i , increment value of i by 1 as i=i+1 and goto step 3until
if(i==6)

Step 4 : Stop

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
for ( i = 1; i <= 10; i++)
{
if (i == 6)
continue;
else
// otherwise print the value of i
printf("%d ", i);
}
getch();
}

RESULT

Thus the C program to Print The Numbers From 1 To 10 Using continue statement
is executed and the result is verified.
LOOPS: FOR, WHILE, DO-WHILE

EX. No: 3a
DATE : FIBONACCI SERIES UP TO N TERMS USING FOR LOOP

AIM:
To write a C program to Fibonacci series up to n terms using for loop

ALGORITHM:

Step 1: Start
Step 2: Read the number of terms n
Step 3: Initialize t1 0, t2 1
Step 4: print a and b values
Step 5: for i 3 to n
a. increment the i value
b. nextTerm = t1 + t2;
c. print next term value
d. t1 t2
e. t2 next term

PROGRAM:

#include <stdio.h>
#include<conio.h>
int main()
{

int i, n;

// initialize first and second terms


int t1 = 0, t2 = 1;
clrscr();

// initialize the next term (3rd term)


int nextTerm = t1 + t2;

// get no. of terms from user


printf("Enter the number of terms: ");
scanf("%d", &n);
// print the first two terms t1 and t2
printf("Fibonacci Series: %d, %d, ", t1, t2);

// print 3rd to nth terms


for (i = 3; i <= n; ++i) {
printf("%d, ", nextTerm);
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}

return 0;
}

RESULT
Thus the C program to to Fibonacci series up to n terms using for loop is executed
and the result is verified.
LOOPS: FOR, WHILE, DO-WHILE

EX. No: 3b
TO CHECK WHETHER THE GIVEN INTEGER IS PALINDROME
DATE :
OR NOT USING WHILE LOOP

AIM:
To write a C program To check whether the given integer is Palindrome or not using
while loop

ALGORITHM:

Step 1: Start
Step 2: read num
Step 3: Set number num to a variable n
n ← num
Step 4: Iterate until num is not equal to 0.
If num value becomes 0, control comes out of the loop. So num’s original value is lost. So,
num,value is stored in other variable n in step 3.
In step 4, reverse of the number is calculated.
while ( num != 0) do
remainder ← num mod 10
num ← num/10
rev ← rev * 10 +remainder
Step 5: Print reverse number
print rev
Step 6: Check if original number & reverse number are same. If it is, number is palindrome.
Otherwise,
not palindrome
if (rev = n) then
print palindrome
else
print not a palindrome
endif
Step 7: End
PROGRAM

#include<stdio.h>
#include<conio.h>
int main()
{
int temp,rev=0,num,remainder ;
clrscr();
printf("Enter the number\n");
scanf("%d",&num);
temp=num;
while(num!=0) //Reversing the number
{
remainder = num%10;
num = num/10;
rev = rev*10+ remainder;
}
printf("The reverse number is %d",rev);
if(rev == temp)
printf("\n%d is a palindrome",temp);
else
printf("\n%d is not a palindrome", temp);
getch();
}

RESULT

Thus the C program to To check whether the given integer is Palindrome or not using
while loop is executed and the result is verified.
LOOPS: FOR, WHILE, DO-WHILE

EX. No: 3c

DATE : PRINT TOTAL VALUE USING DO-WHILE LOOP

AIM:
To write a C program to Print total value Using do-while Loop

ALGORITHM:

Step 1: start
Step2: enter any value below 10, and the total variable initialized to 0.
Step 3: User entered value will assign to the number variable, and then the number is added to the
total.
Step 4: In the next line, we used ++ operator to increment the number value.
Step 5: After this line, the value in a Number variable tests against the while condition. If the
condition results true, it repeats the process. Otherwise, it will exit from it.
Step 6: In the next line, we used one more printf statement to show that it is coming from outside
the while loop.

PROGRAM:

#include<stdio.h>
#include<conio.h>

void main()
{
int number, total=0;

printf("\n Please Enter any integer below 10 \n");


scanf("%d", &number);
do
{
total = total + number;
printf(" Number = %d\n", number);
printf(" Total Value is: %d\n", total);
number++;
}while (number< 10);

printf(" Total Value from outside the Loop is: %d \n", total);
getch();
}

RESULT

Thus the C program to Print total value Using do-While Loop is executed and the
result is verified.
ARRAYS: 1D AND 2D, MULTI-DIMENSIONAL ARRAYS, TRAVERSAL

EX. No: 4a
C IMPLEMENTATION TO FIND TWO SMALLEST ELEMENTS
DATE : IN A ONE DIMENSIONAL ARRAY

AIM:

To write a C program to find smallest elements in a one dimensional array

ALGORITHM:

Step 1: Define two variable min & sec_min


Step 2: Initialize min to array[0] & sec_min to INT_MAX
Step 3: Scan the entire array
Step 4: For(int i=0;i<n;i++)
if array[i]<min
then update min to array[i]&sec_min to previousmin value
else if array[i] is lesser than sec_min but greater than min
then update sec_min to array value
do nothing to min
End for loop
Step 5: If still sec_min has the value INT_MAX
Step 6: Only one smallest value exists, print it
Else
Print min & sec_min

PROGRAM:

#include <stdio.h>
#include<conio.h>
#include <stdlib.h>
#include <limits.h>

void findTwoMin(int* a,int n)


{

int min=a[0]; //initialize min to first array element


int sec_min=INT_MAX,temp=0; //initialize second min to INT_MAX

for(int i=0;i<n;i++){ //scan the entire array


//if a[i]< min then update min to array value
//& second min to previous min value
if(a[i]<min){
sec_min=min;
min=a[i];
}
//else if a[i] is lesser than second min but
//greater than min then update second min to array value
else if (a[i] < sec_min && a[i] > min)
sec_min=a[i];
//do nothing to min
}

//if second min is still at its initialized value


//then no second minimum exists at all
if(sec_min==INT_MAX)
printf("only one smallest element: %d ",min);
else
printf("First smallest element: %d & second smallest element : %d",min,sec_min);
}

int main()

{
int n;
printf("enter no of elements\n");
scanf("%d",&n);
int *a=(int*) malloc(sizeof(int)*n);

printf("enter the elements........\n");


//taking input
for(int i=0;i<n;i++)
scanf("%d",&a[i]);

//find two smallest no


findTwoMin(a,n);

return 0;
}

RESULT

Thus the C program to to find find smallest elements in a one dimensional array is
executed and the result is verified.
ARRAYS: 1D AND 2D, MULTI-DIMENSIONAL ARRAYS, TRAVERSAL

Ex. No: 4b
C PROGRAM TO DISPLAY THE HIGHEST MARKS IN EACH
Date : SUBJECT USING TWO DIMENSIONAL ARRAY

AIM:

To write a C program to Display The Highest Marks in each Subject using two
Dimensional Array

ALGORITHM:

Step 1: Start
Step 2: Create the array
Step 3: Declare the array name and type
Step 4: enter the 5 students marks in three subjects and store the marks using for loop

Step 5: check the condition if(marks[i][j]>max_marks)

Step 5.1 max_marks=marks[i][j];


Step 6: print the highest marks obtained in the subject.
Step 7: Stop

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int marks[5][5],i,j,max_marks;
clrscr();
for(i=0;i<5;i++)
{
printf("\n enter the marks obtained by student %d",i+1);
for(j=0;j<3;j++)
{
printf("\n marks[%d}{%d]=",i,j);
scanf("%d",&marks[i][j]);
}
}

for(j=0;j<3;j++)
{
max_marks=-999;
for(i=0;i<5;i++)
{

if(marks[i][j]>max_marks)
max_marks=marks[i][j];
}
printf("\n the highest marks obtained in the subject%d=%d",j+1,max_marks);
}
getch();
}

RESULT

Thus the C program to Display The Highest Marks in each Subject using Two
Dimensional Array is executed and the result is verified.
ARRAYS: 1D AND 2D, MULTI-DIMENSIONAL ARRAYS, TRAVERSAL

EX. No: 4c
C PROGRAM TO STORE AND PRINT THE VALUES USING MULTI -
DATE : DIMENSIONAL ARRAY

AIM:

To write a C program to store and print the values using multi -dimensional array.

ALGORITHM:

Step 1: Start
Step 2: Create the array
Step 3: Declared three variables I j k for three for loops
Step 4: Initialize the array size int arr[2][3][3];
Step 5: enter the values in the array and store the array value using for loop
Step 6: first for loop represents the block of a 3d array
Step 7: second for loop represents the number of rows
Step 8: Third for loop represents the number of columns.
Step 9: for loops will print the inserted values in the matrix form.
Step 10: stop the program

PROGRAM :

#include<stdio.h>
#include<conio.h>

int main()
{
int i,j,k; //variables for nested for loops

int arr[2][3][3]; //array declaration


printf("enter the values in the array: \n");
for(i=1;i<=2;i++) //represents block
{
for(j=1;j<=3;j++) //represents rows
{
for(k=1;k<=3;k++) //represents columns
{

printf("the value at arr[%d][%d][%d]: ",i,j,k);

scanf("%d",&arr[i][j][k]);
}
}
}
printf("printing the values in array: \n");
for(i=1;i<=2;i++)
{
for(j=1;j<=3;j++)
{
for(k=1;k<=3;k++)
{
printf("%d ",arr[i][j][k]);
if(k==3)
{
printf("\n");
}
}
}
printf("\n");
}
return 0;
}

RESULT

Thus the C program to store and print the values using multi –dimensional
array is executed and the result is verified.
ARRAYS: 1D AND 2D, MULTI-DIMENSIONAL ARRAYS, TRAVERSAL

EX. No: 4d
ARRAYS TRAVERSAL
DATE :

AIM:

To write a C program to arrays traversal

ALGORITHM:

Step 1: Start
Step 2: [Initialize counter variable. ] Set i = LB.
Step 3: Repeat for i = LB to UB.
Step 4: Apply process to arr[i].
Step 5: [End of loop. ]
Step 6: Stop

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int i, size;
int arr[]={1, -9, 17, 4, -3};
clrscr();
size=sizeof(arr)/sizeof(arr[0]); //sizeof(arr) will give 20 and sizeof(arr[0]) will give 4
printf("The array elements are: ");
for(i=0;i<size;i++)
printf("\narr[%d]= %d", i, arr[i]);
getch();
}
RESULT

Thus the C program to Arrays traversal is executed and the result is verified.
STRINGS: OPERATIONS

EX. No: 5a
TO FIND THE LENGTH OF A STRING
DATE :

AIM:

To write a C program to find the length of a string

ALGORITHM:

Step 1: Start
Step 2: declare the string size
Step 3: initialize len=0
Step 4 : entered the string
Step 5: Read the entered string using gets() function
Step 6: The function strlen()calculates the length of the string and the value stored on len
Step 7 : Print the length value.

PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[10];
int len=0;
clrscr();
printf("\n enter the string");
gets(str);
len=strlen(str);
printf("enter string:%s",str);
printf ("the length of the string is :%d",len);
getch();
}
RESULT

Thus the C program to find the length of a string is executed and the result is verified.
STRINGS: OPERATIONS

EX. NO: 5b
DATE : TO COMPARE TWO STRINGS

AIM:

To write a C program to compare two string

ALGORITHM:

Step 1: Start
Step 2: declare the string size
Step 3: initialize the variable
Step 4: entered the first string
Step 5: Read the entered first string using gets() function
Step 6: entered the second string
Step 7: Read the entered second string using gets() function
Step 8: compare the strings by using the strcmp() the value stored on variable
Step 9: check the if condition if(value==0) If the function returns 0 value means that both
the strings are same, otherwise the strings are not equal.
Step 10: Print the Result

PROGRAM:

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char str1[10],str2[20];
int value;
clrscr();
printf("\n enter the first string");
gets(str1);
printf("\n enter the second string");
gets(str2);
value=strcmp(str1,str2);
if(value==0)
printf ("\n strings are same");
else
printf("\n strings are not same");
getch();

RESULT

Thus the C program to compare two strings is executed and the result is verified.
STRINGS: OPERATIONS

EX. No: 5c
TO CONCATENATE TWO STRINGS
DATE :

AIM:

To write a C program to concatenate two string

ALGORITHM:

Step 1: Start
Step 2: declare the string size
Step 3 : entered the first string
Step 4: Read the entered first string using gets() function
Step 5: entered the second string
Step 6: Read the entered second string using gets() function
Step 7: concatenate the strings by using the strcat() function
Step 8: the strings are combined together to form a single string.
Step 9: Print str 1

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[20],str2[20];
printf("\n enter the first string");
gets(str1);
printf("\n enter the second string");
gets(str2);
strcat(str1,str2);
printf("\n output string is :%s",str1);
getch();
}
RESULT

Thus the C program to concatenate two string is executed and the result is verified.
STRINGS: OPERATIONS

EX. No: 5d
DATE : COPY A STRING TO ANOTHER STRING

AIM:

To write a C program to copy a string to another string

ALGORITHM:

Step 1: Start
Step 2: declare the string size
Step 3: entered the first string
Step 4: Read the entered first string using gets() function
Step 7: copy a string to another string(str2) by using the strcpy() function
Step 8: finally print the value of both the variable

PROGRAM

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[]="abc";
int str2[];
clrscr();
strcpy(str2,str1);
printf("\n%s",str2);
getch();
}
RESULT

Thus the C program to copy a string to another string is executed and the result is
verified.
FUNCTIONS: CALL, RETURN, PASSING PARAMETERS BY
(VALUE, REFERENCE), PASSING ARRAYS TO FUNCTION

EX. No: 6a
DATE : SUM OF TWO NUMBER USING FUNCTION CALL

AIM:

To write a C program to sum of two number using function call

ALGORITHM:

Step 1: Start

Step 2: declare and initialize the variable

Step 3: sum = add(a, b); call the function

Step 3: add two variable values and assign the result to the variable sum.

Step 4: display sum

Step 5: stop

PROGRAM:

#include <stdio.h>
#include<conio.h>
int add(int a, int b);
void main()
{

int sum;
int a, b;
clrscr();
printf(" Enter the first and second number \n");
scanf("%d %d", &a, &b);
sum = add(a, b); // call add() function
printf( "The sum of the two number is %d", sum);
}
int add(int n1, int n2) // pass n1 and n2 parameter
{
int c;

c = n1 + n2;
return c;

RESULT

Thus the C program to sum of two number using function call is executed and
the result is verified.
FUNCTIONS: CALL, RETURN, PASSING PARAMETERS BY
(VALUE, REFERENCE), PASSING ARRAYS TO FUNCTION

EX. No: 6b
FACTORIAL OF A GIVEN NUMBER
DATE :

AIM:

To write a C program to Factorial of a given number

ALGORITHM:

Step 1: Start

Step 2: declare and initialize the variable

Step 3: call factorial (n)

Step 4: print factorial f

Step 5: stop factorial (n)

Step 6: if (n==1) then return 1

Step 7: else

Step 8: return n*fact(n-1);


Step 9: Return f

PROGRAM:

#include<stdio.h>

#include<conio.h>

void main()

int fact(int);

int n,f;

clrscr();

printf(“enter the number\n”);


scanf(“%d”,&n);

f=fact(n);

printf(“the factorial of a number=%d”f);

getch();

int fact(int n)

if(n==1)

return(1);

else

return n*fact(n-1);

RESULT

Thus the C program to Factorial of a given number is executed and the result
is verified.
FUNCTIONS: CALL, RETURN, PASSING PARAMETERS BY
(VALUE, REFERENCE), PASSING ARRAYS TO FUNCTION

EX. No: 6c
SWAPPING NUMBERS USING CALL BY VALUE AND
DATE :
REFERENCE

AIM:

To write a C program to Swapping numbers using Call by Value and call by


Reference

ALGORITHM 1:

SWAPPING NUMBERS USING CALL BY VALUE

Step 1: Start
Step 2: Set x=10 and y=20
Step 3: Call the function swap(&x,&y)
Step 3a: Start fuction
Step 3b: assign t= a
Step 3c: assign a= b
Step 3d: assign b= t
Step 3e: end function
Step 5: print the result
Step 6: Stop the program

ALGORITHM 2:

SWAPPING NUMBERS USING CALL BY REFERENCE

Step 1: Start
Step 2: Set x=10 and y=20
Step 3: Call the function swap(&a,&b)
Step 3a: Start fuction
Step 3b: assign *t=*a
Step 3c: assign *a=*b
Step 3d: assign *b=*t
Step 3e: end function
Step 5: print the result
Step 6: Stop the program
PROGRAM 1:

#include <stdio.h>
#include<conio.h>
void swap(int,int);
void main()
{
int x = 10, y = 20;
printf (" x = %d, y = %d from main before calling the function", x, y);
swap(x,y);
printf( "\n x = %d, y = %d from main after calling the function", x, y);
getch();
}
void swap( int a,int b)
{
int t;
t=a;
a=b;

b=t;
printf (" \n x = %d, y = %d from modular function", a, b);

PROGRAM 2:

#include <stdio.h>
#include<conio.h>
void swap(int*,int*);
void main()
{
int x = 10, y = 20;
printf (" x = %d, y = %d from main before calling the function", x, y);
swap(&x,&y);
printf( "\n x = %d, y = %d from main after calling the function", x, y);
getch();
}
void swap( int *a,int *b)
{
int *t;
*t=*a;
*a=*b;
*b=*t;

printf (" \n x = %d, y = %d from modular function", *a, *b);


}
RESULT

Thus the C program to Swapping numbers using Call by value and Call by Reference
is executed and the result is verified.
FUNCTIONS: CALL, RETURN, PASSING PARAMETERS BY
(VALUE, REFERENCE), PASSING ARRAYS TO FUNCTION

EX. No: 6d
TO CALCULATE THE SUM OF ARRAY ELEMENTS BY PASSING
DATE : TO A FUNCTION

AIM:

To write a C program to calculate the sum of array elements by passing to a


function

ALGORITHM:

Step 1: Start
Step 2: declared and create an num variable
Step 3: num array is passed to calculateSum()
Step 4: calculatesum(num)function call ,Call the function float
calculateSum(float num[])
Step 5: Assign float sum = 0.0;
Step6: to find the sum of all element using for loop and return the value
Step 7: print the result

PROGRAM :

#include <stdio.h>
#include<conio.h>
float calculateSum(float num[]);
int main()
{
float result, num[] = {23.4, 55, 22.6, 3, 40.5, 18};

// num array is passed to calculateSum()


result = calculateSum(num);
printf("Result = %.2f", result);
return 0;
}
float calculateSum(float num[])
{
float sum = 0.0;

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


{
sum += num[i];
}

return sum;
}

RESULT

Thus the C program to calculate the sum of array elements by passing to a function is
executed and the result is verified.
RECURSION

EX. No: 7
DATE : BINARY SEARCH USING RECURSION

AIM:

To write a C program to Binary Search using Recursion.

ALGORITHM:

Step 1: Start

Step 2: declare and initialize the variable

Step 3 : Find the middle element of array. using ,

middle = initial_value + end_value / 2 ;

Step 4 : if middle = key value, return ‘element found’ and index.

Step 5 : if middle > key value, call the function with end_value = middle - 1 .

Step 6 : if middle < key value, call the function with start_value = middle + 1 .

Step 7 : exit.

PROGRAM:

#include<stdio.h>
#include<conio.h>
int binarysearch(int[],int,int,int);
void main()
{
int a[10],n,i,first,last,middle,search,position;
clrscr();
printf("enter number of element\n");
scanf("%d",&n);
printf("enter the element\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("enter value to be search");
scanf("%d",&search);
first=0;
last=n-1;
position=binarysearch(a,search,first,last);

if(position==-1)
printf("key not found");
else
printf("key found at position%d",position+1);
getch();
}
int binarysearch(int b[],int k,int l,int h)
{
int middle;
if(l>h)
return -1;
middle=(l+h)/2;
if(k==b[middle])
return(middle);
else if(k<b[middle])
binarysearch(b,k,l,middle-1);
else
binarysearch(b,k,middle+1,h);
return(middle);
}

RESULT

Thus the C program to Binary Search using Recursion is executed and the
result is verified.
POINTERS: POINTERS TO FUNCTIONS, ARRAYS,STRINGS,
POINTERS TO POINTERS, ARRAY OF POINTERS

EX. No: 8a
DATE : SALARY CALCULATION USING POINTER TO FUNCTION

AIM:

To write a C program to salary calculation using pointer to function

ALGORITHM:

Step 1: Start
Step 2: declared the variable
Step 3: enter the employee current salary
Step 4: enter the bonus
Step 5: Call the function void salaryhike(int *var, int b)
Step 6: calculate the salary
Step 7: print the final salary

PROGRAM:

#include<stdio.h>
#include<conio.h>
void salaryhike(int *var, int b)
{
*var = *var+b;
getch();
}
int main()
{
int salary=0, bonus=0;
clrscr();
printf("Enter the employee current salary:");
scanf("%d", &salary);
printf("Enter bonus:");
scanf("%d", &bonus);
salaryhike(&salary, bonus);
printf("Final salary: %d", salary);
return 0;
}

RESULT

Thus the C program to salary calculation using pointer to function is executed


and the result is verified.
POINTERS: POINTERS TO FUNCTIONS, ARRAYS,STRINGS,
POINTERS TO POINTERS, ARRAY OF POINTERS

EX. NO: 8b
C PROGRAM TO ACCESS ELEMENTS OF A 2-D ARRAY
DATE : USING A POINTER TO AN ARRAY.

AIM:

To write a C program to access elements of a 2-d array using a pointer to an


array.

ALGORITHM:

Step 1: Start
Step 2: declare array size and assign to the value
Step 3: declare the pointer variable ptr to an array of 4 integers
Step 4: ptr contains the base address of array arr.
Step 5: print the pointer variable address and accessing the value
Step 6: Stop

PROGRAM:

#include<stdio.h>
#include<conio.h>
int main()
{
int arr[3][4] = {
{10, 11, 12, 13},
{20, 21, 22, 23},
{30, 31, 32, 33}
};
int (*ptr)[4];
ptr = arr;
printf("%p %p %p\n", ptr, ptr + 1, ptr + 2);
printf("%p %p %p\n", *ptr, *(ptr + 1), *(ptr + 2));
printf("%d %d %d\n", **ptr, *(*(ptr + 1) + 2), *(*(ptr + 2) + 3));
printf("%d %d %d\n", ptr[0][0], ptr[1][2], ptr[2][3]);

return 0;
}

RESULT

Thus the C program to access elements of a 2-d array using a pointer to an array
is executed and the result is verified.
POINTERS: POINTERS TO FUNCTIONS, ARRAYS,STRINGS, POINTERS
TO POINTERS, ARRAY OF POINTERS

EX. No: 8c
C PROGRAM DEMONSTRATING THE CONCEPT OF

DATE : PRINTING ARRAY OF POINTERS TO STRING AND THE


ADDRESSES

AIM:

To write a C program to demonstrating the concept of printing array of


pointers to string and the addresses.

ALGORITHM:

Step 1: Start

Step 2: declare and initialize char *a[ ] = {"one", "two", "three"};


Step 3: enter values within each string location using for loop
Step 4: Print the addresses within each string location using for loop
Step 5: Stop

PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i;
char *a[5]={"One","Two","Three","Four","Five"};
printf("The values in every string location are : \n");
for(i=0;i<5;i++)
{
printf("%s\n",a[i]);
}
printf("The address locations of every string values are : \n");
for(i=0;i<5;i++)

printf("%d\n",a[i]);
}
}

RESULT

Thus the C program to demonstrating the concept of printing array of pointers


to string and the addresses is executed and the result is verified.
POINTERS: POINTERS TO FUNCTIONS, ARRAYS, STRINGS,
POINTERS TO POINTERS, ARRAY OF POINTERS

EX. No: 8d
C PROGRAM TO STORE THE ADRESS OF ANOTHER
POINTER AND ACCESSING THE VALUE STORED AT
DATE :
THE POINTER

AIM:

To write a C program to store the adress of another pointer and accessing the
value stored at the pointer

ALGORITHM:

Step 1: Start

Step 2: declare variable and pointer

Step 3: pointer p is pointing to the address of a

Step 4: pointer pp is a double pointer pointing to the address of pointer p

Step 5: print Address of a

Step 6: print the address of p

Step 7: print the value stored at the address contained by p

Step 8: print the value stored at the address contained by the pointer stored at pp

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main ()
{
int a = 10;
int *p;
int **pp;
clrscr();
p = &a;
pp = &p;
printf("address of a: %x\n",p);

printf("address of p: %x\n",pp);
printf("value stored at p: %d\n",*p);
printf("value stored at pp: %d\n",**pp);
getch();
}

RESULT

Thus the C program to store the address of another pointer and accessing the
value stored at the pointer is executed and the result is verified.
POINTERS: POINTERS TO FUNCTIONS, ARRAYS, STRINGS,
POINTERS TO POINTERS, ARRAY OF POINTERS

EX. No: 8e
DEVELOP A PROGRAM USING POINTERS TO COMPUTE THE
SUM, MEAN, AND STANDARD DEVIATION OF ALL ELEMENTS
DATE : STORED IN AN ARRAY OF N REAL NUMBERS.

AIM:

To write a C program to develop a program using pointers to compute the sum,


mean, and standard deviation of all elements stored in an array of n real numbers

ALGORITHM:

Step 1: Start
Step 2: Read n
Step 3: For every value of n read the x
Step 4: Initialize sum=0 and i=0
Step 5: For every value of n and i, comuter sum using sum = sum + (*(x+i) – mean) * ( *
( x+i) – mean)
Step 6: Using the sum value computer variance = sum / n and deviation = sqrt (variance )
Step 7: Display mean, variance, deviation
Step 8: Stop

PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int n , i;
float x[20],sum,mean;
float variance , deviation;
printf("Enter the value of n \n");
scanf("%d",&n);
printf("enter %d real values \n",n);
for (i=0;i<n;i++)
{

scanf("%f",(x+i));
}
sum=0;
for(i=0;i<n;i++)
{
sum= sum+*(x+i);
}
printf("sum=%f\n",sum);
mean=sum/n;
sum=0;
for(i=0;i<n;i++)
{
sum=sum+(*(x+i)-mean)*(*(x+i)-mean);
}
variance=sum/n;
deviation=sqrt(variance);
printf("mean(Average)=%f\n",mean);
printf("variance=%f\n",variance);
printf("standard deviation=%f\n",deviation);
}

RESULT

Thus the C program to develop a program using pointers to compute the


sum, mean, and standard deviation of all elements stored in an array of n real
numbers is executed and the result is verified.
STRUCTURES: NESTED STRUCTURES, POINTERS TO STRUCTURES,
ARRAYS OF STRUCTURES AND UNIONS

EX. No: 9a
DATE : PRINT THE STUDENT DETAILS USING NESTED STRUCTURES

AIM:

To write a C program to print the student details using nested structure

ALGORITHM:

Step 1: Start

Step 2: declare student structure

Step 3: declare class structure

Step 4: enter the class name and student details using for loop

Step 5: print the details using for loop

Step 6: stop

PROGRAM:

#include <stdio.h>
#include<conio.h>
//student structure declaration
struct student
{
char name[50];
int roll;
};

//class structure declaration


struct class
{
char className[50];

struct student std[100]; //maximum


};

int main()
{
int i,n;
char temp;
struct class cls;

printf("Enter class name: ");


fgets(cls.className, 50, stdin);
printf("Enter total number of students in a class: ");
scanf("%d",&n);

for(i=0;i<n;i++)
{
printf("Enter student [%d] roll no.: ",i+1);
scanf("%d",&cls.std[i].roll);
printf("Enter student [%d] name: ",i+1);
scanf("%c",&temp); //read last CR (new line) character and ignore
fgets(cls.std[i].name,50,stdin);
}
//print details
printf("\nDetails are:\n");
printf("CLASS NAME: %s\n",cls.className);
for(i=0;i<n;i++)
printf("student[%d]:
%05d\t%s\n",i+1,cls.std[i].roll,cls.std[i].name);
return 0;

RESULT

Thus the C program to print the student details using nested structure is executed
and the result is verified
STRUCTURES: NESTED STRUCTURES, POINTERS TO STRUCTURES,
ARRAYS OF STRUCTURES AND UNIONS

EX. No: 9b
PRINT THE EMPLOYEE DETAILS USING POINTER TO
DATE : STRUCTURES

AIM:

To write a C program to print the employee details using pointer to structures

ALGORITHM:

Step 1: Start

Step 2: declare employee structure

Step 3: declare the pointer variable

Step 4: enter the employee details

Step 5: pointer ptr is pointing to the address of employee_one ,ptr = &employee_one;

Step 6: Printing structure members using arrow operator

Step 7: stop

PROGRAM:

#include <stdio.h>
#include<conio.h>
struct employee
{
char name[100];
int age;
float salary;
char department[50];
};
int main()
{
struct employee employee_one, *ptr;
printf("Enter Name, Age, Salary and Department of Employee\n");
scanf("%s %d %f %s", &employee_one.name, &employee_one.age,
&employee_one.salary, &employee_one.department);
ptr = &employee_one;
printf("\nEmployee Details\n");
printf(" Name : %s\n Age : %d\n Salary = %f\n Dept : %s\n",
ptr->name, ptr->age, ptr->salary, ptr->department);

return 0;
}

RESULT

Thus the C program to print the employee details using pointer to structures
is executed and the result is verified
STRUCTURES: NESTED STRUCTURES, POINTERS TO STRUCTURES,
ARRAYS OF STRUCTURES AND UNIONS

EX. No: 9c
ARRAYS OF STRUCTURES AND UNIONS
DATE :

AIM:

To write a C program to using arrays of structures and unions

ALGORITHM:

PRINT THE STUDENTS MARK DETAIL USING ARRAYS OF STRUCTURES

Step 1: Start

Step 2: declare employee structure

Step 3: declare the structure variable

Step 4: enter student information using for loop

Step 5: Displaying Information using for loop

Step 6: Stop

ALGORITHM:
UNION AND INTERSECTION OF TWO SORTED ARRAYS

Step 1: Start

Step 2: declare array

Step 3: Use two index variables i and j, initial values i = 0, j = 0

Step 4: If arr1[i] is smaller than arr2[j] then print arr1[i] and increment i.

Step 5: If arr1[i] is greater than arr2[j] then print arr2[j] and increment j.

Step 6: If both are same then print any of them and increment both i and j.

Step 7: Print remaining elements of the larger array.


PROGRAM:
PRINT THE STUDENTS MARK DETAIL USING ARRAYS OF STRUCTURES

#include<stdio.h>
#include<conio.h>

/* Declaration of structure */
struct student
{
char name[30];
int roll;
float marks;
};

int main()
{
/* Declaration of array of structure */
struct student s[3];

int i;
clrscr();

for(i=0;i< 3;i++)
{
printf("Enter name, roll and marks of student:\n");
scanf("%s%d%f",s[i].name, &s[i].roll, &s[i].marks);

}
printf("student marks details are:\n");
for(i=0;i< 3;i++)

{
printf("Name: %s\n",s[i].name);
printf("Roll: %d\n", s[i].roll);
printf("Marks: %f\n\n", s[i].marks);
}

return 0;
}

PROGRAM:
UNION AND INTERSECTION OF TWO SORTED ARRAYS

#include<stdio.h>
#include<conio.h>

/* Function prints union of arr1[] and arr2[]


m is the number of elements in arr1[]
n is the number of elements in arr2[] */
int printUnion(int arr1[], int arr2[], int m, int n)
{
int i = 0, j = 0;
while (i < m && j < n)
{
if (arr1[i] < arr2[j])
printf(" %d ", arr1[i++]);
else if (arr2[j] < arr1[i])

printf(" %d ", arr2[j++]);


else
{
printf(" %d ", arr2[j++]);
i++;
}
}
while(i < m)
printf(" %d ", arr1[i++]);
while(j < n)
printf(" %d ", arr2[j++]);
}
/* Driver program to test above function */
int main()

{
int arr1[] = {11, 12, 14, 15,16};
int arr2[] = {12, 13, 15, 17};
int m = sizeof(arr1)/sizeof(arr1[0]);
int n = sizeof(arr2)/sizeof(arr2[0]);
printUnion(arr1, arr2, m, n);
getchar();
return 0;
}

RESULT

Thus the C program to using arrays of structures and unions is executed and the
result is verified
FILES: READING AND WRITING, FILE POINTERS, FILE OPERATIONS,
RANDOM ACCESS, PROCESSOR DIRECTIVES

EX. No: 10a


WRITING SOME OF THE CHARACTERS AND READING,
DATE : PRINTING , WRITTEN CHARACTERS.

AIM:

To write a C program to writing some of the characters and reading, printing,


written characters.

ALGORITHM:

Step 1: Start

Step2: Creating variable of file pointer

Step 3: Opening/creating a file

Step 4: Write some of the characters in a file

Step 5: Reading one by one character from a file

Step 6: Closing a file

PROGRAM:

#include< stdio.h >


#include<conio.h>
int main()
{

FILE *fp; /* file pointer*/


char fName[20];

printf("\nEnter file name to create :");


scanf("%s",fName);
/*creating (open) a file*/
fp=fopen(fName,"w");
/*check file created or not*/
if(fp==NULL)
{
printf("File does not created!!!");
exit(0); /*exit from program*/

}
printf("File created successfully.");
/*writting into file*/
putc('A',fp);
putc('B',fp);
putc('C',fp);

printf("\nData written successfully.");


fclose(fp);

/*again open file to read data*/


fp=fopen(fName,"r");
if(fp==NULL)
{
printf("\nCan't open file!!!");
exit(0);
}

printf("Contents of file is :\n");

printf("%c",getc(fp));
printf("%c",getc(fp));
printf("%c",getc(fp));
fclose(fp);
return 0;

RESULT

Thus the C program to writing some of the characters and reading,


printing written characters is executed and the result is verified
FILES: READING AND WRITING, FILE POINTERS, FILE
OPERATIONS, RANDOM ACCESS, PROCESSOR DIRECTIVES

EX. No: 10b


PROGRAM TO FIND THE NUMBER OF CHARACTERS IN THE
DATE : GIVEN TEXT FILE USING FILE POINTERS

AIM:

To write a C program to find the number of characters in the given text files using
file pointers

ALGORITHM:

Step 1: Start

Step 2: declare and initialize the variable

Step 3: Open a file in read mode using file pointer.

Step 4: Read a character from file.

Step 5: Iterate through , increment count by 1 for each characters

Step 6: Repeat all these steps till all the chatacter from the files has been read.

Step 7: Stop

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char ch;

int noc = 0;
fp = fopen("test.txt", "r");
while(1)
{
ch = fgetc(fp);
if(ch == EOF)
{
break;
}

noc++;
}
fclose(fp);
printf("\nNumber of characters in file: %d", noc);
}

RESULT

Thus the C program to find the number of characters in the given text files using
file pointers is executed and the result is verified
FILES: READING AND WRITING, FILE POINTERS, FILE
OPERATIONS, RANDOM ACCESS, PROCESSOR DIRECTIVES

EX. No: 10c


C PROGRAM TO FIND SIZE OF A FILE USING FILE
DATE : OPERATIONS

AIM:

To write a C program to find size of a file using file operations

ALGORITHM:

Step 1: Begin

Step 2: function findfileSize()

Step 3: Open a file pointer fp in read only mode.

Step 4: If fp is equals to null then

Step 5: Print “File not found” and return -1.

Step 6: Else count the file size.

Step 7: Close the file.

Step 8: Put the file pointer at the beginning of the file

Step 9: Declare a integer variable result and initialize it with the output of the ftell()
function.

Step 10: Close file pointer fp.

Step 11: Return result.

Step 12: End

PROGRAM:

#include <stdio.h>
#include<conio.h>
int findfileSize(char f_n[])
{
FILE* fp = fopen(f_n, "r"); // opening a file in read mode

if (fp == NULL) // checking whether the file exists or not


{
printf("File Not Found!\n");
return -1;
}
fseek(fp, 0L, SEEK_END);
int res = ftell(fp); //counting the size of the file
fclose(fp); //closing the file
return res;
}
int main() {
char f_n[] = { "b.txt" }; //file name is “b.txt” whose size is to be determined
int result = findfileSize(f_n);
if (result != -1)
printf("Size of the file is %ld bytes \n", result); //printing the file size
return 0;
}

RESULT

Thus the C program to find size of a file using file operations is executed and
the result is verified.
FILES: READING AND WRITING, FILE POINTERS, FILE
OPERATIONS, RANDOM ACCESS, PROCESSOR DIRECTIVES

EX. No: 10d


WRITE A PROGRAM IN C TO SAVE ALPHABET A TO Z IN FILE
DATE : AND THEN PRINT THE LETTERS USING RANDOM ACCESS

AIM:

To write a C program to save alphabet a to z in file and then print the letters using
random access

ALGORITHM:

Step 1: Start

Step 2: declared variable

Step 3: open file in write mode

Step 4: check the condition if (fptr != NULL)


Print the File created successfully
else
print the Failed to create the file

Step 5: write data in file using for loop

Step 6: close the file

Step 7: open file for reading mode and read all character in the file

Step 8: print the character and the current position


PROGRAM:

#include <stdio.h>
#include<conio.h>

int main(void)
{

// integer variable
int i;

// character variable
char ch;

// file pointer

FILE *fptr;

// open file in write mode


fptr = fopen("char", "w");

if (fptr != NULL) {
printf("File created successfully!\n");
}
else {
printf("Failed to create the file.\n");
// exit status for OS that an error occured
return -1;
}

// write data in file


for (ch = 'A'; ch <= 'Z'; ch++) {
putc(ch, fptr);
}

// close connection
fclose(fptr);

// reference
printf("\nReference:\n");
for (i = 0; i < 26; i++)
{
printf("%d ", (i+1));
}
printf("\n");
for (i = 65; i <= 90; i++)
{
// print character
printf("%c", (i));

// manage space
if (i - 65 >= 9)

{
printf(" ");
}
else {
printf(" ");
}
}
printf("\n\n");

// open file for reading


fptr = fopen("char", "r");

printf("Curr pos: %ld\n", ftell(fptr));

// read 1st char in the file

fseek(fptr, 0, 0);
ch = getc(fptr);

printf("1st char: %c\n", ch);

printf("Curr pos: %ld\n", ftell(fptr));

// read 5th char in the file


fseek(fptr, 4, 0);
ch = getc(fptr);
printf("5th char: %c\n", ch);

printf("Curr pos: %ld\n", ftell(fptr));

// read 26th char in the file


fseek(fptr, 25, 0);
ch = getc(fptr);
printf("26th char: %c\n", ch);

printf("Curr pos: %ld\n", ftell(fptr));

// rewind
printf("rewind\n");
rewind(fptr);

printf("Curr pos: %ld\n", ftell(fptr));

// read 10th char in the file


fseek(fptr, 9, 0);
ch = getc(fptr);
printf("10th char: %c\n", ch);

printf("Curr pos: %ld\n", ftell(fptr));


// read 15th char in the file
fseek(fptr, 4, 1); // move 4 bytes forward from current position
ch = getc(fptr);

printf("15th char: %c\n", ch);

printf("Curr pos: %ld\n", ftell(fptr));

// read 20th char in the file


fseek(fptr, 4, 1); // move 4 bytes forward from current position
ch = getc(fptr);
printf("20th char: %c\n", ch);

printf("Curr pos: %ld\n", ftell(fptr));

// close connection
fclose(fptr);

return 0;
}

RESULT

Thus the C program to save alphabet a to z in file and then print the letters using
random access is executed and the result is verified.
FILES: READING AND WRITING, FILE POINTERS, FILE
OPERATIONS, RANDOM ACCESS, PROCESSOR DIRECTIVES

EX. No: 10d


TO CHECK STUDENT SCORED GRADE USING
DATE : PREPROCESSOR DIRECTIVE

AIM:

To write a C program to check student scored Grade using preprocessor directive

ALGORITHM:

Step 1 : Start
Step 2 : define marks
Step 3 : #if macro_condition
statements
#endif macro_condition
Statements
#If condition
statements
#elif condition
Statement
#else
statements
#endif

PROGRAM:

#include <stdio.h>
#include<conio.h>
#define MARKS 90
int main()
{
#ifdef MARKS
printf("MARKS macro has been defined \n");
#endif
#if MARKS >90
printf("Student has scored GRADE A");
#elif MARKS >60
printf("Student has scored GRADE B");
#else
printf("Student has scored GRADE C");
#endif
return 0;
}

RESULT

Thus the C program to check student scored Grade using preprocessor directive
is executed and the result is verified.

You might also like