BCA I Programming Methodology practicals
BCA I Programming Methodology practicals
S.No. Practicals
1 Write a programme to create a pyramid structure.
2 Write a programme to check whether a given
number is prime or not.
3 Write a programme to generate even/odd series
from 1 tom 100 using conditional statements.
4 Write a programme for call by value and call by
reference.
5 Write a programme to print table of any number.
6 Write a programme to find factorial of a given
number.
7 Write a programme to print Fibonacci series.
8 Write a programme to check whether a given
number even or odd.
9 Write a programme to swap the contents of two
variables.
10 Write a programme to perform multiplication of
two matrices.
1.Write a programme to create a pyramid
structure.
#include<iostream.h>
include<conio.h>
int main()
{
int i, space, j;
for(i=1; i<=6; i++)
{
for(space=6; space>i; space--)
cout<<" ";
for(j=0; j<i; j++)
cout<<"* ";
cout<<endl;
}
cout<<endl;
return 0;
}
Output:
#include <iostream>
using namespace std;
int main(){
int i;
cout << "Odd numbers between 1 to 100 are: " << endl;
for (i = 1; i <= 100; i++){
if (i % 2 != 0)
cout << i << " ";
}
cout << "Even numbers between 1 to 100 are: " << endl;
/* If number is divisible by 2. */
if(i % 2 == 0) {
return 0;
}
Output
1. #include <iostream>
2. using namespace std;
3. void change(int data);
4. int main()
5. {
6. int data = 3;
7. change(data);
8. cout << "Value of the data is: " << data<< endl;
9. return 0;
10. }
11. void change(int data)
12. {
13. data = 5;
14. }
Output:
1. #include<iostream>
2. using namespace std;
3. void swap(int *x, int *y)
4. {
5. int swap;
6. swap=*x;
7. *x=*y;
8. *y=swap;
9. }
10. int main()
11. {
12. int x=500, y=100;
13. swap(&x, &y); // passing value to function
14. cout<<"Value of x is: "<<x<<endl;
15. cout<<"Value of y is: "<<y<<endl;
16. return 0;
17. }
Output:
int main()
int i,n;
cin>>n;
for(i=1;i<=10;++i)
return 0;
Output
6 * 1=6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24
6 * 5 = 30
6 * 6 = 36
6 * 7 = 42
6 * 8 = 48
6 * 9 = 54
6 * 10 = 60
6.Write a programme to find factorial of a given
number.
#include <iostream>
using namespace std;
int main() {
int n;
long factorial = 1.0;
if (n < 0)
cout << "Error! Factorial of a negative number doesn't exist.";
else {
for(int i = 1; i <= n; ++i) {
factorial *= i;
}
cout << "Factorial of " << n << " = " << factorial;
}
return 0;
}
Run Code
Output
#include <iostream>
using namespace std;
int main() {
int t1 = 0, t2 = 1, nextTerm = 0, n;
nextTerm = t1 + t2;
while(nextTerm <= n) {
cout << nextTerm << ", ";
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
return 0;
}
Output
#include <iostream>
using namespace std;
int main()
{
int num;
cout<<"Enter an integer number: ";
cin>>num;
if(num%2==0)
cout<<num<<" is an EVEN number."<<endl;
else
cout<<num<<" is an ODD number."<<endl;
return 0;
}
Output
First run:
Enter an integer number: 10
10 is an EVEN number.
Second run:
Enter an integer number: 11
11 s an ODD number.
9.Write a programme to swap the contents of two
variables.
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. int a=5, b=10;
6. cout<<"Before swap a= "<<a<<" b= "<<b<<endl;
7. a=a*b; //a=50 (5*10)
8. b=a/b; //b=5 (50/10)
9. a=a/b; //a=10 (50/5)
10. cout<<"After swap a= "<<a<<" b= "<<b<<endl;
11. return 0;
12. }
Output:
Before swap a= 5 b= 10
After swap a= 10 b= 5
10 Write a programme to perform multiplication of two
matrices.
#include <iostream>
using namespace std;
int main()
{
int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k;
cout << "Enter rows and columns for first matrix: ";
cin >> r1 >> c1;
cout << "Enter rows and columns for second matrix: ";
cin >> r2 >> c2;
cout << "Enter rows and columns for first matrix: ";
cin >> r1 >> c1;
cout << "Enter rows and columns for second matrix: ";
cin >> r2 >> c2;
}
return 0;
}
Output
Output Matrix:
24 29
6 25