0% found this document useful (0 votes)
2 views3 pages

5

The document contains programming tasks focused on problem-solving using C++. It includes code snippets for identifying outputs, generating multiplication tables, printing patterns, and finding prime numbers between 1 and 100. Each task is accompanied by expected outputs and C++ code implementations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

5

The document contains programming tasks focused on problem-solving using C++. It includes code snippets for identifying outputs, generating multiplication tables, printing patterns, and finding prime numbers between 1 and 100. Each task is accompanied by expected outputs and C++ code implementations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PROGRAMMING FOR PROBLEM SOLVING

EXPERIMENT - 5
Task 1: Identify output for below blocks of code without using Codeblocks. Give
justification.
a. #include<iostream> b. #include<iostream>
void main() void main()
{ {
int c=1; int c=0;
while(1) while(c<=5)
{ {
if(c==5) c++;
break; if(c==3)
cout<<c; continue;
c++; cout<<c;
} }
} }
OUTPUT: 12345 OUTPUT: 12456
c. void main() d. void main() {
{ int i,j,x=0;
int i,j,k;
for(i=0;i<5;++i)
{ for (i = 1; i <= 5; i++) {
for(j=0;j<i;++j)
for (j = 1; j <= (5 - i) ;j++) cout<<" ";
x+=(i+j-1);
cout<<x; for (k = 1; k <= i; k++)
break; cout<<i;
} cout<<“\n”;}
cout<<x;
}
}
OUTPUT: 00 OUTPUT:
1
22
333
4444
55555
Task2: Write a C++ program to print multiplication table for 1 to 10.

Expected Output:

PROGRAM:
#include <iostream>
using namespace std;
int main()
{
int i,j,res,num;
cout<<"Tables from 1-10"<<endl;
for(i=1;i<=10;i++)
{
num=i;
for(j=1;j<=10;j++)
{
res=num*j;
cout<<res<<" ";
}
cout<<endl;
}
cout<<endl;
return 0;
}

Task 3: Write a C++ program to print below patterns.


1 1
12 23
123 456
1234 7 8 9 10
#include<iostream>
int main()
{
int i,j,spc,rows,k,t=1;
cout<<"Input number of rows : ";
cin>>rows;
spc=rows+4-1;
for(i=1;i<=rows;i++)
{
for(k=spc;k>=1;k--)
{
cout" ";
}
for(j=1;j<=i;j++)
cout<<t++;
cout<<"\n";
spc--;
}
}

Task 4: Write a C++ program to print all the prime numbers from 1 to 100.
PROGRAM:
#include<iostream>
using namespace std;
int main()
{
int i, chk=0, j;
cout<<"Prime Numbers Between 1 to 100 are:\n";
for(i=1; i<=100; i++)
{
for(j=2; j<i; j++)
{
if(i%j==0)
{
chk++;
break;
}
}
if(chk==0 && i!=1)
cout<<i<<endl;
chk = 0;
}
cout<<endl;
return 0;
}

You might also like