Sie sind auf Seite 1von 35

UNIVERSITY OF CALCUTTA

BBA part III(Hons)Examination-2019


Programming through C language
and Html

ROLL NO : 223-BBA17M-0002
REGISTRATION NO : 223-1121-0092-16
SUBJECT : Computer Application
PAPER CODE : XVIII-B

1
INDEX
SL NO DATE ASSIGNMENTS PAGE SIGNATURE
NO
1 29/08/2018 Assignment 1 3
2 29/08/2018 Assignment 2 4
3 12/09/2018 Assignment 3 5
4 12/09/2018 Assignment 4 7
5 19/09/2018 Assignment 5 9
6 19/09/2018 Assignment 6 11
7 26/09/2018 Assignment 7 12
8 26/09/2018 Assignment 8 14
9 14/11/2018 Assignment 9 15
10 14/11/2018 Assignment 10 17
11 05/12/2018 Assignment 11 18
12 05/12/2018 Assignment 12 20
13 19/12/2018 Assignment 13 21
14 19/12/2018 Assignment 14 23
15 19/02/2019 Assignment 15 25
16 20/03/2019 Assignment 16 28
17 10/04/2019 HTML 31

2
ASSIGNMENT 1 DATE: 29/08/2018
Input a number and check, whether it is a positive, negative or zero.
Algorithm:
STEP 1: INPUT A NUMBER
STEP 2: INITIALIZE VARIABLE N AS INTEGER
STEP 3: ENTER A NUMBER AND STORE IN VARIABLE N
STEP 4: CHECK WHETHER N IS GREATER THAN ZERO
STEP 5: IF N IS GREATER THAN ZERO PRINT ENTERED NUMBER IS POSITIVE
STEP 6: IF N IS LESS THAN ZERO THEN PRINT NUMBER IS NEGATIVE

Source Code:
#include <stdio.h>
int main()
{
int n;
printf("Enter a number: \n");
scanf("%d",&n);
if(n>0)
{
printf("The entered number is a positive");
}
else if(n==0)
{
printf("The entered number is zero");
}
else
{
printf("The entered number is a negetive");
}
return 0;
}

Input: 98
Output: Enter a number:
98
The entered number is positive

Input: -6
Output: Enter a number:
-6
The entered number is negative

3
ASSIGNMENT 2 DATE: 29/08/2018
Input an integer n and print all natural numbers till n.
Algorithm:
STEP 1:INITIALIZE THE VARIALBLE n AND sum as INTEGER
STEP 2:INITIALIZE the variable I with value 1 as INTEGER
STEP 3:Input a number and store in n
STEP 4: CHECK IF N IS LESS THAN ZERO
STEP 5: IF N IS LESS THAN zero then entered number is invalid
Step 6: IF the value of i is within the value of n then print sum

Source code:
#include <stdio.h>
int main()
{
int n,sum,i=1;
printf("Input a number: \n");
scanf("%d",&n);
if(n<=0)
{
printf("The entered number is invalid");
}
else
{
while(i<=n)
{
sum=i++;
printf("%d \n",sum);
}
}
return 0;
}

Input: 3 Input: 4
Output: Input a number: Output: Input a number:
3 4
1 1
2 2
3 3
4

4
ASSIGNMENT 3 DATE: 12/09/2018
Input 3 numbers and find out the largest one. (Without using logical
operator).

Algorithm:
STEP 1: Initialize three variables A,B,C as integer.
STEP 2: Enter three number s and store in a,b,c
STEP 3: Check if a is greater than b and a is greater than c
STEP 4: If value of A is greater than value of B and C then print the value
under variable A is the largest number
STEP 5: If not then C is the largest number
STEP 6: If value of B is greater than value C then print the value under variable
B is the largest number, if not then print the value under C is the largest number

Source code
#include <stdio.h>
int main()
{
int A, B, C;
printf("Enter three numbers: ");
scanf("%d %d %d", &A, &B, &C);

if (A >= B) {
if (A >= C)
printf("%d is the largest number.", A);
else
printf("%d is the largest number.", C);
}
else {
if (B >= C)
printf("%d is the largest number.", B);
5
else
printf("%d is the largest number.", C);
}
return 0;
}

