1. Write a C++ program that will print the following pattern
*************
*****
****
***
**
*
Solution:
#include <cstdlib>
#include <iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(int argc, char *argv[])
{
int i=7;
int j=7;
for(i=1;i<=7;i++){
for(j=7-i;j>=1;--j)cout<<"*";
cout<<"\n";
}
cout<<"\n";
system("PAUSE");
return EXIT_SUCCESS;
}
2. Write a program that will print the following pattern:
1******
12*****
123****
1234***
12345**
123456*
1234567
Solution:
#include <cstdlib>
#include <iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(int argc, char *argv[])
{
int i;
int j;
int k;
for(i=1;i<=7;i++){
for(j=1;j<=i;++j)
cout<<j;
for(k=7-i;k>=1;k--)cout<<"*";
cout<<"\n";
}
cout<<"\n";
system("PAUSE");
return EXIT_SUCCESS; }
No comments
Post a Comment