8/17/2019 CManual (2)
1/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
1. BRANCHING AND SELECTION
1) WRITE A C-PROGRAM TO FIND THE BIGGEST OF THE
GIVEN THREE NUMBERS
ALGORITHM
Step 1: start
Step 2: Declare variables x,y,z and max as a integer type
Step 3: Read x,y and z values
Step 4: if(x
8/17/2019 CManual (2)
2/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/* Program to find the biggest of the given three numbers */
#include /* printf(), scanf() */
#include /* getch(), clrscr() */
void main()
{
int x,y,z,max;
clrscr(); /* clears the screen */printf("Enter x value:");
scanf("%d",&x); /* reads x from the keyboard */
printf("Enter y value:");
scanf("%d",&y); /* reads y from the keyboard */
printf("Enter z value:");
scanf("%d",&z); /* reads z from the keyboard */
if(x
8/17/2019 CManual (2)
3/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
{
if(x
8/17/2019 CManual (2)
4/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
2.WRITE A C-PROGRAM TO PRINT ELECTRICITY BILLS
WITH SLABS
ALGORITHM
Step 1: start
Step 2: Declare variables mno, cr, pr, n as a integer type and
bill as float type
Step 3: Read mno, cr, pr values
Step 4: Computing number of units consumed
n=cr-pr;Step 5: Calculate Amount based on Units
if(n>=0&&n200&&n400&&n600) then
bill=390+n*1.0
else then
write Invalid number of unitsStep 6: Write mno, bill value
Step 7: Stop
8/17/2019 CManual (2)
5/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/* Program to print Electricity bill with slabs */
#include /* printf(), scanf() */
#include /* getch(), clrscr() */
void main()
{
int n,cr,pr,mno;
char utype;
float bill=0.0;clrscr(); /* clears the screen */
printf("\n\t****************************************");
printf("\n\t*****ELECTRICITY BILL
CALCULATION*******");
printf("\n\t****************************************");
printf("\nEnter meter number :");
scanf("%d",&mno);
/*Reading current and previous readings*/
printf("\nEnter current reading:");
scanf("%d",&cr);
printf("\nEnter previous reading:");scanf("%d",&pr);
/*Computing number of units consumed*/
n=cr-pr;
8/17/2019 CManual (2)
6/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
if(n>=0&&n200&&n400&&n600)
bill=390+n*1.0;
elseprintf("\nInvalid number of units");
if(bill>0)
{
printf("\nThe meter number= %d",mno);
printf("\nThe number of units consumed=%d",n);
printf("\nBill amount for %d units is %f\n",n,bill);
}
getch(); /* reads a char from keyboard but it doesn’t print it on
the screen */
}
8/17/2019 CManual (2)
7/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
3.WRITE A C-PROGRAM TO PRINT STUDENT GRADES
ALGORITHM
Step 1: start
Step 2: Declare variables n1, n2, n3, tot as a integer type
Step 3: Read n1, n2, n3 values
Step 4: Computing Total Marks
tot = n1+n2+n3
write tot
tot=tot/300Step 5: Computing Grade
if(tot >= 80) then
wirte You got A grade
else if ( tot >=60) then
write You got B grade
else if ( tot >=40) then
write You got C grade}
else if ( tot < 40) then
write You Failed in this exam
Step 6: Stop
8/17/2019 CManual (2)
8/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/* Program to print Student grades */
#include /* printf(), scanf() */
#include /* getch(), clrscr() */
void main()
{
int n1,n2,n3,tot;
printf("Enter your mark\n ");
printf("Subject 1:");scanf("%d",&n1);
printf("Subject 2:");
scanf("%d",&n2);
printf("Subject 3:");
scanf("%d",&n3);
if(n1
8/17/2019 CManual (2)
9/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
}
tot=n1+n2+n3;
printf("\n Total Marks %d", tot); // printing outputs
if(tot >= 80){
printf("\n You got A grade"); } // printing outputs
else if ( tot >=60){ // Note the space between
else & if
printf("\n You got B grade");}
else if ( tot >=40){printf("\nYou got C grade");}
else if ( tot < 40){
printf("\n You Failed in this exam");}
getch();
}
8/17/2019 CManual (2)
10/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
2. CONTROL STATEMENTS
1) WRITE A C-PROGRAM TO IMPLEMENT THE
CALCULATOR APPLICATION (USING SWITCH)
ALGORITHM
Step 1: start
Step 2: Declare variables sign as a char data type and a, b as
integer data types
Step 3: Read sign valuesign=getchar()
Step 4: switch(sign)
Step 5: case '+': read a, b values
Write a+b
Step 6: case '-': read a, b values
Write a-b
Step 7: case '*': read a, b values
Write a*b
Step 8: case '/': read a, b values
Write a/b
Step 9: case '%': read a, b valuesWrite a%b
Step 10: default: Invalid operation"
Step 11: Repeat the Steps 3,4,5,6,7,8,9,10 until
8/17/2019 CManual (2)
11/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
while(sign != 'Q' && sign != 'q')
Step 12: Stop
PROGRAM
/*Program to implement the calculator application (using
switch)*/
#include /* printf(), scanf() */
#include /* getch(), clrscr() */
void main(){
int a,b;
char sign;
clrscr();
printf("\nPlease enter an operation +, -, *, /, %, : ");
flush(stdin);
scanf("%c",&sign);
while (sign != 'Q' && sign != 'q')
{
switch(sign)
{case '+': printf("\nEnter 2 numbers : ");
scanf("%d%d",&a,&b);
8/17/2019 CManual (2)
12/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
printf("Addition of %d and %d is
%d\n",a,b,a+b);
break;
case '-': printf("\nEnter 2 numbers : ");
scanf("%d%d",&a,&b);
printf("Subtraction of %d and %d is
%d\n",a,b,a-b);
break;
case '*': printf("\nEnter 2 numbers : ");scanf("%d%d",&a,&b);
printf("Multiplication of %d and %d is
%d\n",a,b,a*b);
break;
case '/': printf("\nEnter 2 numbers : ");
scanf("%d%d",&a,&b);
printf("Division of %d and %d is %d\n",a,b,a/b);
break;
case '%': printf("\nEnter 2 numbers : ");
scanf("%d%d",&a,&b);
printf("Modulus of %d and %d is%d\n",a,b,a%b);
break;
default: printf("\nInvalid Option\n");
8/17/2019 CManual (2)
13/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
break;
}
printf("\nPlease enter an operation +, -, *, /, %, : ");
fflush(stdin);
scanf("%c",&sign);
}
getch();
}
8/17/2019 CManual (2)
14/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO PRINT TABLE FOR A GIVEN
NUMBER
ALGORITHM
Step 1: start
Step 2: Declare variables n, i as Integer data types
Step 3: Read n value
Step 4: set i:=1
Step 5: repeat steps 6,7 until i
8/17/2019 CManual (2)
15/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
printf("\n----------------------");
for(i=1;i
8/17/2019 CManual (2)
16/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO PRINT 1 TO N NATURAL
NUMBERS
ALGORITHM
Step 1: start
Step 2: Declare variables n, i as Integer data types
Step 3: Read n value
Step 4: set i:=1
Step 5: repeat steps 6,7 until i
8/17/2019 CManual (2)
17/96
8/17/2019 CManual (2)
18/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
LOOPING CONSTRUCTS-I
1) WRITE A C-PROGRAM TO CHECK THE GIVEN NUMBER
IS ARMSTRONG OR NOT
ALGORITHM
Step 1: start
Step 2: Declare variables n, r, temp ,count=0 as Integer data
types
Step 3: Read n value Assign temp = n
Step 4: Assign temp = nStep 5: Compute
r=n%10
count=count+(r*r*r)
n=n/10
Step 6: Repeat Step 5 while n>0
Step 7: if count equals to temp then
Write “Given number is Armstrong”
Else
Write “Given number is Not Armstrong”
Step 8: Stop
PROGRAM /* Program to Check the Given Number Is Armstrong Or Not*/
#include
#include
8/17/2019 CManual (2)
19/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
void main()
{
int n,count=0,r,temp;
clrscr();
printf("Enter a number : ");
scanf("%d",&n);
temp=n;
while(n>0)
{r=n%10;
count=count+(r*r*r);
n=n/10;
}
if(count==temp)
printf("\nGiven Number is Armstrong");
else
printf("\nGiven Number is not Armstrong");
getch();
}
8/17/2019 CManual (2)
20/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO CHECK THE GIVEN NUMBER
IS PALINDROME OR NOT
ALGORITHM
Step 1: start
Step 2: Declare variables n, r, temp ,count=0 as Integer data
types
Step 3: Read n value
Step 4: Assign temp = n
Step 5: Computer=n%10;
count=(count*10)+r;
n=n/10;
Step 6: Repeat Step 5 while n>0
Step 7: if count equals to temp then
Write “Given number is Palindrome”
Else
Write “Given number is Not Palindrome”
Step 8: Stop
8/17/2019 CManual (2)
21/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/*Program to check the given number is palindrome or not*/
#include
#include
void main()
{
int n,count=0,r,temp,opt;
clrscr();
printf("Enter a number : ");scanf("%d",&n)
temp=n;
while(n>0)
{
r=n%10;
count=(count*10)+r;
n=n/10;
}
if(count==temp)
printf("\nGiven Number is Palindrome");
elseprintf("\nGiven Number is not Palindrome");
getch();
}
8/17/2019 CManual (2)
22/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO CHECK THE GIVEN NUMBER
IS PERFECT OR NOT
ALGORITHM
Step 1: Start
Step 2: read n
Step 3: set i:=i+1,sum:=0
Step 4: repeat steps 5,6 until i ≤ n/2
Step 5: if n mod i=0
set sum:=sum+iStep 6: set i:=i+1
Step 7: if sum=n
write ‘n is perfect’
else
write ‘n is not perfect’
Step 8: stop
8/17/2019 CManual (2)
23/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/*Program to check the given number is perfect or not*/
#include
#include
void main()
{
int n,i,count=0,r,temp,opt;
clrscr();printf("Enter a number : ")
scanf("%d",&n);
for(i=1;i
8/17/2019 CManual (2)
24/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO CHECK THE GIVEN NUMBER
IS STRONG OR NOT
ALGORITHM
Step 1: start
Step 2: Declare variables n, i, f, r, count=0, temp as Integer data
types
Step 3: Read n value Assign temp = n
Step 4: set i=1 and f=1 r=n%10;
Step 5: compute f=f*i and i=i+1Step 6: Repeat step 5 until i0
Step 9: if count equals to temp then
Write “Given number is Strong”
Else
Write “Given number is not Strong”
Step 10: Stop
PROGRAM
/*Program to check the given number is strong or not*/#include
#include
void main()
8/17/2019 CManual (2)
25/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
{
int n,i,f,r,count=0,temp;
printf("Enter a number: ");
scanf("%d",&n);
while(n>0)
{
i=1;f=1;
r=n%10;
while(i
8/17/2019 CManual (2)
26/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO PRINT THE REVERSE OF THE
GIVEN NUMBER
ALGORITHM
Step 1: start
Step 2: Declare variables n, r, temp ,count=0 as Integer data
types
Step 3: Read n value
Step 4: Compute
r=n%10;count=(count*10)+r;
n=n/10;
Step 5: Repeat Step 5 while n>0
Step 6: write count
Step 7: Stop
8/17/2019 CManual (2)
27/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/* Program to print the reverse of the given number */
#include
#include
void main()
{
int n,count=0,r,temp,opt;
clrscr();
printf("Enter a number : ");scanf("%d",&n);
temp=n
while(n>0)
{
r=n%10;
count=(count*10)+r;
n=n/10;
}
printf("\nReverse of %d is %d",temp,count);
getch();
}
8/17/2019 CManual (2)
28/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO CONVERT THE GIVEN
DECIMAL NUMBER TO BINARY NUMBER
ALGORITHM
Step 1: Start
Step 2: read a decimal number n
Step 3: repeat steps 4,5,6,7 until n>0
Step 4: set r:=n%2
Step 5: set num:=(num×10)+r
Step 6: set cnt:=cnt+1Step 7: set n:=n/2
Step 8: set n:=num
Step 9: repeat steps until cnt>0
Step 10: set r:=n mod10
Step 11: set bin:=(bin×10)+r
Step 12: set cnt=cnt-1
Step 13: set n:=n/10
Step 14: write ‘The binary number is’ bin
Step 15: Stop
8/17/2019 CManual (2)
29/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/* Program to convert the given decimal number to binary
number */
#include
#include
void main()
{
long int n,num=0,bin=0,cnt=0,m;
int r;clrscr();
printf("\nEnter a number:");
scanf("%ld",&n);
m=n;
for(;n>0;n=n/2)
{
r=n%2;
num=(num*10)+r
cnt++;
}
for(n=num;cnt>0;n=n/10){
r=n%10;
bin=(bin*10)+r;
8/17/2019 CManual (2)
30/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
cnt--;
}
printf("\nThe binary number of given decimal number %ld
is %ld",m,bin);
getch();
}
8/17/2019 CManual (2)
31/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
LOOPING CONSTRUCTS-II
1) WRITE A C-PROGRAM TO PRINT SUM OF N NATURAL
NUMBERS
ALGORITHM
Step 1: start
Step 2: read n
Step 3: set i:=1,sum=0
Step 4: repeat steps 5,6,7 until i ≤n
Step 5: read numStep 6: set sum:=sum+num
Step 7: set i:=i+1
Step 8: write sum
Step 9: stop
8/17/2019 CManual (2)
32/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/* Program to print sum of n natural numbers */
#include
#include
void main()
{
int n,i,sum=0,num;
clrscr();
printf("\nEnter value for n:");scanf("%d",&n);
i=1;
do
{
printf("\nEnter a number:");
scanf("%d",&num);
sum=sum+num;
i=i+1;
}while(i
8/17/2019 CManual (2)
33/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO GENERATE FIBONACCI
SERIES UP TO N NUMBERS
ALGORITHM
Step 1: start
Step 2: read n
Step 3: set a:=0,b:=1
Step 4: write a and b
Step 5: set i:=1 repeat steps 6,7,8,9 until i
8/17/2019 CManual (2)
34/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
printf("Fibonacci numbers upto %d\n",n);
printf("------------------------------\n");
printf("%d\t%f\t",a,b);
for(i=1;i
8/17/2019 CManual (2)
35/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO PRINT PRIME NUMBERS
BETWEEN 1 TO N NUMBERS
ALGORITHM:
Step 1: Start
Step 2: read n
Step 3: set i:=1
Step 4: repeat steps 5,6,7,8 until i ≤n
Step 5: set cnt:=0,j=1
Step 6: repeat steps i),ii) until j ≤i i).if i mod j=0
set cnt:=cnt+1
ii). set j:=j+1
Step 7: if cnt=2
write i
Step 8: set i:=i+1
Step 9: Stop
PROGRAM
/* Program to generate Fibonacci series up to n numbers */
#include
#includevoid main()
{
int n,i,j,cnt;
8/17/2019 CManual (2)
36/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
clrscr();
printf("\nEnter value for n:");
scanf("%d",&n);
printf("\nThe Prime Numbers from 1 to %d\n\n",n);
for(i=1;i
8/17/2019 CManual (2)
37/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO PRINT * IN EQUILATERAL
TRIANGLE
ALGORITHM:
Step 1: Start
Step 2: read n
Step 3: set i:=1,k:=1,j:=1
Step 4: repeat steps 5,6,7,8 until i ≤n
Step 5: repeat steps i),ii) until j ≤ n-i
i) write “ “;ii) Set j=j+1;
Step 6: repeat steps a),b) until k
8/17/2019 CManual (2)
38/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
printf("Enter number of rows of the triangle \n");
scanf("%d",&n);
for(i=1;i
8/17/2019 CManual (2)
39/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO PRINT SUM OF FIRST N
NATURAL NUMBERS
ALGORITHM
Step 1: Start
Step 2: declare n, i, sum=0
Step 3: read n
Step 4: set i:=1
Step 5: calculate:
sum = sum + ii++
Step 6: repeat Step 5 until i
8/17/2019 CManual (2)
40/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/* Program to find the sum of first N Natural Numbers */
#include
#include
void main()
{
int n,i,sum=0;
clrscr();
printf("\nEnter N value : ");scanf("%d", &n);
i=1;
do
{
sum = sum + i
i = i++;
}
while(i
8/17/2019 CManual (2)
41/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
3. ARRAYS
1) WRITE A C-PROGRAM TO REMOVE DUPLICATE
ELEMENTS IN THE GIVEN ARRAY
ALGORITHM
Step 1: Start
Step 2: Declare i,j,k,n,a[20],temp as Integer type
Step 3: read n
Step 4: set i:=0Step 5: read a[i] , set i:=i+1
Step 6: repeat Step 5 until i
8/17/2019 CManual (2)
42/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
Step 13: write a[i] , set i:=i+1
Step 14: repeat Step 13 until i
8/17/2019 CManual (2)
43/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
{
if(a[i]==a[j])
{
for(k=j;k
8/17/2019 CManual (2)
44/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO INSERT AN ELEMENT AT THE
SPECIFIED LOCATION OF THE ARRAY
ALGORITHM
Step 1: Start
Step 2: Declare i,j,n,a[20],ins,pos,flag=0 as Integer type
Step 3: read n
Step 4: set i:=0
Step 5: read a[i] , set i:=i+1
Step 6: repeat Step 5 until i
8/17/2019 CManual (2)
45/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
Step 13: write a[i] , set i:=i+1
Step 14: repeat Step 13 until i
8/17/2019 CManual (2)
46/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
printf("\nEnter which Element is u want to Insert:");
scanf("%d",&ins);
for(i=0;i=i;j--)
a[j+1]=a[j];a[i]=ins;
}
}
if(flag==1)
{
n=n+1;
}
else
printf("\n Array index out of size");
printf("\n\nElements after inserting an Element is:");
for(i=0;i
8/17/2019 CManual (2)
47/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO ARRANGE THE GIVEN
ELEMENTS IN THE ASCENDING ORDER
ALGORITHM
Step 1: start
Step 2: Declare i,j,n,a[20],temp as Integer type
Step 3: read n
Step 4: set i:=0
Step 5: read a[i] , set i:=i+1
Step 6: repeat Step 5 until i
8/17/2019 CManual (2)
48/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/*Program to arrange the given elements in the ascending order
*/
#include
#include
void main()
{
int i,j,n,a[20],temp;
clrscr();printf("\nEnter the Size of Array:");
scanf("%d",&n);
printf("\nEnter the Elements of array:");
for(i=0;i
8/17/2019 CManual (2)
49/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("\n\nAfter Sorting Elements are:");
for(i=0;i
8/17/2019 CManual (2)
50/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
STRINGS
1) WRITE A C-PROGRAM TO PERFORM THE FOLLOWING
OPERATIONS WITH AND WITHOUT USING STRING
HANDLING FUNCTIONS
I. LENGTH OF THE STRING
ALGORITHM
Step 1: start
Step 2: Declare and initialize a[10] as Character array and j=0,
l=0, i=0, opt as integersStep 3: read a
Step 4: repeat step 5, 6 until loop breaks
Step 5: read opt
Step 6: if opt==1 then
Write strlen(a)
Else if opt==2 then
(a) Repeat step (b) while a[i]!=’/0’
(b) Set j=j+1and i=i+1
(c) Write j
Else
Break;Step 7: stop
8/17/2019 CManual (2)
51/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/* Program to find length of the string */
#include
#include
void main()
{
char a[10];
int j=0,l=0,i=0,opt;
clrscr();printf("\n Enter String:");
scanf("%s",a)
while(1)
{
printf("\n\n1.Using String Handling
Function\n2.Without using String Handling
Functions\n3.exit\nEnter your Option:");
scanf("%d",&opt);
if(opt==1)
{
l=strlen(a);printf("\n length of the string using Strlen()
:%d",l);
}
8/17/2019 CManual (2)
52/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
else if(opt==2)
{
while(a[i]!='\0')
{
j++;
i++;
}
printf("\n Length of the given string is %d",l);
}else
break;
}
getch();
}
8/17/2019 CManual (2)
53/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
REVERSE OF THE GIVEN STRING
ALGORITHM
Step 1: start
Step 2: declare and initialize a[10], b[10]as Character array and
l=0, i=0, opt as integers
Step 3: read a
Step 4: copy a into b
Step 5: repeat step 6,7 until loop breaks
Step 6: read optStep 7: if opt==1 then
Write strrev(b)
Else if opt==2 then
(d) i=strlen(a)
(e) repeat step (c) until i>0
(f) write a[i]
(g) i=i+1
Else
Break;
Step 8: stop
8/17/2019 CManual (2)
54/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/* Program to reverse the string */
#include
#include
#include
void main()
{
char a[10],b[10];
int l=0,i=0,opt;clrscr();
printf("\n Enter String:");
scanf("%S",a);
strcpy(b,a);
while(1)
{
printf("\n\n1.Using String Handling
Function\n2.Without using String Handling
Functions\n3.exit\nEnter your Option:");
scanf("%d",&opt);
if(opt==1){
printf("\n Reverse of the string using Strrev()
:%s",strrev(b));
8/17/2019 CManual (2)
55/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
}
else if(opt==2)
{
l=strlen(a);
printf("\n Reverse of the given string :");
for(i=l;i>=0;i--)
{
printf("%c",a[i]);
}}
else
break;
}
getch();
}
8/17/2019 CManual (2)
56/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
CONCATENATE THE TWO STRINGS
ALGORITHM
Step 1: start
Step 2: declare and initialize a[10], b[10], c[10] as Character
array and l=0, i=0, opt as integers
Step 3: read a,b
Step 4: repeat step 5,6 until loop breaks
Step 5: read opt
Step 6: if opt==1 thenStrcpy(c,a)
strcat(c,b)
write c
Else if opt==2 then
(h) l=strlen(a)
(i) repeat step (c) until b[i]!=’\0’
(j) set c[l+i]=b[i]
(k) c[l+i]=’\0’
Else
Break;
Step 7: stop
8/17/2019 CManual (2)
57/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/* Program to concatenate two strings */
#include
#include
#include
void main()
{
char a[10],b[10],c[10];
int l=0,i=0,opt;clrscr();
printf("\n Enter String1:");
scanf("%s",a);
printf("\n Enter String2:")
scanf("%s",b);
while(1)
{
printf("\n\n1.Using String Handling
Function\n2.Without using String Handling
Functions\n3.exit\nEnter your Option:");
scanf("%d",&opt);if(opt==1)
{
strcpy(c,a);
8/17/2019 CManual (2)
58/96
8/17/2019 CManual (2)
59/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
COMPARE THE TWO STRINGS
ALGORITHM
Step 1: start
Step 2: declare and initialize a[10], b[10], c[10] as Character
array and l=0, i=0, opt as integers
Step 3: read a,b
Step 4: repeat step 5,6 until loop breaks
Step 5: read opt
Step 6: if opt==1 thenIf(Strcmp(a,b)==0) then
Write Strings are equal
Else
write Strings are not equal
Else if opt==2 then
(l) Set i=0
(m) repeat step (c) until a[i]!=b[i]
(n) if( a[i] ==’\0’ || b[i]=’\0’) then break loop
else set i++
(o) if( a[i] ==’\0’ && b[i]=’\0’) then
write strings are equalElse Strings are not equal
Else
Break;
8/17/2019 CManual (2)
60/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
Step 7: stop
PROGRAM
/* Program to Compare to Strings */
#include
#include
#include
void main()
{
char a[10],b[10];int i=0,opt;
clrscr();
printf("\n Enter String1:")
scanf("%s",a);
printf("\n Enter String2:");
scanf("%s",b);
while(1)
{
printf("\n\n1.Using String Handling Function\n2.Without using
String Handling Functions\n3.exit\nEnter your Option:");
scanf("%d",&opt);if(opt==1)
{
if( strcmp(a,b) == 0 )
8/17/2019 CManual (2)
61/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
printf("\nEntered strings are equal.\n");
else
printf("\nEntered strings are not equal.\n");
}
else if(opt==2)
{
while( a[i] == b[i] )
{if( a[i] == '\0' || b[i] == '\0' )
break;
i++;
}
if( a[i] == '\0' && b[i] == '\0' )
printf("\nEntered strings are equal.\n");
else
printf("\nEntered strings are not equal.\n");
}
else
break;}
getch();}
8/17/2019 CManual (2)
62/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
CONCEPT OF USER DEFINED FUNCTIONS
1) WRITE A C-PROGRAM TO SWAP THE TWO NUMBERS
USING CALL BY VALUE AND CALL BY REFERENCE
ALGORITHM
Step 1: start
Step 2: read x,y
Step 3: write x,y
Step 4: call swapvalue()Step 5: write x,y
Step 6: call swapreference()
Step 7: write x,y
Step 8: stop
void swapvalue(int,int)
Step 1: declare temp
Step 2: temp = b;
b = a;
a = temp;
step 3: write a,b
step 4: stopvoid swapreference(int*, int*)
Step 1: declare temp
Step 2: temp = *b;
8/17/2019 CManual (2)
63/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
*b = *a;
*a = temp;
step 3: write *a,*b
step 4: stop
PROGRAM
/* Program to swap the two numbers using call by value and call
by reference */
#include
#includevoid swapreference(int*, int*);
void swapvalue(int,int);
void main()
{
int x, y;
printf("Enter the value of x and y\n")
scanf("%d%d",&x,&y);
printf("\n----Swap using Call By Value----");
printf("\n\nBefore Swapping\nx = %d\ny = %d\n", x, y);
swapvalue(x, y);
printf("\nAfter Swapping\nx = %d\ny = %d\n", x, y);printf("\n----Swap using Call By Reference----");
printf("\n\nBefore Swapping\nx = %d\ny = %d\n", x, y);
swapreference(&x, &y);
8/17/2019 CManual (2)
64/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
printf("\nAfter Swapping\nx = %d\ny = %d\n", x, y);
getch();
}
void swapreference(int *a, int *b)
{
int temp;
temp = *b;
*b = *a;
*a = temp;printf("\nInside called Function\n");
printf ( "a = %d\nb = %d\n",*a,*b) ;
}
void swapvalue( int a, int b ) // x and y are formal
parameters
{
int t ;
t = a ;
a = b ;
b = t ;
printf("\nInside called Function\n");printf ( "a = %d\nb = %d\n", a, b) ;
}
8/17/2019 CManual (2)
65/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO FIND THE FACTORIAL OF
THE GIVEN NUMBER USING RECURSION
ALGORITHM
Step 1: start
Step 2: Declare n, ft as integer variables
Step 3:read n
Step 4: call fact
ft=fact(n);
Step 5: write n,ftStep 6: stop
int fact(int)
Step 1: if (a==1) then
Return 1;
Else then
Call fact “return (a*fact(a-1))”
Step 2: stop
PROGRAM
/* Program to find the factorial of the given number using
recursion */#include
#include
void main()
8/17/2019 CManual (2)
66/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
{
int n,ft;
int fact(int);
clrscr();
printf("\nEnter the value of n:");
scanf("%d",&n);
ft=fact(n);
printf(\n\n\tFactorial of %d = %d\n",n,ft);
getch();}
int fact(int a)
{
if(a==1)
return 1;
else
return a*fact(a-1);
}
8/17/2019 CManual (2)
67/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO FIND NCR USING FUNCTIONS
ALGORITHM
Step 1: start
Step 2: Declare n, r as integer variables and ncr as long
Step 3: Read n,r
Step 4: call find_ncr
ncr=find_ncr(n,r);
Step 5: write ncr
Step 6: stoplong find_ncr(int, int)
Step 1: declare result as long variable
Step 2: call fact
result=fact(n)/fact(r) *fact(n-r);
Step 3: return result
Step 4: stop
long fact(int)
Step 1: if (a==1) then
Return 1;
Else then
Call fact “return (a*fact(a-1))”Step 2: stop
PROGRAM
8/17/2019 CManual (2)
68/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
/* Program to find ncr using functions */
#include
#include
long fact(int);
long find_ncr(int, int);
void main()
{
int n, r;
long ncr;clrscr();
printf("Enter the value of n and r\n);
scanf("%d%d",&n,&r);
ncr = find_ncr(n, r);
printf("\n\n\t%dC%d = %ld\n", n, r, ncr);
getch();
}
long find_ncr(int n, int r)
{
long result;
result = fact(n)/(fact(r)*fact(n-r));return result;
}
long fact(int n)
8/17/2019 CManual (2)
69/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
{
if(n==1)
return 1;
else
return n*fact(n-1);
}
8/17/2019 CManual (2)
70/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO FIND MEAN AND STANDARD
DEVIATION OF A GIVEN SET OF NUMBERS (Define
functions for mean and standard deviation)
ALGORITHM
Step 1: start
Step 2: Declare n as integer variables and m, x[10] as float
Step 3: read n
Step 4: set i=0;Step 5: read x[i], set i:=i+1;
Step 6: repeat step 5 unti i
8/17/2019 CManual (2)
71/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
void sd(float m,float x[10],int n)
Step 1: declare sum=0 as float variable
Step 2: set i=0;
Step 3: Sum=sum+pow((x[i]-m),2), set i:=i+1;
Step 4: repeat step 3 unti i
8/17/2019 CManual (2)
72/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
printf("\nEnter the value of N :");
scanf("%d", &n);
printf("Enter %d real numbers \n", n);
for (i = 0; i < n; i--)
{
scanf("%f", &x[i]);
}
m=mean(x,n);
sd(m,x,n);getch();
}
float mean(float x[],int n)
{
int i;
float sum=0
for (i=0;i
8/17/2019 CManual (2)
73/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
{
float average, variance, std_deviation,sum=0;
/* Compute variance and standard deviation */
int i=0;
for (i = 0; i < n; i++)
{
sum = sum + pow((x[i] - m), 2);
}
variance = sum/ (float)n;std_deviation = sqrt(variance);
//printf("variance of all elements = %.2f\n", variance);
printf("Standard deviation = %.2f\n", std_deviation);
}
8/17/2019 CManual (2)
74/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
FILE HANDLING OPERATIONS
WRITE A C-PROGRAM TO COUNT NUMBER OF
CHARACTERS, SPACES, WORDS AND LINES IN GIVEN
FILE
ALGORITHM
Step 1: start
Step 2: declare noc, now, nol as integers , fr as FILE Pointers and
fname[20], ch as character variables
Step 3: set noc=0,now=0,nol=0Step 4: read fname
Step 5: open fname in read mode using fr pointer
fr=fopen(fname,”r”);
Step 6: if(fr==null) then
Write “error”
Exit(0);
Step 7: ch=fgetc(fr)
Step 8: repeat step 9 while (ch!=EOF)
Step 9: noc=noc+1;
If(ch==’ ‘) then
now=now+1;if(ch==’\n’) then
nol=nol+1;
now=now+1;
8/17/2019 CManual (2)
75/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
ch=fgetc(fr)
Step 10: close file
fclose(fr);
Step 11: write now,noc,nol
Step 12: Stop
PROGRAM
/* Program to count number of characters, spaces, words and
lines in given file */
#include#include
void main()
{
int noc=0,now=0,nol=0;
FILE *fw,*fr;
char fname[20],ch;
clrscr();
printf("\n Enter the source file name:");
gets(fname);
fr=fopen(fname,"r");
if(fr==NULL){
printf("\n error \n");
exit(0);
8/17/2019 CManual (2)
76/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
}
ch=fgetc(fr);
while(ch!=EOF)
{
noc+;
if(ch==' ');
now++;
if(ch=='\n')
{nol++;
now++;
}
ch=fgetc(fr);
}
fclose(fr);
printf("\n total no of character=%d",noc);
printf("\n total no of words=%d",now);
printf("\n total no of lines=%d",nol);
getch();
}
8/17/2019 CManual (2)
77/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO COPY THE CONTENT OF ONE
FILE INTO ANOTHER FILE USING COMMAND LINE
ARGUMENTS
ALGORITHM
Step 1: start
Step 2: read argv[] from command prompt
Step 3: declare fs, ft as FILE pointers and ch as integer
Step 4: if(argc!=3) then
Write “Invalid no of arguments”Return 1
Step 5: Open file in read mode
fs=fopen(argv[1],”r”)
Step 6: if(fs==null) then
Write “Cant find source file”
Return 1
Step 7: Open file in write mode
ft=fopen(argv[2],”w”)
Step 8: if(ft==null) then
Write “Cant find target file”
Close source file: fclose(fs)Return 1
Step 9: Repeat step 12 until loop breaks
step 10: ch=fgetc(fs)
8/17/2019 CManual (2)
78/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
if(feof(fs)) then break
fputc(ch,ft)
Step 11: fclose(fs)
fclose(ft)
Return 0
Step 12: Stop
PROGRAM
/* Program to copy the content of one file into another file usingcommand line arguments */
#include
#include
int main(int argc,char *argv[])
{
FILE fs,*ft;
int ch;
if(argc!=3)
{
printf("Invalide numbers of arguments.");
return 1;}
fs=fopen(argv[1],"r");
if(fs==NULL)
8/17/2019 CManual (2)
79/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
{
printf("Can't find the source file.");
return 1;
}
ft=fopen(argv[2],"w");
if(ft==NULL)
{
printf("Can't open target file.");
fclose(fs);return 1;
}
while(1)
{
ch=fgetc(fs);
if (feof(fs)) break;
fputc(ch,ft);
}
fclose(fs);
fclose(ft);return 0;
}
8/17/2019 CManual (2)
80/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
POINTERS
1) WRITE A C-PROGRAM TO IMPLEMENT ARITHMETIC
OPERATIONS USING POINTERS
ALGORITHM
Step 1: start
Step 2: declare: n1, n2 as integer data type and *x,*y as integer
type pointers
Step 3: read 2 numbers: n1, n2Step 4: Set x=&n1 and y=&n2
Write *x+*y
Write *x-*y
Write *x x *y
Write *x/*y
Write *x%*y
Step 5: stop
PROGRAM
/* Program to implement arithmetic operations using pointers */
#include /* printf() , scanf() functions */#include /* clrscr(), getch() */
void main()
{
8/17/2019 CManual (2)
81/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
int n1,n2,*x,*y; /* 2 integer variables */
clrscr(); /* clears the screen */
printf("Enter 2 numbers : "); /* prints "Enter 2 numbers :
" on the screen */
printf("\n n1= ");
scanf("%d",&n1); /* reads an integer value to n1 */
printf("\n n2= ");
scanf("%d",&n2);
x=&n1;y=&n2; /* reads an integer value to n2 */
printf("\n Addition : %d + %d = %d ",*x,*y, x+y);
printf("\n Subtraction : %d - %d = %d ",*x,*y,*x-*y);
printf("\n Multiplication : %d * %d = %d ",*x,*y,*x**y);
printf("\n Division : %d / %d = %d ",*x,*y,*x/(*y));
printf("\n Modulus : %d %% %d = %d ",*x,*y,*x%*y);
getch();
}
8/17/2019 CManual (2)
82/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
2) WRITE A C-PROGRAM TO SORT NAMES IN ASCENDING
ORDER USING FUNCTIONS
ALGORITHM
Step 1: start
Step 2: read str
Step 3: set i=0
Step 4: repeat step 5 until i
8/17/2019 CManual (2)
83/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
strcpy(x[i],t)
Step 6: stop
PROGRAM
/* Program to sort names in ascending order using functions */
#include
#include
#include
void main()
{char *x[20];
int i,n=0;
void reorder(int n,char *x[]);
clrscr();
printf("Enter no. of String : ")
scanf("%f",&n);
printf("\n");
for(i=0;i
8/17/2019 CManual (2)
84/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
reorder(n,x);
printf("\nreorder list is : \n");
for(i=0;i
8/17/2019 CManual (2)
85/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
1. USER DEFINED DATA TYPES
1) WRITE A C-PROGRAM TO CREATE A NEW DATA TYPE
CALLED AS STUDENT (READ AND PRINT DETAILS OF
STUDENT)
ALGORITHM
Step 1: start
Step 2: declare Structure
Step 3: read sno, name, gen and marks using structure variable sStep 4: write sno, name, gen and marks
Step 5: stop
PROGRAM
/* Program to create a new data type called as student */
#include
#include
#include
struct Student
{
int sno;
char name[20],gen;float marks;
};
void main()
8/17/2019 CManual (2)
86/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
{
struct Student s;
clrscr();
printf("\nEnter Student number : ");
scanf("%d",&s.sno);
printf("\nEnter Student name : ");
fflush(stdin);
gets(s.name);
printf(\nEnter gender : ");scanf("%c",&s.gen);
printf("\nEnter Marks : ");
scanf("%f",&s.marks);
clrscr()
printf("\t\t\t STUDENT DETAILS \n\n");
printf("\nStudent Number : %d",s.sno);
printf("\nStudnet Name : %s",s.name);
printf("\nGender : %c",s.gen);
printf("\nMarks : %.2f",s.marks);
getch();
}
8/17/2019 CManual (2)
87/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO PRINT DAYS IN A WEEK USINF
ENUMERATION
ALGORITHM
Step 1: start
Step 2: Declare enumerated operator days
Step 3: read num
Step 4: weekday=num
Step 5: call display(weekday)
Step 6: stopVoid Display(enum days weekday)
Step 1: switch(weekday)
Step 2: case '1': Write Monday
Step 3: case '2': Write Tuesday
Step 4: case '3': Write Wednesday
Step 5: case '4': Write Thursday
Step 6: case '5': Write Friday
Step 7: case '6': Write Saturday
Step 8: case '7': Write Sunday
Step 9: default: Invalid operation"
Step 10: Repeat the Steps 3,4,5,6,7,8,9,10 untilwhile(sign != 'Q' && sign != 'q')
Step 11: Sto
PROGRAM
8/17/2019 CManual (2)
88/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
/* Program to print days in a week usinf enumeration */
#include
#include
enum days {
Monday=1, Tuesday, Wednesday,
Thursday, Friday, Saturday, Sunday
} weekday;
void Display(enum days);
void main(void){
int num;
printf("Enter an integer for the day of the week. "
"Mon=1,...,Sun=7\n");
scanf("%d", &num);
weekday=num;
Display(weekday)
getch();
}
void Display(enum days weekday)
{switch (weekday)
{
case Monday:
8/17/2019 CManual (2)
89/96
8/17/2019 CManual (2)
90/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
2. STRUCTURES
1) WRITE A C-PROGRAM TO READ NAME OF THE
STUDENT, ROLLNUMBER AND MARKS OBTAINED IN
SUBJECTS FROM KEYBOARD AND PRINT NAME OF
STUDENT, ROLLNUMBER, MARKS IN 3 SUBJECTS AND
TOTAL MARKS BY USING STRUCTURES CONCEPT
ALGORITHM
Step 1: startStep 2: declare Structure
Step 3: read sno, name, marks using structure variable s
Step 4: calculate total =s.m1+s.m2+s.m3
Step 5: write sno, name, marks and total
Step 6: stop
PROGRAM
/* Program to read name of the student, rollnumber and marks
obtained in subjects from keyboard and print name of student,
rollnumber, marks in 3 subjects and total marks by using
structures concept */
#include#include
#include
struct Student
8/17/2019 CManual (2)
91/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
{
int sno;
char name[20];
float m1,m2,m3;
};
void main()
{
struct Student s;
clrscr();printf("\nEnter Student number : ");
scanf("%d",&s.sno);
printf("\nEnter Student name : ");
fflush(stdin);
gets(s.name);
printf("\nEnter Marks in Subject 1: ");
scanf("%f",&s.m1);
printf("\nEnter Marks in Subject 2: ");
scanf("%f",&s.m2);
printf("\nEnter Marks in Subject 3: ");
scanf("%f",&s.m3);clrscr();
printf("\t\t\t STUDENT DETAILS \n\n");
printf("\nStudent Number : %d",s.sno);
8/17/2019 CManual (2)
92/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
printf("\nStudnet Name : %s",s.name);
printf("\nMarks in Subject1 : %.2f",s.m1);
printf("\nMarks in Subject2 : %.2f",s.m2);
printf("\nMarks in Subject3 : %.2f",s.m3);
printf("\nTotal Marks : %.2f",s.m1+s.m2+s.m3);
getch();
}
8/17/2019 CManual (2)
93/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
WRITE A C-PROGRAM TO READ NAME OF THE
STUDENT, ROLLNUMBER AND MARKS OBTAINED IN
SUBJECTS FROM KEYBOARD AND PRINT NAME OF
STUDENT, ROLLNUMBER, MARKS IN 3 SUBJECTS AND
TOTAL MARKS BY USING ARRAYS OF STRUCTURES
CONCEPT
ALGORITHM
Step 1: start
Step 2: declare StructureStep 3: read n
Step 4: set i=0
Step 5: repeat step 6 until i
8/17/2019 CManual (2)
94/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
PROGRAM
/* Program to read name of the student, rollnumber and marks
obtained in subjects from keyboard and print name of student,
rollnumber, marks in 3 subjects and total marks by using arrays
of structures concept */
#include
#include
#include
struct Student{
int sno;
char name[20];
float m1,m2,m3;
};
void main()
{
struct Student s[10];
int n,i;
clrscr();
printf("Enter Number of Students:");scanf("%d",&n);
for(i=0;i
8/17/2019 CManual (2)
95/96
Mrs. B. Lakshmi, Asst.Professor, Dept. of Computer Applications, VRSEC
printf("Enter Details of Student %d",i+1);
printf("\nEnter Student number : ");
scanf("%d",&s[i].sno);
printf("\nEnter Student name : ");
fflush(stdin);
gets(s[i].name);
printf("\nEnter Marks in Subject 1: ");
scanf("%f",&s[i].m1);
printf("\nEnter Marks in Subject 2: ");scanf("%f",&s[i].m2);
printf("\nEnter Marks in Subject 3: ");
scanf("%f",&s[i].m3);
}
clrscr();
for(i=0;i
8/17/2019 CManual (2)
96/96
printf("\nTotal Marks :
%.2f",s[i].m1+s[i].m2+s[i].m3);
}
getch();
}