Showing posts with label cplusplus Tutorials. Show all posts
Showing posts with label cplusplus Tutorials. Show all posts

Thursday, January 22, 2015

c++ Creating Diamond Shape

Here is the code on how to crate diamond share in c++.

#include "stdafx.h"
#include<iostream>
using namespace std;
int main() {

int a, b, c;
    int n = 0;
    cout<<"Enter N:";
    cin>>n;

    for (a = 1; a <= n; a++)
    {
          for (b = 0; b < (n - a); b++)
                cout<<" ";
          for (b = 1; b <= a; b++)
                cout<<"*";
          for (c = 1; c < a; c++)
               cout<<"*";
cout<<"\n";
    }

    for (a = n - 1; a >= 1; a--)
    {
          for (b = 0; b < (n - a); b++)
               cout<<" ";
          for (b = 1; b <= a; b++)
                cout<<"*";
          for (c = 1; c < a; c++)
               cout<<"*";
         cout<<"\n";
    }
 
   cout<<"\n";


cin.get();
cin.get();
return 0;
}


Read More

c++ Reverse Number

here is the code in c++ on how to reverse the number input by the user.

#include "stdafx.h"
#include<iostream>
using namespace std;

int main() {
int number, reverse_num = 0;
cout<<"Input a Number to Reverse:";
 cin>> number;

   for(;number!= 0 ; ) {
      reverse_num = reverse_num * 10;
      reverse_num = reverse_num + number%10;
      number = number/10;
   }
   cout<<"Reversed Number is:  "<<reverse_num;

cin.get();
cin.get();
return 0;
}

Read More

c++ creating triangle

here is the code for creating triangle on c++.

#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {

for(int x=1;x<=7;x = x + 2) {
for(int zz=7;zz>=x;zz--) {
cout<<" ";
}
for(int y=1;y<=x;y++) {
for(int z=1;z<=1;z++) {
cout<<" ";
}
cout<<"*";
}
cout<<"\n";
}
cin.get();
cin.get();
return 0;
}

Read More

c++ sample codes.


#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {

for(int x= 1;x<=5;x++) {
for(int z=1;z<=x;z++) {
cout<<" ";
}
for(int y=1;y<=5;y++) {
cout<<"*";
}
cout<<"\n";
}
cin.get();
cin.get();
return 0;
}

Read More

c++ create right triangle.

this is how to create right triangle on c++.

#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {

int a;
cout<<"Enter N:";
cin>>a;
for(int x= 1;x<=a;x++) {
for(int y=1;y<=x;y++) {
cout<<"*";
}
cout<<"\n";
}
cin.get();
cin.get();
return 0;
}













#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {

int a;
cout<<"Enter N:";
cin>>a;
for(int x= 1;x<=a;a--) {
for(int y=1;y<=a;y++) {
cout<<"*";
}
cout<<"\n";
}
cin.get();
cin.get();
return 0;
}
Read More

c++ Displaying the number repeatedly.

here is the code for displaying numbers repeatedly using nested loop.

#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {

for(int x= 1;x<=5;x++) {
for(int y=1;y<=5;y++) {
cout<<y;
}
cout<<"\n";
}
cin.get();
cin.get();
return 0;
}












#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {

int a = 1;
cout<<"Enter N:";
cin>>a;
for(int x= 1;x<=a;x++) {
for(int y=1;y<=a;y++) {
cout<<y;
}
cout<<"\n";
}
cin.get();
cin.get();
return 0;
}


Read More
Designed By Seo Blogger Templates Published.. Blogger Templates