PCD Manual
PCD Manual
DEPARTMENT
of
COMPUTER SCIENCE AND ENGINEERING
LAB MANUAL
Prepared By
Department of CSE, GAT
GLOBAL ACADEMY OF TECHNOLOGY
VISION
Become a premier institution imparting quality education in engineering and
management to meet the changing needs of society.
MISSION
M1. Create environment conducive for continuous learning through quality
teaching and learning processes supported by modern infrastructure.
VISION
To achieve academic excellence and strengthen the skills to meet emerging
challenges of computer science and engineering.
MISSION
M1. To impart strong theoretical foundations in the field of Computer
Science and Engineering accompanied with extensive practical training.
M2. To inculcate research and innovation spirit among students through
interaction with industry and projects that address societal issues.
M3. Instill professional ethics and social values amongst students with
concern for environment.
PSO
PSO1: Design, Implement and test system software and application software
to meet the desired needs.
PSO2: Develop solutions in the area of communication networks, data base
Systems and computing systems.
Global Academy of Technology
Course Details
Course Name: Computer Programming Lab.
Course Code: 15CPL16/26.
Course prerequisite: Basic Mathematics knowledge and Logical thinking.
Course objectives
Upon completion of this course, students are expected to:
1. Understand various parts of a computer and write algorithms and flow chart to solve
problems.
2. Familiarize with Turbo C/Dev C++ Editor and write, compile and execute programs
using C Programming concepts.
3. Analyze and implement programs using derived, user data types and functions.
4. Write programs for creating files and perform operations on files.
Course outcomes
Upon successful completion of this course, students should be able to:
PART A
Demonstration of Personal Computer and its Accessories:
Laboratory Session-2: Write-up on RAM, SDRAM, FLASH memory, Hard disks, Optical
media, CDROM/R/RW, DVDs, Flash drives, Keyboard, Mouse, Printers and Plotters.
Introduction to flowchart, algorithm and pseudo code.
Note: These TWO Laboratory sessions are used to fill the gap between theory classes and
practical sessions. Both sessions are to be evaluated as lab experiments.
PART B
Laboratory Experiments:
Implement the programs with WINDOWS / LINUX platform using appropriate
C compiler.
1. Design and develop a flowchart or an algorithm that takes three coefficients (a, b, and c)
of a Quadratic equation (ax2+bx+c=0) as input and compute all possible roots. Implement a C
program for the developed flowchart/algorithm and execute the same to output the possible
roots for a given set of coefficients with appropriate messages.
2. Design and develop an algorithm to find the reverse of an integer number NUM and
check whether it is PALINDROME or NOT. Implement a C program for the developed
algorithm that takes an integer number as input and output the reverse of the same with
suitable messages. Ex: Num: 2014, Reverse: 4102, Not a Palindrome
3. a. Design and develop a flowchart to find the square root of a given number N.
Implement a C program for the same and execute for all possible inputs with appropriate
messages. Note: Don’t use library function sqrt(n).
Global Academy of Technology
b. Design and develop a C program to read a year as an input and find whether it is leap year
or not. Also consider end of the centuries.
4. Design & develop an algorithm to evaluate polynomial f(x) = a4x4 + a3x3 + a2x2 + a1x +a0,
for a given value of x and its coefficients using Horner’s method. Implement a C program for
the same and execute the program with different set of values of coefficients and x.
5. Draw the flowchart and Write a C Program to compute Sin(x) using Taylor series
approximation given by Sin(x) = x - (x3/3!) + (x5/5!) - (x7/7!) + …….
Compare your result with the built- in Library function. Print both the results with appropriate
messages.
6. Develop an algorithm, implement and execute a C program that reads N integer numbers
and arrange them in ascending order using Bubble Sort.
7. Develop, implement and execute a C program that reads two matrices A (m x n ) and B
(p x q ) and Compute product of matrices A and B. Read matrix A and matrix B in row major
order and in column major order respectively. Print both the input matrices and resultant
matrix with suitable headings and output should be in matrix format only. Program must
check the compatibility of orders of the matrices for multiplication. Report appropriate
message in case of incompatibility.
8. Develop, implement and execute a C program to search a Name in a list of names using
Binary searching Technique.
10. a. Design and develop a C function RightShift(x ,n) that takes two integers x and n as
input and returns value of the integer x rotated to the right by n positions. Assume the integers
are unsigned. Write a C program that invokes this function with different values for x and n
and tabulate the results with suitable headings.
b. Design and develop a C function isprime(num) that accepts an integer argument and returns
1 if the argument is prime, a 0 otherwise. Write a C program that invokes this function to
generate prime numbers between the given ranges.
Global Academy of Technology
11. Draw the flowchart and write a recursive C function to find the factorial of a number, n!,
defined by fact(n)=1, if n=0. Otherwise fact(n)=n*fact(n-1). Using this function, write a C
n
program to compute the binomial coefficient Cr. Tabulate the results for different values of
n and r with suitable messages.
12. Given two university information files “studentname.txt” and “usn.txt” that contains
students Name and USN respectively. Write a C program to create a new file called
“output.txt” and copy the content of files “studentname.txt” and “usn.txt” into output file in
the sequence shown below. Display the contents of output file “output.txt” on to the screen.
13. Write a C program to maintain a record of n student details using an array of structures
with four fields (Roll number, Name, Marks, and Grade). Assume appropriate data type for
each field. Print the marks of the student, given the student name as input.
14. Write a C program using pointers to compute the sum, mean and standard deviation of all
elements stored in an array of n real numbers.
Global Academy of Technology
1 Observation Book 4
2 Record / Manual 8
TOTAL 12
1 Write-Up 12
2 Conduction 56
3 Viva Voce 12
TOTAL 80
TABLE OF CONTENTS
1. Design and develop a flowchart or an algorithm that takes three coefficients (a, b, and c) of a
Quadratic equation (ax2+bx+c=0) as input and compute all possible roots. Implement a C
program for the developed flowchart/algorithm and execute the same to output the possible
roots for a given set of coefficients with appropriate messages.
Theory:
A quadratic equation is a polynomial equation of the second degree. The general form is ax2 +
bx + c=0, where a, b, and c are constants, with a ≠ 0. (If a = 0, the equation becomes a Linear
Equation.)
Solving for ‘x’ then gives
Algorithm :
step 1: read a, b, c
step 2: if (a == 0)
write “invalid data”
exit
end if
disc = b*b-4*a*c
deno = 2*a
step 3: if (disc>0)
write “roots are real and distinct”
root1=(-b+√disc)/deno
root2=(-b-√disc)/deno
write “root1,root2”
else if (disc = = 0)
write “roots are real and equal”
root1=root2=-b/deno
write “root1,root2”
else
write “roots are complex”
root1 = -b/deno
root2 = √|disc|/deno
write “root1+iroot2”
write “root1-iroot2”
step 4: stop.
Flowchart :
Start
Read a,b,c
F T
Is a == 0?
disc ← (b * b) – 4 * a * c
deno ← 2 * a
F
Is disc>0?
Print Invalid
data
T
T
Print “Roots are complex”
Print “roots are real
& equal”
root1← rp + i ip
root2← rp – i ip
Program 1:
#include<stdio.h>
#include<math.h>
#include<process.h>
void main( )
{
float a,b,c,disc,deno,rootl,root2,ip,rp;
if (a == 0)
{
printf("\n invalid data");
getch();
exit(0);
}
Run 1:
Enter values of co-efficient
2
4
2
Roots are real and equal:
Rootl=Root2 =-1.000000
Run 2:
Enter values of co-efficient
2
8
1
Roots are real and distinct:
Rootl = -0.129171 and Root2 = -3.870829
Run 3:
Enter values of co-efficient
4
5
6
Roots are complex:
Rootl = -0.625000 + i1.053269
Root2 = -0.625000 -i1.053269
Run 4:
Enter values of co-efficient
0
5
6
Invalid data
OUTPUT:
2. Design and develop an algorithm to find the reverse of an integer number NUM and check
whether it is PALINDROME or NOT. Implement a C program for the developed algorithm
that takes an integer number as input and output the reverse of the same with suitable
messages. Ex: Num: 2014, Reverse: 4102, Not a Palindrome.
Theory:
A palindrome number or numeral palindrome is a 'symmetrical' number like 16461, which
remains the same when its digits are reversed. The term palindromic is derived from palindrome,
which refers to a word like rotor that remains unchanged under reversal of its letters. The
palindromic numbers (in decimal) are:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161,
171, 181, 191, …
Algorithm:
Step 2: temp=num
Step 5: if(num==rev)
write “ num is a Palindrome”
else
write “ num is not a Palindrome”
end if
Step 6 : stop.
Flowchart:
Program 2:
#include<stdio.h>
#include<process.h>
void main ( )
{
int num , temp , digit , rev;
rev = 0;
if (num= = rev)
printf ("\n %d is a palindrome",num);
else
printf ("\n %d is not a palindrome",num);
getch();
}
Run 1:
Enter any number 2332
Reversed number is = 2332
2332 is a palindrome
Run 2:
Enter any number 4324
Reversed number is=4234
4324 is not a plindrome
OUTPUT:
3a: Design and develop a flowchart to find the square root of a given number N. Implement
a C program for the same and execute for all possible inputs with appropriate messages.
Note: Don’t use library function sqrt (n).
Algorithm:
Flowchart:
Start
j=0.0001
Read num1
num← fabs(num1)
F i←0
i←i + j i<num
T
F
is (i*i)>num?
T
i←i-j,Tbreak
is num1>=0 ?
F
T
Print num1, i Print num1, i“i”
Stop
Program 3a:
#include<stdio.h>
#include<conio.h>
void main()
{
float i,j;
float num,num1;
j=0.0001; // accuracy
num=fabs(num1);
if (num1>=0)
printf("Square Root of %f is %f",num1,i);
else
printf("Square Root of %f is (%f)i",num1,i);
getch();
Run 2:
Enter any number: -4
Square root of 4.000000 is 2.00 i
OUTPUT:
3b. Design and develop a C program to read a year as an input and find whether it is leap year
or not. Also consider end of the centuries.
Rule 2: If year is not divisible by 400 as well as 100 but it is divisible by 4 then that year are also
leap year.
For example: 2004, 2008, 1012 are leap year.
Flowchart:
Start
Read year
Is
(year%400 == 0) || (((year%400!=0)
&&( year%100 != 0)) || (year%4 ==0))
F
T
T a leap year
print print not a leap
year
year
Stop
Algorithm:
Program 3b:
#include<stdio.h>
void main()
{
int year;
getch();
Run 1: Run 2:
Enter a year to check if it is a leap year Enter a year to check if it is a leap year
2010 2008
2010 is not a leap year. 2008 is a leap year.
OUTPUT:
4. Design, develop and execute a program in C to evaluate the given polynomial, f(x) =
a4x4+a3x3+a2x2+a1x+a0, for a given value of x and coefficients using Horner’s
method.Implement a C program for the same and execute the program with different set of
values of coefficients and x.
Theory:
A univariate polynomial function has the following form:
For example if k = 4 the order of the polynomial is 4 and the function has the following form:
Horner's method is commonly used to find the roots of a polynomial function. However it can
also be used to evaluate the polynomial function for a given value of x.
The main goal of the Horner scheme is to reduce the number of multiplications needed by
isolating the variable (in this case x).
A concrete example:
The main advantage here is that when using Horner's method it is not necessary to use a power
function to evaluate the variable x.
Algorithm:
Flowchart:
Start
Read n , x
F i←0
i+1 i<=n
T
Read a[i]
result ← a[n]
F i← n-1
i-1 i>=0
T
result ←result*x+a[i]
Print result
Stop
Program 4:
#include<stdio.h>
void main()
{
int n,i;
float a[30],x,result;
result=a[n];
getch();
}
RUN 2:
Enter maximum Degree of polynomial
4
Enter Co-efficients of the polynomial
54321
Enter the value of x….
1
Evaluated result =15.000000
OUTPUT:
5. Draw the flowchart and Write a C Program to compute Sin(x) using Taylor series
approximation given by
Sin(x) = x - (x3/3!) + (x5/5!) - (x7/7!) + …….
Algorithm:
Flowchart:
Program 5:
#include<stdio.h>
#include<conio.h>
void main()
{
float x, sum,term,;
int n,i;
for(i=1;i<100;i++)
{
term=(-term*x*x)/((2*i)*(2*i+1)); /* next term*/
sum=sum+term;
}
Run 2:
Enter the value x in degrees:
90
The sine value is 1.000000
OUTPUT:
Compare your result with the built- in Library function. Print both the results with
appropriate messages.
Algorithm:
Step 1: Read x in degrees
Step 2: Convert x to radians
x=x*3.14/180
Step 3: for ( i = 1 to 100)
term = (term*x*x)/((2*i)*(2*i+1))
sum = sum + term
Step 4: Print sum as sin(x) using Taylor Series
Step 5: Print The sine value from built in function is sin(x)
Step 6: Stop
Flowchart:
Start
Read x in degrees
x←x*3.14/180
sum← term←x
F
i←1
i←i + 1 i<100
term← (-term*x*x)/((2*i)*(2*i+1))
sum←sum + term
sum←sin(x)
Stop
Program:
#include<stdio.h>
#include<math.h>
void main()
{
float x, sum,term;
int n,i;
for(i=1;i<100;i++)
{
term=(-term*x*x)/((2*i)*(2*i+1));
sum=sum+term;
}
Run 1:
Enter the value x in degrees:
45
The sine value is 0.706825
The sine value from built-in function is 0.706825
Run 2:
Enter the value x in degrees:
90
The sine value is 1.000000
The sine value from built-in function is 1.000000
OUTPUT:
6. Develop an algorithm, implement and execute a C program that reads N integer numbers
and arrange them in ascending order using Bubble Sort.
Theory:
Bubble sort is a simple sorting algorithm that works by repeatedly stepping through the list to be
sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order.
The pass through the list is repeated until no swaps are needed, which indicates that the list is
sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list.
Because it only uses comparisons to operate on elements, it is a comparison sort.
Algorithm :
Flowchart:
Start
Read n
Read n elements
F
i←0
i←i + 1 i<n
T
Read a[i]
Print sorted
Print n
array
elements
i←0
i←i + 1 i<n i ←0 i<n
F
i ←i+1
T i ←i+1
Print a[i] Print a[i]
F j←1
j←j+ 1 j<n
T
Stop
F
i←0
i←i+ 1 i < n-j
T
F is
a[i]>a[i+1] ?
T
temp ←a[i]
a[i] ←a[i+1]
A a[i+1] ←temp
Program 6:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j,temp,a[10],k;
printf("Enter the number of elements\n");
scanf("%d",&n);
printf("Sorted array:\n");
for(i=0;i<n;i++)
printf("%d\n",a[i]);
getch();
}
Run 1:
Enter the number of elements
3
Enter the elements to sort
26
51
8
Given array:
26
51
8
Sorted array:
8
26
51
Run 2:
Enter the number of elements
5
Enter the elements to sort
88
36
5
99
2
Given array:
88
36
5
99
2
Sorted array:
2
5
36
88
99
OUTPUT:
7. Develop, implement and execute a C program that reads two matrices A (m x n ) and B (p x
q ) and Compute product of matrices A and B. Read matrix A and matrix B in row major
order and in column major order respectively. Print both the input matrices and resultant
matrix with suitable headings and output should be in matrix format only. Program must
check the compatibility of orders of the matrices for multiplication. Report appropriate
message in case of incompatibility.
Algorithm:
Step 2: if (n!=p)
print “Aborting!!!!!! Multiplication Of The Above Matrices Not Possible.”
goto step 7
else
print “multiplication possible”
Step 3: for(i=0 to m)
for(j=0 to n)
Read a[i][j]
end for
end for
for (j=0 to q)
for (i=0 to p)
Read b[j][i]
end for
end for
Step 5: for(k=0 to n)
c[i][j] =c[i][j]+a[i][k]*b[k][j]
end for
Flowchart:
Program 7:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,m,n,p,q;
if(n!=p)
{
printf("Aborting!!!!!!\nMultiplication of the Above Matrices Not Possible.");
getch();
exit(0);
}
else
printf("Multiplication Is Possible\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++) //print the first matrix
{
printf(" %d\t ",a[i][j]);
}
printf("\n");
}
printf("The Second Matrix Is:\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++) //print the second matrix
{
printf(" %d\t ",b[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf(" %d\t ",c[i][j]);
}
printf("\n");
}
getch();
}
Run 1:
Enter The Rows And Columns Of The First Matrix: 2 2
Multiplication Is Possible
Run 2:
Enter The Rows And Columns Of The First Matrix: 2 2
Aborting!!!!!!
Multiplication of the Above Matrices Not Possible.
OUTPUT:
8. Develop, implement and execute a C program to search a Name in a list of names using
Binary searching Technique.
Theory:
In computer science, a binary search is an algorithm for locating the position of an item in a
sorted array. The idea is simple: compare the target to the middle item in the list. If the target
is the same as the middle item, you've found the target. If it's before the middle item, repeat
this procedure on the items before the middle. If it's after the middle item, repeat on the items
after the middle
Algorithm:
1. get the middle element;
2. if the middle element equals to the searched value, the algorithm stops;
3. otherwise, two cases are possible:
case1: searched value is less, than the middle element. In this case, go to the step 1 for the part
of the array, before middle element.
case 2: searched value is greater, than the middle element. In this case, go to the step 1 for the
part of the array, after middle element.
Algorithm:
step 1: read n
step 7: stop
Flowchart:
Program 8:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,low,high,mid;
char a[20][20], key[20];
while((strcmp(key,a[mid])!= 0)&&low<=high)
{
if(strcmp(key,a[mid]) > 0)
low=mid+1;
if(strcmp(key,a[mid]) < 0)
high=mid-1;
mid=(low+high)/2;
}
getch();
}
Run 1:
Enter the number of names:
5
Run 2:
Enter the number of names:
4
OUTPUT:
9 i:
Algorithm:
Flowchart:
strcopy(str1,str2)
Start
i ← i+1
strcopy(str1,str2)
T
str2[i] ←str1[i]
i←i+1
Print str2
str2[i] ←’\0’
Stop
return
Program 9 i:
#include<stdio.h>
void strcopy(char[],char[]);
int main()
{
char str1[100],str2[100];
printf("Enter any string: ");
gets(str1);
strcopy(str1,str2);
printf("After copying: %s",str2);
return 0;
}
OUTPUT:
9 ii:
Algorithm:
Flowchart
Start
Read string
F i ←0 i<strlen(s)
i← i+1
T
B
is F
isalpha(s[i])?
T
ch=tolower(s[i])
is
ch == ‘a’ || ch == ‘e’ ||
ch ==’i’ ||
F ch ==’o’|| ch ==’u’? T
T
Consonants++ vowels++
else
print count of
vowels and
consonants
Stop
Program 9ii:
#include<stdio.h>
#include<string.h>
void main()
{
char s[150], ch;
int i,vowels=0, consonants=0;
printf("Enter a string:\n");
gets(s);
for(i=0;i < strlen(s);i++) /* to check the string with vowels and consonants */
{
if( isalpha(s[i]))
{
ch=tolower(s[i]);
if(ch == ‘a’ || ch == ‘e’ || ch ==’i’ || ch ==’o’|| ch ==’u’)
vowels++;
else
consonants++;
}
}
getch();
Run 1:
Enter a string:
Global academy of technology
No of vowels in the given string is: 9
No of consonants in the given string is: 16
Run 2:
Enter a string:
C programming lab
No of vowels in the given string is: 4
No of consonants in the given string is: 11
OUTPUT:
10. a. Design and develop a C function RightShift(x ,n) that takes two integers x and n as input
and returns value of the integer x rotated to the right by n positions. Assume the integers are
unsigned. Write a C program that invokes this function with different values for x and n and
tabulate the results with suitable headings.
Algorithm:
Step 5: Read i
for(i=1 to n)
if(x%2==0)
x=x>>1;
else
x=x>>1;
x+=32768;
end if
return x to step 4
Step 6: Stop
Flowchart:
Program 10 a:
#include<stdio.h>
#include<conio.h>
void main()
{
unsigned int x,res;
int n;
Run 1
Enter the value of x
4
Enter the no. of bits to be rotated
2
The Rotated Value is = 1
Run 2
Enter the value of x
15
Enter the no. of bits to be rotated
1
The Rotated Value is = 32775
OUTPUT:
10 b. Design and develop a C function isprime(num) that accepts an integer argument and
returns 1 if the argument is prime, a 0 otherwise. Write a C program that invokes this function
to generate prime numbers between the given range.
Algorithm:
Flowchart :
isprime(i)
Start
T
is Return 0
Read n1,n2
n=1||n=0?
F
F
i ←n1 i<=n2
i←2 F
i←i+1 i<=n/2
i←i+1
T
T
is F
isprime(i)? F is T Return 0
n%i==0?
print i Return 1
Stop
Program 10 b:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n1,n2;
for(i=n1;i<=n2;i++)
{
if(isprime(i)) // function call
printf("%d\t",i);
}
getch();
}
Run 1:
Enter the range 1 10
2357
Run 2:
Enter the range 0 15
2 3 5 7 11 13
OUTPUT:
11. Draw the flowchart and write a recursive C function to find the factorial of a number, n!,
defined by fact(n)=1, if n=0. Otherwise fact (n) =n*fact (n-1). Using this function, write a C
program to compute the binomial coefficient nCr. Tabulate the results for different values of n
and r with suitable messages.
Algorithm:
Flowchart:
Program 11:
#include<stdio.h>
#include<conio.h>
void main()
{
long int n,r,ncr;
getch();
Run 2:
Enter n and r values: 12 4
Binomial co-efficient: 495
OUTPUT:
12. Given two university information files “studentname.txt” and “usn.txt” that contains
students Name and USN respectively. Write a C program to create a new file called
“output.txt” and copy the content of files “studentname.txt” and “usn.txt” into output file in
the sequence shown below. Display the contents of output file “output.txt” on to the screen.
Student Name USN
Name 1 USN1
Name 2 USN2
Algorithm:
Step 1: Input student names and usn into studentname.txt and usn.txt respectively.
Step 4: While (read a character from file 1and continue till not end of file and read a character
from file 2and continue till not end of file)
Step 7: While (read characters from output.txt file till not end of file) and display it on the
console
Flowchart:
Start
Is T
fp1==NULL Print file
|| not found
fp2==NULL?
F
Open output.txt in write mode
Is
(fscanf(fp1,"%s",
name)!=EOF) F
&&
(fscanf(fp2,"%s",
usn)!=EOF)? fclose output.txt
T
fprint name and usn in output.txt
Is
fscanf(fp3,"%s%s",
name,usn)!=EOF?
F
Stop
Close all files
Program 12:
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE *fp1,*fp2,*fp3;
char name[20],usn[20];
fclose(fp3);
fp3=fopen("output.txt","r");
while(fscanf(fp3,"%s%s",name,usn)!=EOF)
{
printf("%s\t\t\t%s\n",name,usn); /*output characters to console*/
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
}
RUN 1:
Files are merged into third file successfully
NAME USN
Aarthi 1GA10CS001
Archana 1GA10CS002
RUN 2:
File not found.
OUTPUT:
13. Write a C program to maintain a record of “n” student details using an array of structures
with four fields (Roll number, Name, Marks, and Grade). Each field is of an appropriate data
type. Print the marks of the student given student name as input.
Algorithm:
Step 1: Input the number of students and read student data in terms of roll number, student name,
marks and grade respectively.
Step 4: If the name exists then print the student is in list and also marks .
Step 6: Stop.
Flowchart:
Program 13:
#include <stdio.h>
struct student
{ // structure definition
char name[50];
int roll;
int marks;
char grade[2];
}; // end of structure definition
int main()
{
struct student s[100]; // s is an array of structure
char searchname[50];
int i, n;
printf("\n");
}
for(i=0;i<n;++i)
{ /* string comparison, check against all student names until found */
if (strcmp( s[i].name, searchname ) == 0)
{
printf("%s is in the List and her marks is %d\n",s[i].name,s[i].marks);
getch();
return 0;
}
}
Run1:
Enter the number of students:
1
Enter information of students:
For 1 Student
For 1 Student
Roll number: 12
Name: nita
Marks: 97
Grade: A
Run2:
Enter the number of students:
2
Enter information of students:
For 1 Student
For 2 Student
For 1 Student
Roll number: 1234
Name: kusum
Marks: 56
Grade: C
For 2 Student
Roll number: 1235
Name: Lata
Marks: 90
Grade: A
OUTPUT:
14. Write a C program using pointers to compute the sum, mean and standard deviation of all
elements stored in an array of n real numbers.
Algorithm:
Flowchart:
start
F i←0
i<n
i←i+1
T
read a+i
F i←0
i<n
i←i+1
F
i←0 i<n
i←i+1
T
var ← (*(a + i)) - (int)mean
num ← num + var*var
A
Stop
Program 14:
#include <stdio.h>
#include <malloc.h>
#include<math.h>
void main()
{
int i, n, sum = 0, num = 0, var;
float mean, std_dev, variance;
int *a;
printf("\nSum is %d \t",sum);
printf("\nMean is %f \t",mean);
printf("\nStandard Deviation is %f \n",std_dev);
getch();
return;
}
Run 1:
Enter the size of array A
5
Enter Elements of Array
1 2 30 5 4
Sum is 42
Mean is 8.400000
Standard Deviation is 10.899542
Run 2:
Enter the size of array A
4
Enter Elements of Array
12 14 16 18
Sum is 60
Mean is 15.00000
Standard Deviation is 2.236068
OUTPUT:
1) What is a flowchart?
2) What is an Algorithm?
3) What is recursion?
4) What are advantages of flow charts?
5) What are different symbols in flowcharts?
6) What is a connector symbol?
7) Is the following assignment correct? A==10;
8) char a=”r”; Is the declaration correct?
9) What is the maximum length of variable?
10) Can a C keyword used as a variable name?
11) What does an expression contains?
12) How is an expression evaluated?
13) What does the modulus performs?
14) Name different logical operators.
15) What is syntax of conditional operator?
16) Is the scanf statement correct? scanf(“%s”,&a);
17) What is a variable?
18) How a variable is declared?
19) What is a constant?
20) List some valid logical expression.
21) What is the difference between post and pre increment/decrement?
a) when they are stand alone
b) when they are embed in an expression
22) What is a keyword?
23) What are Literals?
24) What are two categories of C constants?
25) What is the range of integer constant?
26) What is the output of printf("%d") ?
27) Is there a similarity between for and while?
28) Difference between if-else if ladder and switch
29) What is ternary operator? Write the syntax
30) Difference between while and do-while
31) In what scenario we have to apply for loop?
32) Does break exits from the two loops?
33) How does continue work?
34) What is string? Difference between string and char
35) Difference between array and linked-lists?
36) Difference between linked-lists and trees?