100% found this document useful (1 vote)
1K views

Computer Science PBA Notes SSC-II

Notes PBA

Uploaded by

esha yasir
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views

Computer Science PBA Notes SSC-II

Notes PBA

Uploaded by

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

COMPUTER SCIENCE

PBA
Askaria School & Colleges
1. Installation of C compiler:
1. Go to the official website or a trusted download site.
2. Download the latest version of Dev-C++.
3. Once downloaded, locate the installer in your Downloads folder.
4. Double-click the file to start the installation.
5. Upon launching the installer, you will be prompted to choose your preferred
language. Select your language and click OK.
6. Read the License Agreement, and if you agree with the terms, click I Agree.
7. Choose the folder where you want to install Dev-C++.
8. You will be presented with options for the components you want to install.
By default, it will include: Dev-C++ IDE, GCC Compiler and Shortcut
icons Leave the default options checked and click Install.
9. The installer will now copy all necessary files and set up Dev-C++.
10.Once the installation is complete, click Finish.

2. Familiarization with IDE of C compiler:


Menu Bar

Tool Bar

Editor
Window

Compiler
Window
2.1 How To create new project?
1. Go to File option in menu bar
2. Choose New > source file
3. It will create a file you can save that file by choosing Save as option from
file menu or by pressing CTRL + S.
4. Specify a name for you file and choose type as C source file
5. Click on save button to save you file.
2.2 How To Compile and Run your file?
1. After writing code just click on the Execute option given in menu bar.
2. Choose Compile and Run option or press F11
3. Compiler will check your code if there is any error it will show that in
compiler window. Otherwise, it will show an output console to you.
3. Printf, Scanf and getch statements: Program to find sum of
two numbers
#include<stdio.h>
#include<conio.h>
void main(void)
{
int num1,num2,sum;
printf(“Enter first number:”);
scanf(“%d”, &num1);
printf(“\n Enter second number:”); Enter first number:10
scanf(“%d”,&num2); Enter second number:5
sum=num1+num2; Sum of two numbers is=15
printf(“Sum of two numbers is=%d”,sum);
getch();
}

Assignment(=) operator: Program to find subtraction of two


numbers
#include<stdio.h> Enter first number:10
#include<conio.h> Enter second number:5
void main(void) Subtraction of two numbers is=5
{
int num1,num2,sub;
printf(“Enter first number:”);
scanf(“%d”, &num1);
printf(“\n Enter second number:”);
scanf(“%d”,&num2);
sub=num1-num2;
printf(“Subtraction of two numbers is=%d”,sub);
getch();
}

Program to find multiplication and division of two numbers


#include<stdio.h>
#include<conio.h>
void main(void)
{
int num1,num2,mul,div;
printf(“Enter first number:”);
scanf(“%d”, &num1);
printf(“\n Enter second number:”); Enter first number:10
scanf(“%d”,&num2); Enter second number:5
mul=num1*num2; Multiplication=50
div=num1/num2; Division=2
printf(“Multiplication=%d”,mul);
printf(“Division=%d”,div);
getch();
}

Program to calculate the area and circumference of circles


#include<stdio.h>
#include<conio.h>
void main(void) Enter radius of circle:5
{ Area of circle=78.5
const float pi=3.14; Circumference of circle=31.4
float radius,area,circum;
printf(“Enter radius of circle:”);
scanf(“%f”, &radius);
area=pi*radius*radius;
circum=2*pi*radius;
div=num1/num2;
printf(“\nArea of circle=%f”,area);
printf(“\nCircumference of circle=%f”,circum);
getch();
}

Program to calculate the area of right angle triangle


#include<stdio.h>
#include<conio.h>
void main(void)
{
int base,height;
float area;
printf(“Enter base:”);
scanf(“%d”, &base);
printf(“\n Enter height:”); Enter base:20
scanf(“%d”, &height); Enter height=40
area=0.5*base*height; Area of triangle=400
printf(“\nArea of triangle=%d”,area);
getch();
}

Program to calculate the area of rectangle


#include<stdio.h>
#include<conio.h>
void main(void)
{
int length,width,area;
printf(“Enter length:”);
scanf(“%d”, &length);
printf(“\n Enter width:”); Enter length:5
scanf(“%d”, &width); Enter width=10
area=length*width; Area of rectangle=50
printf(“\nArea of rectangle=%f”,area);
getch();
}
Program to calculate the sum of subjects and print percentage
#include<stdio.h>
Enter marks of five subjects:60 70 75 80 85
#include<conio.h>
Sum of marks=370
void main(void)
{ Percentage is=74
float s1,s2,s3,s4,s5,sum,tmarks=500;
float percentage;
printf(“Enter marks of five subjects:”);
scanf(“%f ,%f ,%f ,%f ,%f”, &s1,&s2,&s3,&s4,&s5);
sum=s1+s2+s3+s4+s5;
percentage=(sum*100)/tmarks;
printf(“\nSum of marks=%f”,sum);
printf(“\nPercentage is=%f”,percentage);
getch();
}
Comparing numbers: Program to compare three numbers
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a,b,c;
printf(“Enter three numbers:”);
scanf(“%d%d%d”,&a,&b,&c);
if((a>=b)&&(a>=c)) Enter three numbers:3
printf(“Largest number=%d”,a); 4
else if((b>=a)&&(b>=c)) 2
printf(“Largest number=%d”,b); Largest number=4
else
printf(“Largest number=%d”,c);
getch();
}
Solving quadratic Equation:
#include <stdio.h> Enter coefficients a, b, and c: 5
#include <math.h> -9
void main(void)
{ -2
int a, b, c, d; Roots are real and different

Root 1 is 2.000000 and Root 2 is -0.200000


float r1, r2;
printf("Enter coefficients a, b, and c: ");
scanf("%d %d %d", &a, &b, &c);
d = b * b - 4 * a * c;
if (d == 0)
{
printf("Roots are real and equal\n");
r1 = r2 = -b / (2 * a);
printf("Root 1 and Root 2 are %f\n", r1); Enter coefficients a, b, and c: 2
} 4
else if (d > 0)
5
{
printf("Roots are real and different\n"); Roots are imaginary
r1 = (-b + sqrt(d)) / (2. * a);
r2 = (-b - sqrt(d)) / (2. * a);
printf("Root 1 is %f and Root 2 is %f\n", r1, r2);
}
else
{
printf("Roots are imaginary\n");
}
getch();
}
Finding factorial of given numbers:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int n,k,fact=1;
printf(“Enter a number to calculate its factorial:”);
scanf(“%d”, &n);
Enter a number to calculate its factorial: 5
for(k=1; k<=n; k++) Factorial of 5 = 120
fact=fact*k;
printf(“Factorial of %d = %d”,n,fact);
getch();
}
Finding Table of a given number:
Enter table number whose
#include<stdio.h>
table is required: 5
#include<conio.h>
void main(void) 5x1=5
{ 5 x 2 = 10
int n, k; 5 x 3 = 15
5 x 4 = 20
printf(“Enter table number whose table is required:”); 5 x 5 = 25
scanf(“%d”,&n); 5 x 6 = 30
for(k=1; k<=10; k++) 5 x 7 = 35
printf(“%d x %d = %d\n”, n, k, n*k); 5 x 8 = 40
getch(); 5 x 9 = 45
} 5 x 10 = 50
Generating / Summing of simple series(even / odd):
Sum of odd series from 1 to 100:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int k,sum; Sum = 2500
sum=0;
for(k=1;k<100;k=k+2)
sum=sum+k;
printf(“Sum is %d”,sum);
getch();
}
Sum of even series from 1 to 100:
#include<stdio.h>
#include<conio.h>
void main(void)
{
int k,sum;
Sum = 2550
sum=0;
for(k=2;k<=100;k=k+2)
sum=sum+k;
printf(“Sum = %d”,sum);
getch();
}
Generating odd series from 1 to 20:
#include<stdio.h>
#include<conio.h>
void main(void)
{ 1 3 5 7 9 11 13 15 17
int k; 19
for(k=1; k<20; k=k+2)
printf(“%d\t”, k);
getch();
}
Generating even series from 1 to 20:
#include<stdio.h>
#include<conio.h>
void main(void) 2 4 6 8 10 12 14 16 18
{ 20
int k;
for(k=2; k<=20; k=k+2)
printf(“%d\t”, k);
getch();
}
Part II
HTML
Create a webpage/ Website involving:
 Lists
 Images
 Hyperlinks
 Tables
1. HTML List
There are three types of list in HTML
 Unordered list
 Ordered list
 Definition list
Unordered, Ordered List and definition list:
1.1. An unordered list starts with the <ul> tag. An ordered list starts with
<ol> tag. Each list item starts with the <li> and ends with the </li>.
<html>
<body>
<h2> An Unordered HTML List</h2>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
<h2>An Ordered HTML List</h2>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>

Output:
1.2. HTML Ordered List with Letters:
<html>
<body>
<h2>Ordered List with Letters</h2>
<ol type="A">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</htm|>

Output:

2. Images and backgrounds:


2.1. HTML Images:
<html>
<body>
<h2>HTML Image</h2>
<img src="pic laptop.jpg" alt="Laptoo" width="500" height="333>
</body>
<htm|>
Output:
2.2. HTML link:
<html>
<body>
<h2>Local Links</h2>
<p><a href-"html images.asp">HTML Images</a> is a link to a page on this
website.</p>
<p> <a href-"https://www.KS.org/">KS</a> is a link to a website on
the World Wide Web.</p>
</body>
</html>

Output:

2.3. Backgrounds:
<html>
<body style="background-color:powderblue”>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Output:

3. Hyperlinks:
The <a> tag defines a hyperlinks which is use to link from one page to
another. The most important attributes of the <a> elements is the href
attribute, which indicate the link’s destination.
<html>
<body>
<a href= "https://www.KSschools.com">Welcome to our school! </a>
</body>
</html>

Output:
4. Tables:
An HTML table is defined with the <table> tag.
Each table row is defined with the <tr> tag. A table header is defined with the <th>
tag. A table data is defined with the <td> tag

<html>
<body>
<h2>Basic HTML Table</h2>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>

<tr>
<td>Jalil</td>
<td>Saqib</td>
<td>50</td>
</tr>

<tr>
<td>Ali</td>
<td>Awas</td>
<td>94</td>
</tr>

<tr>
<td>Munir</td>
<td>Shah</td>
<td>80</td>
</tr>

</table>
</body>
</html>
Output:
__________________________________________________________
Practice sheet:
Question No. 1 [Marks: 06]
i. Rearrange the lines in the correct order, so that the program compares two
numbers entered by the user and displays the larger number. [Marks: 2]
{
if (a > b)
printf("Larger number = %d", a);
else
printf("Larger number = %d", b);
printf("Enter the first number: ");
scanf("%d", &a);
scanf("%d", &b);
printf("Enter the second number: ");
int a, b;
#include <stdio.h>
void main(void)
}
ii. Modify the above program so that it also checks if both numbers are equal, and
displays an appropriate message. [Marks: 3]
iii. Write down the output of the program when the input numbers are 8 and 8.
[Marks: 1]
Question No. 2 [Marks: 6]
Write a C program to solve a quadratic equation of the form ax² + bx + c = 0. The
program should prompt the user to input the coefficients a, b, and c, and should
then calculate the roots using the quadratic formula.
Requirements:
i. Input: [Marks: 2]
 The program should prompt the user to enter the values of a, b, and c.
ii. Processing: [Marks: 3]
 The program should calculate the roots using the formula:

−𝑏 ± √𝑏 2 − 4𝑎𝑐
𝑥=
2𝑎
iii. Output: [Marks: 1]
 The program should display the roots of the equation. If the discriminant is
negative, it should print "No real roots."

You might also like