10 SCIENCE BOARD PRACTICALS (2)
10 SCIENCE BOARD PRACTICALS (2)
#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:
#include<iostream>
using namespace std;
int main()
{
// declare variables
double num1, num2;
#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;
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;
#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:
#include<iostream>
using namespace std;
int main() {
float fahren , Celsius;
cout << “Enter temperature in Fahrenheit\n”;
cin >> fahren;
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;
Enter 10 Numbers :
1 2 3 4 5 6 7 8 9 10
#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:
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