You are on page 1of 9

NAME: SEHAR DAWOOD

ROLL NO: BCBSM-S22-008


SUBMITTED TO: Sir Zeeshan Mubeen

TASK
Q1:: Write a program in C++ to read ‘n’ numbers from user then find and print all
prime numbers from these entered numbers.

PROGRAM
#include<iostream>
using namespace std;
int main(){ int n,i,j;
cout<<"enter number=";
cin>>n; for(i=2; i<n; i++)
{

for(j=2; j<=i; j++){


if(i%j==0){ break;
} } if(i==j)
{ cout<<i<<en
dl;
}
}

Write a program in C++ to check whether a number is a palindrome or


not.(such numbers are same for reading from start or last) e.g., Input a
number: 121
Q2:

Expected Output: 121 is a palindrome number


PROGRAM

#include<iostream>
using namespace std;
int main(){ int n,r;
cout<<"enter number="; cin>>n;
for(r=0; n!=0; n=n/10){
r=r*10; r=r+n%10;
}
cout<<"reverse"<<r<<endl; if(n==r){
cout<<r<<"is a palindrome numb";
}
else
{
cout<<r<<" is not a palindrome numb";
}

Write a program in C++ to print a string in reverse order. E.g., HOUSE will
be ESUOH.

PROGRAM
Q3:

#include<iostream>
#include<string.h>
using namespace std;
int main(){ char
ch[55]="sehar";
cout<<"change reverse string:"<<strrev(ch);
}

Write a program in C++ to count the prime number occurs within given range
by user.

PROGRAM
#include<iostream>
using namespace std;
int main(){ int num , i,
count,n; cout<<"enter
range:"; cin>>n;
Q4:

for(num=1; num<=n; num++){ count=0;


for(i=2; i<=num/2; i++){
if(num%2==0){ count+
+; break;
}
}
if(count==0 && num!= 1) cout<<num<<endl;
}
}

Write a program to print following:


Part1:
****************
****************
****************
**************** PROGRAM:

#include<iostream> using
namespace std; int main(){ int
rows,column,i,k; cout<<"enter
number of rows"; cin>>rows;
cout<<"enter number of column";
cin>>column; for(i=1; i<=rows; i+
+){ for(k=1; k<=column; k++)
{ cout<<"*";
Q5:

}
cout<<"\n";
}
}
• PART 2:

**

***

****

*****

******

PROGRAM:
#include<iostream>

using namespace std;

int main(){ int

rows,i,j;

cout<<"number of rows";

cin>>rows; cout<<"enter number

of column"; for(int i=1; i<=rows;

i++)

{ for(j=1; j<=i; +

+j){ cout<<"*";

} cout<<"\n";

• PART 3:

*
**

***

****

*****

PROGRAM:

#include<iostream>

#include<string.h> using namespace

std; int main(){ char

ch[55]="sehar"; cout<<"change reverse

string:"<<strrev

• PART 4:
*

***

****

******
********

*********

PROGRAM:
#include<iostream>

using namespace std; int

main(){ int rows,i,j,space;

cout<<"enter number of rows";

cin>>rows; for(i=1; i<=rows;

i++)

for(space=i; space<rows; space++)

cout<<" ";

for(j=1; j<=(2*i-1);j++)

cout<<"*"; }

cout<<"\n";

• PART 5:
1
222
33333
4444444
5555555555
PROGRAM:

• PART 6:
1
212
32123
43214322
54321454321
PROGRAM:

You might also like