0% found this document useful (0 votes)
5 views65 pages

New Lab Record - C

The document outlines the development of algorithms, flowcharts, and programs for various basic operations including addition of two numbers, simple interest calculation, arithmetic operations, and data type handling. It includes step-by-step procedures, sample code, and expected input/output for each task. Each section concludes with a confirmation that the program has been completed successfully.

Uploaded by

kirthikasarava7
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)
5 views65 pages

New Lab Record - C

The document outlines the development of algorithms, flowcharts, and programs for various basic operations including addition of two numbers, simple interest calculation, arithmetic operations, and data type handling. It includes step-by-step procedures, sample code, and expected input/output for each task. Each section concludes with a confirmation that the program has been completed successfully.

Uploaded by

kirthikasarava7
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/ 65

EXNO. : 1(A) REG.

NO :
DATE : NAME :

DEVELOP AN ALGORITHM FOR ADDITION OF TWO NUMBERS

AIM

To develop an algorithm for addition of two numbers

ALGORITHM

Step 1: Start

Step 2: Declare variables num1, num2.

Step 3: Read values num1, num2.

Step 4: Add num1, num2 and assign the result to sum.

Sumnum1+num2

Step 5: Display the values of sum.

Step 6: Stop

RESULT

Thus , the algorithm has been developed successfully.


EXNO. : 1(B) REG. NO :
DATE : NAME :

DEVELOP FLOWCHART FOR ADDITION OF TWO NUMBERS


AIM

To develop a flowchart for addition of two numbers

FLOWCHART

RESULT

Thus , the flowchart has been developed successfully.


EXNO. : 1(C) REG. NO :
DATE : NAME :

DEVELOP PSEUDO CODE FOR ADDITION OF TWO NUMBERS


AIM

To develop a pseudo code for addition of two numbers

PSEUDO CODE

Function main():

Declare num1, num2, sum as integers

Display "Enter the first number: "

Input num1

Display "Enter the second number: "

Input num2

sum = num1 + num2

Display "The sum of", num1, "and", num2, "is:", sum

Return 0

End Function

RESULT

Thus, the pseudo code has been developed successfully.


EXNO. : 2a REG. NO :
DATE : NAME :
DEVELOP A PROGRAM TO FIND THE SIMPLE INTEREST

AIM

To Develop a Program to find the simple interest.

PROCEDURE

1. Start the program


2. Get the input value P,N,R
3. Calculate the interest using si = (amount * rate * time) / 100;
4. Display the value of si
5. End the program

PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int amount, rate, time, si;
printf("\nEnter Principal Amount : ");
scanf("%d", &amount);
printf("\nEnter Rate of Interest : ");
scanf("%d", &rate);
printf("\nEnter Period of Time : ");
scanf("%d", &time);
si = (amount * rate * time) / 100;
printf("\nSimple Interest : %d", si);
}
INPUT AND OUTPUT

Enter Principal Amount : 500


Enter Rate of interest : 5
Enter Period of Time : 2
Simple Interest : 50

RESULT

Thus, the Program has been executed and the output was verified.
EXNO. : 2B REG. NO :
DATE : NAME :

PERFORM VARIOUS ARITHMETIC OPERATIONS


AIM

To perform various arithmetic operations

PROCEDURE
Step1: Start
Step2:get a and b values
Step3: Calculate c=a+b
Step4 :calculate d=a-b
Step 5:calculate e=a*b
Step6:calculate f=a/b
Step 7 : Calculate g=a%b
Step 8 : display all the outputs
Step 9: stop

PROGRAM

#include <stdio.h>
int main()
{
int a,b;
printf(“ Enter A and B values”);
scanf(“%d%d”, &a, &b);
printf(“Addition =%d”,a+b);
printf(“Subtraction =%d”,a-b);
printf(“Multiplication =%d”,a*b);
printf(“Division =%d”,a/b);
printf(“Remainder =%d”,a%b);
}

INPUT AND OUTPUT

Enter A and B value


10 20
Addition = 30
Subtraction= -10
Multiplication = 200
Division = 0.5
Remainder = 0

RESULT

Thus the program has been completed successfully.


EXNO. : 3A REG. NO :
DATE : NAME :

GET ALL THE PRIMARY TYPE DATA AND DISPLAY THE SAME
AIM