Input: 4 5 6
Output: Enter 3 numbers:
4
5
6
6 is the largest number

Input: 123
Output: Enter 3 numbers:
1
2
3
3 is the largest number

6
ASSIGNMENT 4 DATE: 12/09/2018
Input a character and check whether it is a vowel or constraint. (Using
switch case)

Algorithm
STEP 1: initialize variable ch as character
Step 2: Input a character and store in variable ch
STEP 3: CHECK IF the character entered is between A to Z
STEP 4: IF the character Is either a,e,I,o,u then print vowel
STEP 5: IF character is anything apart from a,e,I,o,u then print consonant
STEP 6:If none of the above hold then print it is not a character

Source code

#include <stdio.h>
int main()
{
char ch;
printf("Enter a character: ");
scanf("%c",&ch);
if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z'))
{
switch(ch)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'a':
case 'e':
case 'i':
case 'o':
7
case 'u':
printf("%c is a VOWEL.\n",ch);
break;
default:
printf("%c is a CONSONANT.\n",ch);
}
}
else
{
printf("%c is not an alphabet.\n",ch);
}
return 0;
}

Input: a
Output: Enter a character
a
a is a vowel.

Input: Z
Output: Enter a character
Z
Z is a constraint.

8
ASSIGNMENT 5 DATE: 19/09/2018
Input an integer and check whether it’s prime or composite.
Algorithm

STEP 1: initialize variable n,p and i as integer


STEP 2: ENTER A NUMBER and store in N
Step 3: CHECK IF N mod I is equal to zero if yes then increment p by 1
STEP 4: IF value of p is equal to 2 print n is prime number
Step 5: IF value of p is equal to 1 print n is not a prime number
Step 6: IF value of n is not equal to either of the above print n is composite

Source Code:

#include <stdio.h>
int main()
{
int n,p,i;
printf("Enter a number: \n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
{
p++;
}
}
if(p==2)
{
printf("The entered number is a prime number");
}
else if(n==1)
{

9
printf("The entered number is not a prime number");
}
else
{
printf("The entered number is a composite number");
}
return 0;
}

Input: 13
Output: Enter a number:
13
The entered number is a prime number

Input: 22
Output: Enter a number:
22
The entered number is not a prime number

10
ASSIGNMENT 6 DATE: 19/09/2018
Input an integer and calculate it’s factorial.
Algorithm
STEP 1:initialize n,i as integer
STEP 2: initialize fact with value 1 as INTEGER
STEP 3 : ENTER A NUMBER and store in n
STEP 4: IF value of n is zero print factorial of zero is zero
STEP 5: otherwise print factorial of n
Source code
#include <stdio.h>
int main()
{
int fact=1,n,i;
printf("Enter a number: \n");
scanf("%d",&n);
if(n==0)
{
printf("0 is the factorial of 0");
}
else
{
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("%d is the factorial of %d",fact,n);
}
return 0;
}

Input: 3
Output: Enter a number:
3
6 is the factorial of 3

Input: 4
Output: Enter a number:
4
24 is the factorial of 4

11
ASSIGNMENT 7 DATE: 26/08/2018
Input a number and check if it’s an Armstrong number or not.
Algorithm
STEP 1: initialize cnt,sum,rem,cube with value zero as integer
STEP 2: initialize number,n and temp as integer
STEP 3: ENTER A NUMBER and store in number
Step 4: transfer the value of number in temp and then to n
STEP 5: remainder is equal to number mod 10
STEP 6: number is equal to number by 10
STEP 7: Count is equal to count plus 1
STEP 9: REM=number mod 10
STEP 10: Sum = sum+cube
STEP 11: number = number/10
STEP 12: Repeat step 9 to 11 until number >0
STEP 13: If sum=temp print number is Armstrong
STEP 14: Else print number is not Armstrong

Source code
#include <stdio.h>
#include <math.h>
int main()
{
int number,n,cnt=0,r, sum = 0, rem = 0, cube = 0, temp;
-
printf ("enter a number: \n");
scanf("%d", &number);
temp = number;
n=number;

while (n!=0)
{
r=n%10;
n=n/10;
cnt=cnt+1;
}

12
while (number != 0)
{
rem = number % 10;
cube = pow(rem, cnt);
sum = sum + cube;
number = number / 10;
}
if (sum == temp)
printf ("The given number is an armstrong number");
else
printf ("The given number is not an armstrong number");
return 0;
}

Input: 153
Output: enter a number:
153
The given number is an armstrong number.

Input: 122
Output: enter a number:
122
The given number is not an armstrong number.

13
ASSIGNMENT 8 DATE: 26/09/2018
Input a string and find out it’s reverse to check if it’s a palindrome or not.
Algorithm

STEP 1: Define two arrays a,b as character.


STEP 2: Enter a string and store in a.
STEP 3: Copy value of a in b.
STEP 4:Reverse value of b.
STEP 5:Check if value of reversed b is equal to a
STEP 6: If it is same the print it is a palindrome
STEP 7: Otherwise print not a palindrome

Source code
#include <stdio.h>
#include <string.h>
int main()
{
char a[50],b[50];
printf("Enter a string: \n ");
gets(a);
strcpy(b,a);
strrev(b);
if(strcmp(a,b)==0)
printf(" Pallindrome ");
else
printf(" Not pallindrome ");
return 0;
}

Input: abba
Output: Enter a string: abba
Pallindrome

Input: abcd
Output: Enter a string: abcd
Not pallindrome

14
ASSIGNMENT 9 DATE: 14/11/2018
Input an integer and find out it’s reverse to check if it’s a palindrome or
not.

Algorithm
STEP 1: Initialise rev with zero as integer
STEP 2: Enter a number and store in variable n
STEP 3:Transpose n with t
STEP 4: Remainder = n mod 10
STEP 5: Reverse=rev*10+rem
STEP 6:n= n/10
STEP 7:Repeat steps 4 to 6 till n>0
STEP 8: Check whether value of t = rev
STEP 9: If yes then print palindrome
STEP 10: If no the print not a palindrome
Source Code:
#include <stdio.h>
int main()
{
int n,t,rev=0,rem;
printf("Enter a number: \n");
scanf("%d",&n);
t=n;
while(n>0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
printf("The reversed number of %d is %d \n",t,rev);
if(t==rev)
{
printf("The entered number is a palindrome number");
}
else
{
printf("The entered number is not a palindrome number");
}
return 0;
}
15
Input:121
Output: Enter a number:
121
The reversed number of 121 is 121
The entered number is a palindrome number

Input:122
Output: Enter a number:
122
The reversed number of 122 is 221
The entered number is not a palindrome number

16
ASSIGNMENT 10 DATE:14/11/2018
Find out the sum of the given series:
 ½+1/4+1/6+…………+1/n (Input the value of n).

Algorithm
STEP 1:Initialize variables i,N as integer
STEP 2: Initialize variable sum as float
STEP 3:Enter value of N and store in variable N
STEP 4: Calculate sum= sum*((float)1/(float)i)
STEP 5:Print sum of the series

Source code
#include<stdio.h>

int main()
{
int i,N;
float sum;
printf("Enter the value of N: ");
scanf("%d",&N);
sum=0.0f;
for(i=2;i<=N;i=i+2)

sum = sum + ((float)1/(float)i);


printf("Sum of the series is: %f\n",sum);
return 0;
}
Input: 4 Input: 20
Output: Output:
Enter the value of N: 4 Enter the value of N: 20
Sum of the series is: 0.750000 Sum of the series is: 1.464484

17
ASSIGNMENT 11 DATE:05/12/2018
Display the following pattern, the number of rows will be n.
*
**
***
****
*****

Algorithm
STEP1:Initialize row,c,s,n as integer
STEP 2: Enter number of rows of stars and store in variable n
STEP 3: Transpose n to s
STEP 4: Print blank
STEP 5: Print *

Source code
#include <stdio.h>

int main()
{
int row, c, n, s;

printf("Enter the number of rows in pyramid of stars you wish to see: \n");
scanf("%d", &n);

s = n;

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


{
for (c = 1; c < s; c++)
printf(" ");

s--;

for (c = 1; c <= 2*row - 1; c++)


printf("*");

printf("\n");
}
18
return 0;
}

Input: 3
Output:
Enter the number of rows in pyramid of stars you wish to see:

***

*****

Input: 5
Output:
Enter the number of rows in pyramid of stars you wish to see:

***

*****

*******

*********

19
ASSIGNMENT 12 DATE: 05/12/2018
Write a program to generate Fibonacci series up to n terms.
Source code
#include <stdio.h>
//0 1 1 2 3 5 8 13 21 ...
void main()
{
int n, i, first, second, next;
printf("Enter the number of terms in the fibonacci series : \n");
scanf("%d", &n);
first=0;
second=1;
for(i=0;i<n;i++)
{
if (i<=1)
next=i;
else
{
next=first + second;
first=second;
second=next;
}
printf("%d ", next);
}
}

Input: 4
Output:
Enter the number of terms in the fibonacci series:

0 1 1 2

20
ASSIGNMENT 13 DATE: 19/12/2018
Input an array of integers and find out the maximum and minimum
values among them.

Source code
#include <stdio.h>

int main()
{
int array[100], maximum,min, size, c;

printf("Enter the number of elements in array\n");


scanf("%d", &size);

printf("Enter %d integers\n", size);

for (c = 0; c < size; c++)


scanf("%d", &array[c]);

maximum = array[0];

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


{
if (array[c] > maximum)
{
maximum = array[c];

}
}
min = array[0];

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


{
if (array[c] < min)
{
min = array[c];

}
}

printf("Maximum element is %d.\n", maximum);


printf("Minimum element is %d.\n", min);
21
return 0;
}

Input: 3
12
23
55

Output:
Enter the number of elements in array

Enter 3 integers

12

23

55

Maximum element is 55.

Minimum element is 12.

22
ASSIGNMENT 14 DATE: 19/12/2018
Input an array of n number of integers and sort them in ascending order.
Source code
#include <stdio.h>

void main()
{
int a[10],n,i,j, temp;
printf ("Enter the number of integers to be sorted : \n");
scanf("%d", &n);
printf("Enter the elements : \n");
for(i=0;i<n;i++)
scanf("%d", &a[i]);
for (i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if (a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
}

printf("Sorted array is : \n");


for(i=0;i<n;i++)
printf("%d \n", a[i]);

Input:4
67
5
6
7

Output:
Enter the number of integers to be sorted:

4
23
Enter the elements:

67

Sorted array is:

6
7
67

24
ASSIGNMENT 15 DATE: 19/02/2019
Write 2 matrices and computer their sum.
Source code
#include <stdio.h>

void main()
{
int a[10][10], b[10][10], c[10][10];
int r1,c1,r2,c2,i,j;
printf("Enter the number of rows of first matrix : ");
scanf("%d",&r1);
printf("Enter the number of columns of first matrix : ");
scanf("%d",&c1);
printf("Enter the number of rows of second matrix : ");
scanf("%d",&r2);
printf("Enter the number of columns of second matrix : ");
scanf("%d",&c2);
if (r1==r2 && c1==c2)
{
printf("Enter the elements of the first matix : \n");
for (i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the elements of the second matix : \n");
for (i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("First Matrix : \n");
for (i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%d ", a[i][j]);
}
25
printf("\n");
}

printf("Second Matrix : \n");


for (i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%d ", b[i][j]);
}
printf("\n");
}

for (i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}

printf("Sum of the two matrices : \n");


for (i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%d ", c[i][j]);
}
printf("\n");
}
}
else
printf("The input matrices cannot to added!");
}

Output:
Enter the number of rows of first matrix : 2

Enter the number of columns of first matrix : 2

Enter the number of rows of second matrix : 2

26
Enter the number of columns of second matrix : 2

Enter the elements of the first matix :

5
6

Enter the elements of the second matix :

4
First Matrix :

3 4

5 6

Second Matrix :

7 6

5 4
7 6

5 4

Sum of the two matrices :

10 10

10 10

27
ASSIGNMENT 16 DATE: 20/03/2019
Write a menu driven program to perform the basic arithmetic calculations.
Source code
#include <stdio.h>

void main()
{
int a,b,sum, diff, prod, ch;
float quot=0.0;
printf("Enter 2 integers : \n");
scanf("%d %d", &a, &b);

printf("1. Addition \n");


printf("2. Subtraction \n");
printf("3. Multiplication \n");
printf("4. Division \n");

printf("Enter your choice (1-4) : ");


scanf("%d", &ch);
switch(ch)
{
case 1:
sum=a+b;
printf("Sum of %d and %d = %d \n", a, b, sum);
break;

case 2:
if (a>b)
diff=a-b;
else
diff=b-a;

printf("Difference between %d and %d = %d \n", a, b, diff);


break;

case 3:
prod=a*b;
printf("Product of %d and %d = %d \n", a, b, prod);
break;

case 4:
if (a>b)
28
quot=a/b;
else
quot=b/a;
printf("Quotient of %d and %d = %f \n", a, b, quot);
break;

default:

printf("Wrong choice!!");

}
}

Input: 3, 4
Output:
Enter 2 integers:

1. Addition

2. Subtraction

3. Multiplication

4. Division

Enter your choice (1-4) : 1


Sum of 3 and 4 = 7

Input: 9, 8
Output:
Enter 2 integers:

1. Addition

29
2. Subtraction

3. Multiplication

4. Division

Enter your choice (1-4) : 2


Difference between 9 and 8 = 1

30
ASSIGNMENT 17 DATE: 10/04/2019

HTML
1. Design a website using HTML about your college. You should include
the following:
a) Marque and a background colour.
b) Font in bold, italics and underlined as well as showing different types of
fonts and different font colours and sizes.
c) Image to be turned into link.
d) At least two hyperlinks in your page.
e) Use table to display information.

Source code
<html>
<head><title>Scottish Church College</title></head>
<body bgcolor="lime"><marquee><font size="14" face="lucida
calligraphy"><i>Admissions going on!!!!!</i></font></marquee>
<font size="28" face="verdana"><center><b><u> Welcome to Scottish Church
College </u></b></center></font>
<br>
<center><a href="http://www.scottishchurch.ac.in"><img
src="1.jpg"></a></center>
<br>
<center><b><a
href="https://en.wikipedia.org/wiki/Scottish_Church_College">Click here to
know more</b></a></center>
<center><a href="https://www.google.com">Click here to Google about
us</a></center>
<br>
<br>
<table border="4">
<tr>
<td><h4><b><font color="blue">Courses offered</font></b></h4></td>
<td><h4><b><font color="blue">Course fees</font></b></h4></td>
</tr>
<tr>
<td>BBA</td>
<td>Rs. 500000</td>
</tr>
<tr>
<td>B.com</td>
<td>Rs. 300000</td>
</tr>
31
<tr>
<td>Computer Science</td>
<td>Rs. 200000</td>
</tr>
<tr>
<td>Micro Biology</td>
<td>Rs. 100000</td>
</tr>
</table>
<br>
<br>
</body>
</html>

32
2. Design a webpage about IPL 2019 using HTML. Make suitable
assumptions.
Source code
<html>
<head><title>Welcome to the official website of IPL 2019</title></head>
<body bgcolor="aqua">
<marquee><font size="12" face="lucida calligraphy">IPL 2019 from 7th April
2019 to 23rd May 2019</font></marquee>
<br>
<br>
<center><h1><u>Welcome to the official page of IPL 2019</u></h1></center>
<br>
<center><a href="https://www.iplt20.com/"><img src="ipl-2019.jpg"
border="3"></a></center>
<br>
<br>
<Center><a href="https://www.ipltickets.net/">Book your tickets
here</a></center>
<br>
<table border="3">
<tr>
<th>Team names</th>
<th>Points</th>
</tr>
<tr>
<td><font color="red">Kolkata Knight Riders</font></td>
<td>20</td>
</tr>
<tr>
<td><font color="blue">Mumbai Indians</font></td>
<td>19</td>
33
</tr>
<tr>
<td><font color="red">Kings 11 punjab</font></td>
<td>17</td>
</tr>
<tr>
<td><font color="Yellow">Sunrisers Hydrabad</font></td>
<td>15</td>
</tr>
<tr>
<td><font color="brown">Delhi Capitals</font></td>
<td>13</td>
</tr>
<tr>
<td><font color="Pink">Rajasthan Royals</font></td>
<td>12</td>
</tr>
<tr>
<td><font color="Orange">Royal Challengers Bangalore</font></td>
<td>9</td>
</tr>
</table>
</body>
</html>

34
35

Das könnte Ihnen auch gefallen