0% found this document useful (0 votes)
15 views27 pages

10 SCIENCE BOARD PRACTICALS (2)

The document contains multiple C++ program examples that perform various tasks, including displaying a welcome message, performing arithmetic operations, calculating totals and averages, checking number signs, finding areas, converting units, sorting numbers, and calculating factorials and grades. Each program is accompanied by its source code and sample output. The examples illustrate fundamental programming concepts and basic input/output operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views27 pages

10 SCIENCE BOARD PRACTICALS (2)

The document contains multiple C++ program examples that perform various tasks, including displaying a welcome message, performing arithmetic operations, calculating totals and averages, checking number signs, finding areas, converting units, sorting numbers, and calculating factorials and grades. Each program is accompanied by its source code and sample output. The examples illustrate fundamental programming concepts and basic input/output operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

OBJECT: Write a program to print WELCOME text in a new line

#include <iostream>
using namespace std;

int main()
{
cout << "\n\n Print a welcome text in a separate line:\n";
cout << "----------------------------------------------\n";
cout << " WELCOME \n" ;
OUTPUT:

Print a welcome text in a separate line:


----------------------------------------------
WELCOME
OBJECT: Write a program to add, subtract, multiply and divide two
numbers using arithmetic operators.

#include<iostream>
using namespace std;
int main()
{
// declare variables
double num1, num2;

// take input from end-user


cout << "Enter two Numbers :: ";
cin >> num1 >> num2;

// addition of two number


cout << num1 << "+" << num2 << " = "<< num1+num2 << endl;

// subtraction of two number


cout << num1 << "-" << num2 << " = "<< num1-num2 << endl;

// multiplication of two number


cout << num1 << "*" << num2 << " = "<< num1*num2 << endl;

// division of two number


cout << num1 << "/" << num2 << " = "<< num1/num2 << endl;
return 0;
}
OUTPUT:
Enter two number: 20 5
20+5=25
20-5+15
20*5=100
20/5=4
OBJECT: Write a program to compute the total and average of six
numbers.

#include <iostream>
using namespace std;

int main()
{

float n1,n2,n3,n4,n5,n6,tot,avrg;
cout << "\n\n Compute the total and average of six numbers
:\n";
cout << "--------------------------------------------------
-\n";
cout<<" Input 1st two numbers (separated by space) : ";
cin>> n1 >> n2;
cout<<" Input third and fourth numbers (separated by
space) : ";
cin>> n3 >> n4;
cout<<" Input 1st two numbers (separated by space) : ";
cin>> n1 >> n2;

tot=n1+n2+n3+n4+n5+n6;
avrg=tot/6;

cout<<" The total of six numbers is : "<< tot << endl;


cout<<" The average of six numbers is : "<< avrg <<
endl;
cout << endl;

return 0;
}
OUTPUT:
Compute the total and average of four numbers :
----------------------------------------------------
Input 1st two numbers (separated by space) : 25 20
Input third and fourth numbers (separated by space) : 10 20
Input last two numbers (separated by space) : 15 25
The total of six numbers is : 115
The average of six numbers is : 19.166
OBJECT: Write a program to check whether a number is positive,
negative or zero.

#include <iostream>
using namespace std;

int main()
{
signed long num1 = 0;
cout << "\n\n Check whether a number is positive, negative
or zero:\n";
cout << "--------------------------------------------------
---\n";
cout << " Input a number : ";
cin >> num1;
if(num1 > 0)
{
cout << " The entered number is positive.\n\n";
}
else if(num1 < 0)
{
cout << " The entered number is negative.\n\n";
}
else
{
std::cout << " The number is zero.\n\n";
}
return 0;
}
OUTPUT:
Check whether a number is positive,negative or zero:
-----------------------------------------------------
Input a number : 8
The entered number is positive.
OBJECT: Write a program to find area of rectangle.

#include<iostream>
#define PI 3.141
using namespace std;

int main ( );
{
int length, breadth, area;
cout << "Enter length of rectangle : "
cin >>length;
cout << "Enter breadth of rectangle : "
cin >>breadth;

// Formula to calculate area of rectangle


area = lenth * breadth;
cout << "Area of rectangle : " <<area;
return 0;
}
OUTPUT:
Enter length of rectangle :4
Enter breadth of rectangle :4
Area of rectangle :16
OBJECT: Write a program to input length in centimeter and convert it
into meter.

#include<iostream>
using namespace std;

int main()
{
float kmet,met,cent;
cout << "\n\n Convert centimeter into meter and
kilometer:\n";
cout << "--------------------------------------------------
\n";
cout << " Input the distance in centimeter : ";
cin >> cent;
met = (cent/100);
kmet= (met/100);
cout << " The distance in meter is: "<< met << endl;
cout << " The distance in kilometer is: "<< kmet << endl;
cout << endl;
return 0;
}
OUTPUT:

Convert centimeter into meter and kilometer:


--------------------------------------------------
Input the distance in centimeter : 25
The distance in meter is:0.25
The distance in kilometer is:0.00025
OBJECT: Write a program to temperature in Fahrenheit and convert it
into Celsius.