To get all the Primary type data and display the same

PROCEDURE

Step1.start
Step2.Get all the primary datatypes
Step 3: display the same
Step4: stop

PROGRAM
#include <stdio.h>
void main()
{
int a;
float b;
double c;
char d;

printf("Enter character: ");


scanf("%c", &d);

printf("Enter Integer Value: ");


scanf("%d", &a);

printf("Enter float value: ");


scanf("%f", &b);

printf("Enter double value: ");


scanf("%lf", &c);

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


printf("Integer: %d\n", a);
printf("Float: %f\n", b);
printf("Double: %lf\n", c);
}

INPUT AND OUTPUT

Enter Character:a
Enter Integer value:7
Enter float value:3.1
Enter double value: 4.000000001
Character:a
Integer:7
Float:3.1
Double:4.000000001

RESULT

Thus the program has been completed successfully


EXNO. : 3B REG. NO :
DATE : NAME :

CONVERT FLOAT INTO INTEGER DATA TYPE


AIM

To convert float into integer data type for given float value

PROCDURE

Step1:start
Step2:get float value
Step3: convert float into integer
Step4: display the value
Step6: stop

PROGRAM

#include <stdio.h>
void main()
{
int a;
float b;
printf("Enter the float value: ");
scanf("%f", &b);
a= (int)b;
printf("%d\n", a);
}
INPUT AND OUTPUT

Enter the float value: 4.0


4

RESULT

Thus the program has been completed successfully.


EXNO. : 4A REG. NO :
DATE : NAME :

CHECK WHETHER THE GIVEN NUMBER IS POSITIVE OR NOT USING


CONDITIONAL OPERATOR
AIM

To check whether the given number is positive or not using Conditional operator

PROCEDURE

Step1:start
Step2:get n value
Step3: n is greater than 0 , display n is positive otherwise display n is negative
Step 4:stop

PROGRAM

#include<stdio.h>
void main()
{
int n;
printf(“enter a value”);
scanf(“%d”,&n);
(n>0)?printf(“ positive”):printf(“negative”)
}
INPUT AND OUTPUT

Enter a value:3
positive

Enter a value:-7
Negative

RESULT

Thus the program has been completed successfully


EXNO. : 4B REG. NO :
DATE : NAME :

PERFORM VARIOUS BITWISE OPERATOR OPERATIONS

AIM

To perform various Bitwise operator operations

PROCEDURE

Step1: Start
Step2: get a and b value
Step3: apply bitwise operators and display the result
Step 4: Stop

PROGRAM

#include<stdio.h>
void main()
{
int a,b;
printf(“enter the a and b value”);
scanf(“%d%d”,&a,&b);
printf(“bitwise and : %d”,a&b);
printf(“bitwise or : %d”,a|b);
printf(“bitwise xor : %d”,a^b);
printf(“bitwise complement : %d”,~a);
printf(“bitwise shift left : %d”,a<<1);
printf(“bitwise shift right : %d”,a>>1);
}
INPUT AND OUTPUT

Enter a and b value


1
2
Bitwise and: 0
Bitwise or :3
Bitwise xor :3
Bitwise complement:-2
Bitwise shift left :3
Bitwise shift right :0

RESULT

Thus the program has been completed successfully.


EXNO. : 4C REG. NO :
DATE : NAME :

DEVELOP A PROGRAM TO FIND AREA OF CIRCLE

AIM

To find area of circle

PROCEDURE

Step1: Start
Step 2: get a radius
Step 3: calculate area= 3.14*r*r
Step 4: Display area
Step 5: Stop

PROGRAM

#include<stdio.h>
Void main()
{
Int r;
Float area;
Printf(“enter the radius”);
Scanf(“%d”,&r;);
Area=3.14*r*r;
Printf(“Area of circle :%f”,area);
}
INPUT AND OUTPUT
Enter radius : 4
Area of circle : 50.24

RESULT

Thus the program has been completed successfully.


EXNO. : 5A REG. NO :
DATE : NAME :

FIND THE GIVEN NUMBER IS POSITIVE OR NEGATIVE OR ZERO NUMBER

AIM

To check whether a given number is Positive or Negative or Zero.

PROCEDURE

1. Start the program.


2. Get the input value using number variable.
3. if (number<0) used to check whether the value negative or positive
4. display the result
5. End the program

