Professional Documents
Culture Documents
PF THEOREY
BSSE-1-B
SUBMITTED BY: ABU BAKAR
SUBMITTED TO: SADAF ANWAR
QUESTION#1:
STRING ARRAY:
Strings hold groups of characters, like a word or a phrase. In programming, strings allow
programmers to easily store, find, and change information in a program.
String variables make it easier for programmers to find information and reuse values in their
code. strings make simple for programmers to read and update the values allocated to various
variables across their programmers.
DECLARATION:
The array is named and the type of its elements are specified in a"array declaration." It can also
provide the array's size in terms of elements. A variable having an array type is regarded as a
pointer to the array elements' type.
For example, you can create an array named age and store the ages of 5 students as follows:
The array age will store 5 integers representing the ages of different students.
INITIALIZATION:
The process of assigning and storing elements to an array is known as array initialization.
Initialization can be done all at once or one by one. The first element in an array is kept at index
0, and the last member is kept at index n-1, where n is the array's total number of items.
CODE:
string names [5] = {“A”,” B”,” C”,” D”, “E”};
EXAMPLE:
#include<iostream>
using namespace std;
int main ()
cout<<names[i]<<endl;
return 0;
Output:
QUESTION#2:
CODE:
#include<iostream>
int main ()
return 0;
Output:
QUESTION#3:
int prime(int n)
int c=0,i;
for(i=2;i<n;i++)
if(n%i==0)
c=1;
if(c==0)
else
int main()
int n;
cout<<"\nEnter a number: ";
cin>>n;
prime(n);
return 0;
Output:
QUESTION#4:
#include<iostream>
int reverse(int a)
while(a!=0)
int i=0;
i=i*10;
i=i+a%10;
a=a/10;
cout<<i;
int main()
int a;
cin>>a;
reverse(a);
return 0;
Output:
QUESTION#5:
#include<iostream>
int main()
for(i=0;i<2;i++)
for(j=0;j<2;j++)
cout<<"matrix1["<<i<<"]["<<j<<"]="<<matrix1[i][j]<<endl;
for(i=0;i<2;i++)
for(j=0;j<2;j++)
cout<<"matrix2["<<i<<"]["<<j<<"]="<<matrix2[i][j]<<endl;
cout<<"Adding matrices\n";
for(j=0;j<2;j++)
sum[i][j]=matrix1[i][j]+matrix2[i][j];
cout<<"\t"<<sum[i][j];
cout<<endl;
return 0;
Output: