You are on page 1of 6

(1) Write in C++ language to draw the following

figure:

#include<iostream.h>
using namespace std;

int main() {
for(int i=1;i<10;i++)
{
for(int j=1;j<10;j++)
if(i+j==6||j-i==4||i-j==4||i+j==14)
cout<<"*";
else
cout<<" ";
cout<<endl;}
return 0;
}
(2) Write in C++ language to draw the following figure:

#include <iostream.h>
using namespace std;
int main() {
int num=4;
for(int i=1;i<8;i++)
{
for(int j=1;j<8;j++)
if(i==j || i+j==8)
{
if(i<5)
cout<<num-i;
else
cout<<num+i-8;
}
else
cout<<" ";
cout<<endl;
}
return 0;
}
(3)
C++ program to print the pyramid of digits in
pattern as below.
#include <iostream.h>
using namespace std;
int main()
{
int count;
for(int i=1;i<6;i++)
{
count=i-1;
for(int j=0;j<9;j++)
{
if(i+j<=4||j-4>=i)
cout<<"*";
else if (j>4)
cout<<--count;
else
cout<<++count;
}

cout<<endl;
}
return 0;
}
(4)
C++ Program to Check Whether a Number is Prime or Not (A Prime
number is 1,3,5,7,11,13,.... and so on) .

#include<iostream.h>
void main()
{ int num ,j=0;
cin>>num;
for(int i=2;i<num;i++)
if(num % i==0)
j++;
if(j==0)
cout<<" Prime";
else
cout<<"Not Prime";
}
(5)Write C++ program to read 5 numbers and determine if the numbers
sorted ascending or not.(‫) يوجد فد المالزد نصًاد‬

#include<iostream.h>
void main()
{ int x1,x2,x3,x4,x5;
cout<<"enter five numbers";
cin>>x1>>x2>>x3>>x4>>x5;
if(x1>x2)&&(x2>x3) &&(x3>x4) &&(x4>x5)
cout<<"The numbers are sorted descending";
else
cout<<"The numbers are sorted Ascending";
}
(6) C++ program to Calculate (1) + (1+2) + (1+2+3) + (1+2+3+4) + ... +
(1+2+3+4+...+n) series

#include<iostream.h>
void main()
{

int i,j,n,sum=0;
cout<<"enter the N number for series";
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)

{ sum+=j;
}}
cout<<"Sum: "<<sum;
}

You might also like