PROGRAM
#include <stdio.h>
#include <conio.h>
void main()
{
int number;
clrscr();
printf(" Finding positive,Negative and Zero \n");
printf("_____________________________________ \n");
printf("Enter a number\n");
scanf ("%d", &number);
printf("The Given Number is %d \n",number);
if (number > 0)
printf ("%d is a positive number\n", number);
else if (number<0)
printf ("%d is a negative number\n", number);

else
printf ("%d is a Zero \n", number);

INPUT AND OUTPUT

Finding positive,Negative and Zero


____________________________
Enter a number 4
4 is a positive number

Finding positive,Negative and Zero


____________________________
Enter a number -4
-4 is a negative number

Finding positive,Negative and Zero


____________________________
Enter a number 0
0 is a Zero
RESULT

Thus the program has been completed successfully.


EXNO. : 5B REG. NO :
DATE : NAME :

CHECK WHETHER THE GIVEN CHARACTER IS VOWEL AND CONSONANT


USING SWITCH CASE

AIM

To find the given character is vowel and consonant using switch case

PROCEDURE

1. Start the program


2. Get the input value using ch variable.
3. Switch case used to check whether the input constant or vowels
4. display the result
5 .End the program

PROGRAM

#include<stdio.h>
void main()
{
char ch;
clrscr();
printf(" Finding Vowels Or Consonant \n");
printf(" ___________________________ \n");
printf("\n Enter any character:");
scanf("%c",&ch);
clrscr();

switch(tolower(ch))
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("\n The character %c is vowel!",ch);
break;
default :
printf("\n The character %c is consonant!",ch);
}
}

INPUT AND OUTPUT

Finding Vowels Or Consonant


___________________________
Enter any character:a
The character a is vowel

Finding Vowels Or Consonant


___________________________
Enter any character:b
The character b is consonant

RESULT

Thus the program has been completed successfully


EXNO. : 5C REG. NO :
DATE : NAME :

CHECK WHETHER THE GIVEN NUMBER IS PRIME NUMBER OR NOT

AIM

To check whether the given number is prime number or not

PROCEDURE
1.Get a number N and initialize the counter is zero
2. start the loop I from 1 to N
2.1 check the given number is divisible by i
2.1.1 increase the counter value by one
2.1.2 the loop will be continued until reach N
3.If the value of the counter is 2, the given number is prime ,otherwise the given number is not
prime.

PROGRAM
#include<stdio.h>
void main()
{
int i,count=0,n;
clrscr();
printf(" Checking Prime Or Not \n");
printf(" _____________________ \n");
printf("\nEnter a number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
count++;
}

if(count==2)
printf("\n Given Number %d is prime",n);
else
printf("\nGiven number %d is not a prime",n);
}

INPUT AND OUTPUT

Checking Prime Or Not


_____________________
Enter a number: 5
Given number 5 is prime

Checking Prime Or Not


_____________________
Enter a number: 4
Given number 4 is not prime

RESULT

Thus the program has been completed successfully


EXNO. : 5D REG. NO :
DATE : NAME :

GENERATE FIBONACCI SERIES

AIM

To generate Fibonacci series

PROCEDURE
1. Get N Value
2. Initialize f1=0 and f2=1
3. Display f1 and f2
4. Start the loop I from 3 to n
4.1 calculate f3=f1+f2
4.2 display f3
4.3 assign f1=f2 and f2=f3
4.4 continue the 4 th step until it reaches N.

PROGRAM
#include <stdio.h>
int main()
{
int i ,n, f1=0, f2=1;
clrscr();
printf("Enter number of terms: ");
scanf("%d",&n);
clrscr();
printf(" Fibonacci Series \n");
printf(" ________________ \n");
printf(" The Given Term is : %d\n",n);
printf("Fibonacci Series: \n%d \n%d\n", f1, f2);
for (i=3;i<=n;i++)
{
F3=f1+f2
F1=f2;
F2=f3;
printf("%d\n",f3);
}
}

INPUT AND OUTPUT

Enter number of terms: 6


Fibonacci Series
_____________
The Given Term is : 6
Fibonacci Series:
0
1
1
2
3
5

RESULT

Thus the program has been completed successfully


EXNO. : 6A REG. NO :
DATE : NAME :

ARRANGE THE ELEMENTS IN AN ASCENDING ORDER AND DESCENDING


ORDER

AIM

To arrange the elements in an ascending order and descending order

PROCEDURE

 Input size of array and elements in array. Store it in some variable say size and arr.
 To select each element from array, run an outer loop from 0 to size - 1. The loop
structure must look like for(i=0; i<size; i++).
 Run another inner loop from i + 1 to size - 1 to place currently selected element at
its correct position. The loop structure should look like for(j = i + 1; j<size; j++).
 Inside inner loop to compare currently selected element with subsequent element
and swap two array elements if not placed at its correct position.Which is if(arr[i]
> arr[j]) then swap arr[i] with arr[j].

PROGRAM

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],j,n,i,temp;
printf(" Enter the size of the array \t");
scanf("%d",&n);
printf(" enter the elements for an array \t");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
clrscr();
printf("\n Sorting Element \n ");
printf(" _______________ \n");
printf(" Size of an Given Array %d \n",n);
printf(" Before Sorting Array are \n");
for(i=1;i<=n;i++)
{
printf("\t %d",ar[i]);
}

for(i=1;i<=n-1;i++)
{
for(j=i+1;j<=n;j++)
{
if(a[i]>=a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}

printf("\n\n Ascending Order are - \n");


for(i=1;i<=n;i++)
printf("\t %d",a[i]);
printf("\n\n Descending Order are - \n");
for(i=n;i>=1;i--)
printf("\t %d",a[i]);
}
INPUT AND OUTPUT
Enter the value of N
5
Enter elements for an array
234
780
130
56
90
The numbers arranged in Ascending order are given below
56
90
130
234
780
The numbers arranged in Descending order are given below
780
234
130
90
56

RESULT

Thus the program has been completed successfully


EXNO. : 6B REG. NO :
DATE : NAME :

SEARCH AN ELEMENT IN AN ARRAY USING LINEAR SEARCH

AIM
To search an element in an array using linear search method.
PROCEDURE
1. Set the value Set j to 1
2. Initially, we need to mention or accept the element to be searched from the user.
3. Then, we create a for loop and start searching for the element in a sequential
fashion.
4. As soon as the compiler encounters a match i.e. array[element] == key value,
return the element along with its position in the array.
5. If no values are found that match the input, it returns -1.
PROGRAM

#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],flag=0,n,i,ele;
printf(" enter the size of the array \t");
scanf("%d",&n);
printf(" enter the elements for an array \t");
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
printf(“enter searching element”);
scanf(“%d”,&ele);
for(i=1;i<=n;i++)
{
if (a[i]==ele)
{
flag=1;
break;
}
}
if (flag ==1)
printf(“element is found”);
else
printf(“element is not found”);
}

INPUT AND OUTPUT

enter the size of the array

enter the elements in the array

12
45
2
7
1
Enter searching element
2
Element is found

RESULT
Thus the program has been completed successfully
EXNO. : 6C REG. NO :
DATE : NAME :

FIND SMALLEST & LARGEST NUMBER AMONG N NUMBERS

AIM

To find the smallest and largest number among ‘n’ numbers

PROCEDURE
1. Declare the variables j,n,a[20]
2. Get the Max and Min value
3. Get the input using scanf() statement
4. Using if (a[i] > max) maximum value assigned in max variable
5. Using else if (a[i] < min) minimum value assigned in min variable
6. Finally max variable and min variable printed

PROGRAM
#include <stdio.h>
#include<conio.h>
void main ()
{
int i, j, n, a[20], max, min;
clrscr ();
printf ("Enter n value \n");
scanf ("%d", &n);
printf ("Enter the elements for an array\n");
for (i = 1; i <= n; i++)
{
scanf ("%d", &a[i]);
}
max = a[1]; min = a[1];
for (i = 1; i <= n; i++)
{
if (a[i] > max)
max = a[i];
else
min = a[i];
}
printf ("Largest number is %d\n Smallest number is %d", max, min);
}
INPUT AND OUTPUT
Enter n value
5
Enter the elements for an array
5
1
6
8
2
Largest Number is : 8
Smallest Number is :1

RESULT

Thus the program has been completed successfully


EXNO. : 7A REG. NO :
DATE : NAME :