#include<iostream>
using namespace std;
int main() {
float fahren , Celsius;
cout << “Enter temperature in Fahrenheit\n”;
cin >> fahren;

// convert fahreneheit to celsius


// Subtract 32, then multiply it by 5, then divide by 9

celsius = 5 * (fahren - 32) / 9;


cout << fahren <<" Fahrenheit is equal to " << celsius <<"
Centigrade";
return 0;
}
OUTPUT:

Enter temperature in Fahrenheit 80


80 Fahrenheit is equal to 26.6667 Centigrade
OBJECT: Write a program that takes a number and prints its multiple
up to 10.

SOURCE CODE:

#include<iostream>
#include<conio.h>
using namespace std;
int main() {
int n,i,t;
cout << “Enter a number\n”;
cin >> n;
for(i=1;i<=10;i++)
{
t=i*n;
cout <<t<< endl; }
getch();
}
OUTPUT:

Enter a number 3
3
6
9
12
15
18
21
24
27
30
OBJECT: Write a program to get 10 characters using getch( ) function
and print all characters
#include <iostream>
#include <conio.h>
using namespace std;
int main() {
int i,len;
//integer variable declaration
cout<<"Enter the Array length: ";
//Ask input for array length
cin>>len;
//Reading the input for array length char
char_array[len];
//Array declaration cout<<"\n";//move to next line
cout<<"Enter the characters for array :";
//Ask input for elements(numbers)
for(i=0; i<len; i++){
//input using for loop
cin>>char_array[i];
//Reading the array elements from user
}
cout<<"\ndisplay the characters\n";
for(i=0; i<len; i++)
{
//display elements using for loop
cout<<char_array[i];
cout<<("\n");
}
getch();
return 0; }
OUTPUT:
Enter the array length: 7
Enter the characters for array: program
Display the characters
p
r
o
g
r
a
m
OBJECT: Write a program to read 10 numbers and sort them in
descending order.
#include<iostream>
using namespace std;
int main ()
{
int num[10];
int i, j, desc;

cout<<"\n Enter 10 Numbers : \n";


cout<<" ";
for (i = 0; i < 10; ++i)
cin>>num[i];

for (i = 0; i < 10; ++i) // 'for' loop is used for


sorting the numbers in descending order
{
for (j = i + 1; j < 10; ++j)
{
if (num[i] < num[j])
{
desc = num[i];
num[i] = num[j];
num[j] = desc;
}
}
}
cout<<"\n Numbers in Descending Order : \n";
for (i = 0; i < 10; ++i)
{
cout<<" ";
cout<<num[i];
cout<<"\n";
}
}
OUTPUT:

Enter 10 Numbers :
1 2 3 4 5 6 7 8 9 10

Numbers in Descending Order :


10
9
8
7
6
5
4
3
2
1
OBJECT: Write a program to read 10 numbers and sort them in
ascending order.

#include<iostream>
using namespace std;
int main() {
int a[10];
int n, temp;
cout << "Enter size of an array:";
cin>>n;
cout << "Enter array elements:";
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = 1 + i; j < n; j++) {
if (a[i] > a[j]) {
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
cout << "Array list after sorting:";
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
return 0;
}
OUTPUT:

Enter size of an array:5


Enter array elements:10 30 20 50 40
Enter array elements:10 30 20 50 40
OBJECT: Write a program to read an integer n and print the factorial
of n
#include <iostream>
using namespace std;
int main(void)
{
int num,a,fact=1;
cout<<”\n\t\t\t Factorial of a number”;
cout<<”\n\t\t\t ----------------------”;
cout<<”\n\t\t\t Enter positive integer number: ”;
cin>>num;
for(a=1;a<=num;a++)
{
fact=fact*a;
}
cout<<”\n\n\t\t\t Factorial of a given number is: “<<fact;
return 0;
}
OUTPUT:

Factorial of a number
----------------------
Enter positive integer number: 6
Factorial of a given number is: 720
OBJECT: Write a program to calculate total, percentage and grade

#include<iostream.h>
#include<conio.h>
void main(void){
int no, i;
float marks[10],per=0,total=0;
clrscr();
cout<<”Enter number of subjects”;
cin>>no;
cout<<”Enter marks of “<<no<<”subject”;
for(j=0;j<no;j++)
{
cin>>marks[i];
}
for(j=0;j<no;j++)
{
total=total+marks[i];
}
cout<<”Total”<<total<<endl;
per=total/no;
cout<<”Percentage”<<per<<”%”<<endl;
if(per>85){
cout<<”A grade”;
}
else if(per<85 && per>=75)
{
cout<<”B grade;
}
else if per<75 && per>=50)
{
cout<<”C grade;
}
else if per<50 && per>=30)
{
cout<<”D grade;
}
else
{
cout<<”FAIL”;
}
getch();
}
OUTPUT:
Enter number of subject: 6
Enter marks of subject:
88
67
98
76
63
72
Total: 464
Percentage: 77.33%
B grade

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy