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

Bca Solved Assignment BCSL 021 C Language Programming Lab

This document contains an assignment for an IGNOU BCA/MCA C Language Programming course. It includes 8 questions to write C programs related to generating Pascal's triangle, calculating the surface area and volume of a sphere, determining if a matrix is symmetric, managing student records, deleting characters from a string, defining and manipulating a hotel structure, copying files, and reversing the first n characters of a file. The assignment is worth 50 marks and is due on October 15, 2016 for the July 2016 session or April 15, 2017 for the January 2017 session.

Uploaded by

hojik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
309 views

Bca Solved Assignment BCSL 021 C Language Programming Lab

This document contains an assignment for an IGNOU BCA/MCA C Language Programming course. It includes 8 questions to write C programs related to generating Pascal's triangle, calculating the surface area and volume of a sphere, determining if a matrix is symmetric, managing student records, deleting characters from a string, defining and manipulating a hotel structure, copying files, and reversing the first n characters of a file. The assignment is worth 50 marks and is due on October 15, 2016 for the July 2016 session or April 15, 2017 for the January 2017 session.

Uploaded by

hojik
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

BCA & MCA (IGNOU)

http://www.ignouassignmentguru.com
Course Code : BCSL-021
Course Title : C Language Programming
Assignment Number : BCA(2)/L-021/Assignment/16-17
Maximum Marks : 50 Weightage : 25%
Last Dates for Submission : 15thOctober, 2016 (For July 2016 Session)
15th April, 2017 (For January 2017 Session)
Course Code: BCSL-021

1. Write a C program to generate Pascal's triangle. (5 Marks)

Ans:
#include<stdio.h>

long factorial(int);

int main()
{
int i, n, c;

printf("How many rows you want to show in pascal triangle?\n");

scanf("%d",&n);

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


{
for ( c = 0 ; c <= ( n - i - 2 ) ; c++ )
printf(" ");
for( c = 0 ; c <= i ; c++ )
printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));
printf("\n");
}
return 0;
}

long factorial(int n)

1
{
int c; IGNOU ASSIGNMENT GURU Page-
long result = 1;

for( c = 1 ; c <= n ; c++ )


result = result*c;
return ( result );
}
2. Write a C Program to find the surface area and the volume of a sphere. (Surface
Area = 4 π r2 and Volume = 4/ 3 π r3 ) (5 Marks)
Ans:
#include <stdio.h>
#include <math.h>

int main()
{

/IGNOUASSIGNMENTGURU
BCA & MCA (IGNOU)
http://www.ignouassignmentguru.com

float radius;
float surface_area, volume;

printf("Enter radius of the sphere : \n");


scanf("%f", &radius);
surface_area = 4 * (22/7) * radius * radius;
volume = (4.0/3) * (22/7) * radius * radius * radius;
printf("Surface area of sphere is: %.3f", surface_area);
printf("\n Volume of sphere is : %.3f", volume);
return 0;
}

3. Write a C program to find whether the given matrix is symmetric or not. (5


Marks)
Ans:
#include<conio.h>
#include<stdio.h>
void main()
{
int a[10][10],i,j,m;
clrscr();
printf("Enter order of square matrix: ");
scanf("%d",&m);
for(i=1;i<=m;i++)
{
for(j=1;j<=m;j++)
{
printf("Enter value of a[%d][%d]: ",i,j);
scanf("%d",&a[i][j]);
}
}
for(i=1;i<=m;i++)
{
for(j=1;j<=m;j++)
{
if(a[i][j]!=a[j][i]) 2
IGNOU ASSIGNMENT GURU Page-
{
printf("\n\nMatrix is not symmetric");
getch();
exit(0);
}
}
}
printf("\n\nMatrix is symmetric");
getch();
}

4. Write a interactive C program to create records of 15 students, where each record


has fields name, rollno, GPA and fees. Write a function calcfee ( ) to reduce the fees of

/IGNOUASSIGNMENTGURU
BCA & MCA (IGNOU)
http://www.ignouassignmentguru.com
those students who have obtained GPA greater than 9.0 by 25% of the original fees, 10%
fee concession if GPA is between 8.0 and 8.9 and 5% concession if the GPA is between 7.5
and 7.9. Display all the records before and after updation. (5 Marks)
Ans:
#include<stdio.h>
#define SIZE 50

struct student
{
char name[30];
int rollno;
int gpa,fee;
};

void calcfee(struct student st[])


{
for (i = 0; i < n; i++)
{
if(st[i].gpa>=9.0)
st[i].fee=st[i].fee-(st[i].fee*0.25);
else if(s[i]t.gpa<=8.9 && st[i].gpa<8.0)
{
St[i].fee=st[i].fee-(st[i].fee*0.05);
printf("Total Fee=%d",st[i].fee);
printf("roll no=%d", &st[i].rollno);
}
}
}
void main()
{
int i, j, max, count, total, n, a[SIZE], ni;
struct student st;
clrscr();
printf("Enter how many students: ");
scanf("%d", &n);

3
IGNOU ASSIGNMENT GURU Page-
for (i = 0; i < n; i++)
{
printf("\nEnter details name, rollno,gpa,fee");
scanf("%s", &st[i].name);
scanf("%d", &st[i].rollno);
scanf("%d", &st[i].gpa);
scanf("%d", &st[i].fee);
}
Printf(“\nPrint Before update\n”)
for (i = 0; i < n; i++)
{

printf("roll no=%d", &st[i].rollno);


printf (“GPA=%d", &st[i].gpa);

/IGNOUASSIGNMENTGURU
BCA & MCA (IGNOU)
http://www.ignouassignmentguru.com
printf("GPA=%d", &st[i].gpa);
printf("fee=%d", &st[i].fee);
calcfee(st[i]);

Printf(update data:\n”)

getch();
}

5. Using pointers, write a function that receives a string and a character as argument.
Delete all occurrences of this character in the string. The function should return corrected
string with no holes/spaces. (5 Marks)

Ans:
#include<stdio.h>
#include<conio.h>
#include<string.h>

void del(char str[], char ch);

void main() {
char str[10];
char ch;

printf("\nEnter the string : ");


gets(str);

printf("\nEnter character which you want to delete : ");


scanf("%ch", &ch);

del(str, ch);
getch();
} 4
IGNOU ASSIGNMENT GURU Page-

void del(char str[], char ch) {


int i, j = 0;
int size;
char ch1;
char str1[10];

size = strlen(str);

for (i = 0; i < size; i++) {


if (str[i] != ch) {
ch1 = str[i];
str1[j] = ch1;
j++;

/IGNOUASSIGNMENTGURU
BCA & MCA (IGNOU)
http://www.ignouassignmentguru.com
}
}
str1[j] = '\0';

printf("\ncorrected string is : %s", str1);


}
6. Define a structure that describes a hotel. It should have members that include the
name, address, star(5 star, 3 star or 2 star), average room charge and number of rooms.
Write a function to perform the following operations:
(i) To print out hotels of a given grade in order of charges.
(ii) To print out hotels with room charges less than a given value.
(5 Marks)
Ans:
#include <stdio.h>
struct hotel
{
char name[20];
char add[20];
int grade;
int arc;
int rooms;
};
void output();
void out();
struct hotel inn[]={
{"PLAZA","G-99,DELHI",3,4500,50},
{"MYUR","E-45,NOIDA",4,5000,100},
{"RAJDOOT","H-44,DELHI",2,4000,50},
{"SAMRATH","B-75,BOMBAY",5,6000,200},
{"SURYA","A-77,NOIDA",1,3500,150}
};
void main()
{
int go;
clrscr();
printf("Enter 1 for grade search\n");
printf("Enter 2 to search by charge:"); 5
IGNOU ASSIGNMENT GURU Page-
scanf("%d",&go);
switch(go)
{
case 1: output();
break;
case 2: out();
break;
default:printf("Wrong input");
break;
}
getch();
}
void output()
{

/IGNOUASSIGNMENTGURU
BCA & MCA (IGNOU)
http://www.ignouassignmentguru.com
int gr,i;
printf("Enter Grade 1 to 5:");
scanf("%d",&gr);
if(gr>=1||gr<=5)
{
for(i=0;i<=4;i++)
{
if(inn[i].grade==gr)
printf("Hotel Name: %s\nAddress:%s\nGrade:%d\nAverage Room charge:%d\n\
Number of Rooms:%d",inn[i].name,inn[i].add,inn[i].grade,inn[i].arc,inn[i].rooms);
}
}
else
printf("Wrong grade input!");
}
void out()
{
int ch,i=0;
printf("Enter the Room charges not greater than 6000:");
scanf("%d",&ch);
while(i<5)
{
if(inn[i].arc<ch)
printf("Hotel Name: %s\nAddress:%s\nGrade:%d\nAverage Room charge:%d\n\
Number of Rooms:%d\n",inn[i].name,inn[i].add,inn[i].grade,inn[i].arc,inn[i].rooms);
i++;
}}

7. Write an interactive C program which copies one file to another. (5 Marks)


Ans:
#include<stdio.h>
void main()
{
char x;
FILE *p,*y;
clrscr();
p=fopen("abc.txt","r"); 6
IGNOU ASSIGNMENT GURU Page-
y=fopen("xyz.txt","w");

do
{
x=fgetc(p);
putchar(x);
fputc(x,y);
}while(x!=eof());
getch();
}
8. Write an interactive C program to reverse the first n characters in a file.:
Ans:

#include <stdio.h>

/IGNOUASSIGNMENTGURU
BCA & MCA (IGNOU)
http://www.ignouassignmentguru.com
#include <conio.h>
#include <string.h>
#include <process.h>

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


{
char a[15];
char s[20];
char n;
int k;
int j=0;
int i;
int len;
FILE *fp;

if(argc!=3)
{
puts("Improper number of arguments.");
exit(0);
}
fp = fopen(argv[1],"r");
if(fp == NULL)
{
puts("File cannot be opened.");
exit(0);
}

k=*argv[2]-48;
n = fread(a,1,k,fp);
a[n]='\0';
len=strlen(a);
for(i=len-1;i>=0;i--)
{
s[j]=a[i];
printf("%c",s[j]);
j=j+1;
} 7
IGNOU ASSIGNMENT GURU Page-
s[j+1]='\0';
getch();
}/

/IGNOUASSIGNMENTGURU

You might also like