MATRIX ADDITION AND SUBTRACTION

AIM
To calculate addition of two matrices and subtraction of two matrices.

PROCEDURE
1. Declare the variables i,j,a[10][10],b[10][10],c[10][10],d[10][10],m1,n1,m2,n2;
2. Get the Rows and Columns value
3. Get the input using scanf() statement
4. Using c[i][j] = a[i][j] + b[i][j] ; Addition values assigned in c[i][j] array.
5. Using d[i][j] = a[i][j] - b[i][j];;Subtraction values assigned in d[i][j] array.
6. Finally c[i][j] array and d[i][j] array printed

PROGRAM
#include<stdio.h>
void main()
{
int i,j,a[10][10],b[10][10],c[10][10],d[10][10],m1,n1,m2,n2;
printf("Enter the number of Rows of Mat1 : ");
scanf ("%d",&m1);
printf("Enter the number of Columns of Mat1 : ");
scanf ("%d",&n1);
for(i=1;i<=m1;i++)
for(j=1;j<=n1;j++)
{
printf("Enter the Element a[%d][%d] : ",i,j);
scanf("%d",&a[i][j]);
}
printf("Enter the number of Rows of Mat2 : ");
scanf ("%d",&m2);
printf("Enter the number of Columns of Mat2 : ");
scanf ("%d",&n2);
for(i=1;i<=m2;i++)
{
for(j=1;j<=n2;j++)
{
printf(" Enter the Element b[%d][%d] :",i,j);
scanf("%d",&b[i][j]);
}
}
for(i=1;i<=m1;i++)
{
for(j=1;j<=n1;j++)
{
c[i][j] = a[i][j] + b[i][j] ;
d[i][j] = a[i][j] - b[i][j];
}
}
printf("\nThe Addition of two Matrices \n");
printf(" ____________________________ \n");
for(i=1;i<=m1;i++)
{
for(j=1;j<=n1;j++ )
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
printf("\nThe Subtraction of two Matrices \n");
printf(" ____________________________ \n");
for(i=1;i<=m1;i++)
{
for(j=1;j<=n1;j++ )
{
printf("%d\t",d[i][j]);
}
printf("\n");
}
}
INPUT AND OUTPUT
Enter the number of Rows of Mat1 : 2
Enter the number of Columns of Mat1 : 2
Enter the Element a[0][0] : 4
Enter the Element a[0][1] : 4
Enter the Element a[1][0] : 4
Enter the Element a[1][1] : 4
Enter the number of Rows of Mat2 : 2
Enter the number of Columns of Mat2 : 2
Enter the Element b[0][0] :1
Enter the Element b[0][1] :2
Enter the Element b[1][0] :3
Enter the Element b[1][1] :4

The Addition of two Matrices


____________________________
5 6
7 8

The Subtraction of two Matrices


____________________________
3 2
1 0

RESULT

Thus the program has been completed successfully


EXNO. : 7B REG. NO :
DATE : NAME :

MATRIX MULTIPLICATION
AIM

Program to multiply two matrices.

PROCEDURE

1. Declare the variables m, n, p, q, c, d, k, sum;


2. Get the Rows and Columns value
3. Get the input using scanf() statement
4. Using sum + first[c][k]*second[k][d];
5. Values assigned in sum variables.
6. Finally assigned to multiply[c][d]) and array printed

PROGRAM

#include <stdio.h>

#include <conio.h>

void main()

int a[3][3],b[3][3],c[3][3],i,j;

printf("\nENTER VALUES FOR MATRIX A:\n");

for(i=1;i<=3;i++)

for(j=1;j<=3;j++)
scanf("%d",&a[i][j]);

printf("\nENTER VALUES FOR MATRIX B:\n");

for(i=1;i<=3;i++)

for(j=1;j<=3;j++)

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

for(i=1;i<=3;i++)

for(j=1;j<=3;j++)

for(k=1;k<=3;k++)

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

printf("\nTHE VALUES OF MATRIX C ARE:\n");

for(i=1;i<=3;i++)

for(j=1;j<=3;j++)

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

printf(“\n”);

}
INPUT AND OUTPUT

ENTER VALUES FOR MATRIX A :

1 1 1

1 1 1

1 1 1

ENTER VALUES FOR MATRIX B :

1 1 1

1 1 1

1 1 1

THE VALUES OF MATRIX C ARE :

333
333
333

RESULT

Thus the program has been completed successfully


EXNO. : 8A REG. NO :
DATE : NAME :

CHECK WHETHER THE GIVEN STRING IS PALINDROME OR NOT

AIM

To check whether the given string is palindrome or not

PROCEDURE

1. Get the string s


2. Copy the string s into s1
3. Find the reverse of s
4. Compare s and s1
5. If it is return 0 , the given string is palindrome otherwise it not palindrome

PROGRAM

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char s[10],s1[10];
int i,len,flag=0;
clrscr();
printf("\nENTER A STRING: ");
scanf(“%s”,s);
strcpy(s1,s);
strrev(s);
if (strcmp(s,s1)==0)
printf(“the given string is palindrome”);
else
printf(“the given string is not palindrome”);
}

INPUT AND OUTPUT

ENTER A STRING: level


The given string is palindrome
ENTER A STRING: leve
The given string is not palindrome

RESULT

The Program has been executed and the output was verified.
EXNO. : 8B REG. NO :
DATE : NAME :

STRING MANIPULATION
AIM

Program for manipulating the strings using string handling functions

PROCEDURE

1. Get the First String and second String.


2. Find the string length using strlen() function and print the length of both string
3. strlcat(), strcpy(),strcmp() and strrev() string function used for string
concatenation,string copy, comparison and reverse.
4. Values assigned in s1 and s2.
5. Finally s1 and s2 are printed.

PROGRAM

#include<stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
char s1[20],s2[20];
int l1,l2;
printf("Enter the strings\n");
scanf("%s %s",s1,s2);
printf(" String Manipulation \n");
printf(" ___________________ \n");
printf(" First String :%s \n",s1);
printf(" Second String: %s \n\n",s2);
l1=strlen(s1);
l2=strlen(s2);
printf( "Length of First String %d \n",l1);
printf(" Length of Second String %d \n\n",l2);
printf(" Before Concatenation First String is %s\n",s1);
strcat(s1,s2);
printf(" After Concatenation Second String is %s \n",s1);
printf(" Before Copying Second String is %s \n",s2);
strcpy(s2,s1);
printf(" After Copying Second String is %s \n\n",s2);
if(strcmp(s1,s2)==0)
printf("\nBoth Strings are equal\n");
else
printf("\nBoth Strings are not equal");
printf(" Reverse of the string is %s \n\n",s2);
}

INPUT AND OUTPUT

Enter the strings


Radha
raja
String Manipulation
_________________
First String : Radha
Second String :raja
Length of first string :5
Length of second string :4

Before concatenation of first string : Radha


After concatenation of second string : Radharaja

Before copying second string : raja


After copying second string :Radharaja

Both strings are equal

Reverse of the string : ajarahdaR

RESULT

The Program has been executed and the output was verified.
EXNO. : 8C REG. NO :
DATE : NAME :

STUDENT MARK SHEET PREPARATION USING STRUCTURE

AIM

Program to generate the mark sheet of the student using structure

PROCEDURE

1. Get the name of the student ,rollno ,m1,m2,m3


2. Calculate the total ,average mark scored of the student
3. if (st[i].m1>50&&st[i].m2>50&&st[i].m3>50), display PASS,otherwise display
FAIL.
4. The above same to be followed for all the student by using loop and display the
same
PROGRAM
#include<stdio.h>
struct student
{
char name[30];
int rollno;
int m1,m2,m3;
int total;
float avg;
};
struct student st[30];
void main()
{
int i,n;
clrscr();
printf("Enter how many students: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\nEnter Student name \n");
scanf("%s",&st[i].name);
printf(" Enter Student Roll No. \n");
scanf("%d",&st[i].rollno);
printf("Enter Subject Mark : ");
scanf("%d",&st[i].m1);
scanf("%d",&st[i].m2);
scanf("%d",&st[i].m3);
}
printf(" Student Mark Sheet \n");
printf("________________________________________________________ \n");
printf(“Name Rollno M1 M2 M3 Total average Result \n”);
printf(“_________________________________________________________\n”);
for(i=1;i<=n;i++)
{
printf(" %s ",st[i].name);
printf(" %d ",st[i].rollno);
printf(" %d %d %d ",st[i].m1,st[i].m2,st[i].m3);
st[i].total=st[i].m1+st[i].m2+st[i].m3;
st[i].avg=st[i].total/3;
printf(" %d ",st[i].total);
printf(" %f ",st[i].avg);
if(st[i].m1>50&&st[i].m2>50&&st[i].m3>50)
printf(" PASS\n");
else
printf(" FAIL \n");
}
Printf(“__________________________________________________”);
}

INPUT AND OUTPUT

Enter how many students : 3

Student Mark Sheet


______________________________________________________________
Name Rollno M1 M2 M3 Total Average Result
Xxx 1 60 70 80 210 70 PASS

YYY 2 20 60 40 120 40 FAIL

_____________________________________________________________

RESULT

The Program has been executed and the output was verified.
EXNO. : 9A REG. NO :
DATE : NAME :

FUNCTION WITH ARGUMENTS AND WITH RETURN VALUE

AIM

Program to sum of two numbers using function with arguments and with return value.

PROCEDURE

1. Get a and b values


2. Call add() function through main function that is used for adding two values and
return result value to the main()
3. Print the result

PROGRAM

#include<stdio.h>
int add(int x,int y);
void main ()
{
int a, b,k;
printf(“Enter the value for A:”);
scanf(“%d”,&a);
printf(“Enter the value for B:”);
scanf(“%d”,&b);
k=add(a,b);
printf(“Result :%d”,k);
}
int add (int x,int y)
{
int z;
z = x+y;
return(z);
}
INPUT AND OUTPUT

Enter the value of A: 5

Enter the value of B: 6

Result : 11

RESULT

The Program has been executed and the output was verified.
EXNO. : 9B REG. NO :
DATE : NAME :

SWAP TWO NUMBERS USING CALL BY VALUE AND CALL BY


REFERENCE

AIM

Program to swap two numbers using call by value and call by reference.

PROCEDURE

1.Get a and b values


2.pass the values to swap1() and pass address to swap2()
3.perform the operation of swapping by using respective function
4.display a and b values.

PROGRAM
#include<stdio.h>
#include<conio.h>
void swap1(int,int);
void swap2(int*,int*);
void main()
{
Int a,b;
clrscr();
printf("\n\nEnter the value of A and B=");
scanf("%d%d",&a,&b);
printf("\n\nBefore swapping A=%d,B=%d",a,b);
swap1(a,b);
printf("\n\nAfter call by value,values are A=%d,B=%d",a,b);
swap2(&a,&b);
printf("\n\nAfter call by reference,values are A=%d,B=%d",a,b);
getch();
}
void swap1(inta,int b)
{
int temp;
temp=a;
a=b;
b=temp;
}
void swap2(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
INPUT AND OUTPUT

Enter the value of A and B=


10
20

Before swapping A=10,B=20


After call by value,values are A=10,B=20
After call by reference,values are A=20,B=10

RESULT

The Program has been executed and the output was verified.
EXNO. : 9C REG. NO :
DATE : NAME :

FIND FACTORIAL OF GIVEN NUMBER USING RECURSIVE FUNCTION

AIM

Program to calculate factorial of a number using recursion.

PROCEDURE

1. Get N value for finding factorial


2. Pass N to function and call
3. Define stopping condition and Calculate factorial value by using recurrence
relation n*fact(n-1) and return
4. Display the factorial value

PROGRAM

#include<stdio.h>
#include<conio.h>
int factorial( int n);
void main()
{
int n;
clrscr();
printf("Enter a positive integer: ");
scanf("%d",&n);
clrscr();
printf(" Factorial \n");
printf(" _______________ \n");
printf(" The Given Value is %d \n",n);
printf("Factorial of %d is %d", n, factorial(n));
}
int factorial( int n)
{
if(n==0)
return (1);
else
return (n*factorial(n-1);
}

INPUT AND OUTPUT

Enter positive integer :5

Factorial
________

The given value is :5

Factorial of 5 is 120

RESULT

The Program has been executed and the output was verified.
EXNO. : 10A REG. NO :
DATE : NAME :

FIND LARGEST ELEMENT USING DYNAMIC MEMORY ALLOCATION


AIM

To find largest element using dynamic memory allocation.

PROCEDURE

1. Take N elements and a pointer to store the address of N elements.


2. Allocate memory dynamically for N elements.
3. Store the elements in the allocated memory.
4. Traverse the array arr[] to find the largest element among all the numbers by comparing
the values using pointers.

PROGRAM
#include <stdio.h>
#include <stdlib.h>
int main()
{
int num;
float *data;
printf("Enter the total number of elements: ");
scanf("%d", &num);
data = (float *)calloc(num, sizeof(float));
if (data == NULL) {
printf("Error!!! memory not allocated.");
exit(0);
}
for (int i = 0; i < num; ++i) {
printf("Enter Number %d: ", i + 1);
scanf("%f", data + i);
}
for (int i = 1; i < num; ++i) {
if (*data < *(data + i))
*data = *(data + i);
}
printf("Largest number = %.2f", *data);
return 0;
}
INPUT AND OUTPUT

Enter the total number of elements: 5


Enter Number 1: 3.4
Enter Number 2: 2.4
Enter Number 3: -5
Enter Number 4: 24.2
Enter Number 5: 6.7
Largest number = 24.20

RESULT

The Program has been executed and the output was verified.
EXNO. : 10B REG. NO :
DATE : NAME :

ADDITION OF TWO NUMBERS USING POINTER


AIM

To perform addition of two numbers using pointer

PROCEDURE
1.Get two values
2.assign the address of two values into pointer variables
3.calculate c=*a+*b
4.display c

PROGRAM
#include<stdio.h>
Void main()
{
Int c,d,*a,*b,c;
Printf(“enter two values”);
Scanf(“%d%d”,&c,&d);
A=&c;
B=&d;
C=*a+*b;
Printf(“result :%d”,c);
}
INPUT AND OUTPUT
Enter two values
4
5
Result:9

RESULT

Thus the program has been completed successfully


EXNO. : 11 REG. NO :
DATE : NAME :

FILE : CREATE ,WRITE AND READ

AIM

To perform various file operations


PROCEDURE

1. Open a file with write mode


2. Read a value from keyboard and write a content into the file
3. Close a file
4. Open a file with read mode
5. Read a content from a file and write on the screen
6. Close a file

PROGRAM
#include<stdio.h>
Void main()
{

FILE *fp; /* file pointer*/


Int no;
// write a content into the file
Fp=fopen(“data.txt”,”w”);
Printf(“enter the no”);
Scanf(“%d”,&no);
Fprintf(fp,”%d”,no);
Fclose(fp);
//Read a content from the file
Fp=fopen(“data.txt”,”r”);
fscanf(fp,“%d”,&no);
printf(”%d”, no);
Fclose(fp);
}
INPUT AND OUTPUT

Enter the number


12
12

RESULT

Thus the program has been completed successfully


EXNO. : 12 REG. NO :
DATE : NAME :

FILE HANDLING FUNCTIONS – getw(),putw() and remove()

AIM

To perform operations of file handling functions such as getw(),putw() and remove().

PROCEDURE

1.get no
2.open a file with w+ mode
3.write a no into file
4. move filepointer to first position of the file
5.read a no from file
6.display the no
7.remove the filename from memory
8.close the file

PROGRAM

#include <stdio.h>
void main()
{
FILE *fp;
int no;
char filename[10]=”data.txt”
scanf(“%d”,&no);
fp=fopen(filename,”w+”);
putw(no,fp);
fseek(fp,7,seek_set);
k=getw(fp);
printf(“%d”,k);
remove(filename);
fclose(fp);
}

INPUT AND OUTPUT

10
10

RESULT

The Program has been executed and the output was verified.
EXNO. : 13 REG. NO :
DATE : NAME :

AREA CALCULATION USING MACROS

AIM

To calculate area using macros

PROCEDURE

1. Define a macro
2. Define a function macro
3. Get radius value to calculate area of circle
4. Pass radius value to macro function and Call the macro function
5. Calculate the area
6. Display the result
Program:

#include <stdio.h>
#define PI 3.1415
#define circleArea(r) (PI*r*r)
void main()
{
float radius, area;
printf("Enter the radius: ");
scanf("%f", &radius);
area = circleArea(radius);
printf("Area = %.2f", area);
}
INPUT AND OUTPUT

Enter the radius: 5


Area = 78.54

RESULT

The Program has been executed and the output was verified.

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