#include<iostream>
#include<string.h>
//#include<graphics.h>
//#include<dos.h>
#include<math.h>
using namespace std;
int main()
{
// clrscr();
int c=1,c1=4,c2=1,c3=1,r[2000][10],c4=1,c5=1,p[2000][10],q[2000][10],o[2000][10],t[2000][10],s[2000][10],w[2000][10],i,l=1,j,k,m,u[2000][10],a[2000][10],v,e=0,g=1,f=1,h=0,b[2000][10],z[2000][10],y[6000][5],x[2000][10];
cout<<"Enter 0 for not selecting and 1 for selecting\n";
for(i=0;i<=15;i++)
{
cout<<"Enter the value for "<<i<<":";
cin>>v;
if(v==1)
{
a[c][5]=i;
m=i;
while(c1!=0)
{
a[c][c1]=m%2;
m=m/2;
c1--;
}
c++;
c1=4;
}
}
for(i=1;i<c;i++)
{
for(j=1;j<c;j++)
{
for(k=1;k<=4;k++)
{
if(a[i][k]+a[j][k]==1)
e++;
}
if(e==1)
{
for(k=1;k<=4;k++)
{
if(a[i][k]+a[j][k]!=1)
b[f][g]=a[i][k];
else
b[f][g]=3;
g++;
}
b[f][5]=a[i][5];
b[f][6]=a[j][5];
g=1;
f++;
h++;
}
e=0;
}
if(h==0)
{
for(k=1;k<=4;k++)
x[c2][k]=a[i][k];
c2++;
}
h=0;
}
c=0;
for(i=1;i<f;i++)
{
for(j=1;j<i;j++)
{
for(k=1;k<=4;k++)
{
if(b[i][k]==b[j][k])
c++;
}
if(c!=4)
e++;
c=0;
}
if(e==i-1)
{
for(k=1;k<=6;k++)
u[h+1][k]=b[i][k];
h++;
}
e=0;
}
for(i=1;i<=h;i++)
{
if(u[i][7]!=4)
{
for(j=1;j<=h;j++)
{
if(u[j][7]!=4)
{
if((u[i][6]==u[j][5])(u[i][6]==u[j][5])(u[i][5]==u[j][5])(u[i][5]==u[j][6]))
{
for(k=1;k<=h;k++)
{
if(u[j][6]==u[k][5]u[j][6]==u[k][6]u[j][5]==u[k][5]u[j][5]==u[k][6])
{
for(e=1;e<=h;e++)
{
if(i!=j&&i!=k&&i!=e&&j!=k&&j!=e&&k!=e)
{
if(u[k][6]!=u[e][5]&&u[k][6]!=u[e][6]&&u[k][6]!=u[e][6]&&u[k][6]!=u[e][5])
u[j][7]=4;
}
}
}
}
}
}
}
}
}
cout<<endl;
f=h+1;
e=0;h=0;g=1;l=1;c=1;
for(i=1;i<f;i++)
{
for(j=1;j<f;j++)
{
for(k=1;k<=4;k++)
{
if(u[i][k]+u[j][k]==1)
e++;
if((u[i][k]+u[j][k]==3)(u[i][k]+u[j][k]==4))
e=2;
}
if(e==1)
{
for(k=1;k<=4;k++)
{
if(u[i][k]+u[j][k]!=1&&u[i][k]+u[j][k]!=6)
z[l][g]=u[i][k];
else
z[l][g]=3;
g++;
}
g=1;
l++;
h++;
}
e=0;
}
if(h==0)
{
for(k=1;k<=7;k++)
w[c3][k]=u[i][k];
c3++;
}
h=0;
}
c=0;
for(i=1;i<l;i++)
{
for(j=1;j<i;j++)
{
for(k=1;k<=4;k++)
{
if(z[i][k]==z[j][k])
c++;
}
if(c!=4)
e++;
c=0;
}
if(e==i-1)
{
for(k=1;k<=4;k++)
t[h+1][k]=z[i][k];
h++;
}
e=0;
}
l=h+1;
e=0;h=0;g=1;m=1;c=1;c1=4;
for(i=1;i<l;i++)
{
for(j=i+1;j<l;j++)
{
for(k=1;k<=4;k++)
{
if(t[i][k]+t[j][k]==1)
e++;
if(t[i][k]+t[j][k]==3t[i][k]+t[j][k]==4)
e=2;
}
if(e==1)
{
for(k=1;k<=4;k++)
{
if(t[i][k]+t[j][k]!=1&&t[i][k]+t[j][k]!=6)
y[m][g]=t[i][k];
else
y[m][g]=3;
g++;
}
g=1;
m++;
h++;
}
e=0;
}
if(h==0)
{
for(k=1;k<=4;k++)
r[c4][k]=t[i][k];
c4++;
}
h=0;
}
c=0;h=0;
for(i=1;i<m;i++)
{
for(j=1;j<i;j++)
{
for(k=1;k<=4;k++)
{
if(y[i][k]==y[j][k])
c++;
}
if(c!=4)
e++;
c=0;
}
if(e==i-1)
{
for(k=1;k<=4;k++)
s[h+1][k]=y[i][k];
h++;
}
e=0;
}
f=h+1;
e=0;h=0;g=1;l=1;c=1;
for(i=1;i<f;i++)
{
for(j=1;j<f;j++)
{
for(k=1;k<=4;k++)
{
if(s[i][k]+s[j][k]==1)
e++;
if((s[i][k]+s[j][k]==3)(s[i][k]+s[j][k]==4))
e=2;
}
if(e==1)
{
for(k=1;k<=4;k++)
{
if(s[i][k]+s[j][k]!=1&&s[i][k]+s[j][k]!=6)
q[l][g]=s[i][k];
else
q[l][g]=3;
g++;
}
g=1;
l++;
h++;
}
e=0;
}
if(h==0)
{
for(k=1;k<=4;k++)
p[c5][k]=s[i][k];
c5++;
}
h=0;
}
c=0;
for(i=1;i<l;i++)
{
for(j=1;j<i;j++)
{
for(k=1;k<=4;k++)
{
if(q[i][k]==q[j][k])
c++;
}
if(c!=4)
e++;
c=0;
}
if(e==i-1)
{
for(k=1;k<=4;k++)
o[h+1][k]=q[i][k];
h++;
}
e=0;
}
for(i=1;i<=h;i++)
{
cout<<1;
}
cout<<endl;
for(i=1;i<c2;i++)
{
if(x[i][1]==0)
cout<<"A'";
if(x[i][1]==1)
cout<<"A";
if(x[i][2]==0)
cout<<"B'";
if(x[i][2]==1)
cout<<"B";
if(x[i][3]==0)
cout<<"C'";
if(x[i][3]==1)
cout<<"C";
if(x[i][4]==0)
cout<<"D'";
if(x[i][4]==1)
cout<<"D";
cout<<"+";
}
c=0;
for(i=1;i<c3;i++)
{
if(w[i][7]!=4)
{
if(w[i][1]==0)
cout<<"A'";
if(w[i][1]==1)
cout<<"A";
if(w[i][2]==0)
cout<<"B'";
if(w[i][2]==1)
cout<<"B";
if(w[i][3]==0)
cout<<"C'";
if(w[i][3]==1)
cout<<"C";
if(w[i][4]==0)
cout<<"D'";
if(w[i][4]==1)
cout<<"D";
cout<<"+";
}
}
cout<<endl;
c=0;
for(i=1;i<c4;i++)
{
for(j=1;j<=h;j++)
{
if(((o[j][1]-r[i][1])==2(o[j][1]-r[i][1])==3(o[j][1]-r[i][1])==0)&&((o[j][2]-r[i][2])==2(o[j][2]-r[i][2])==3(o[j][2]-r[i][2])==0)&&((o[j][3]-r[i][3])==2(o[j][3]-r[i][3])==0(o[j][3]-r[i][3])==3)&&((o[j][4]-r[i][4])==2(o[j][4]-r[i][4])==0(o[j][4]-r[i][4])==3))
c++;
}
for(j=1;j<c5;j++)
{
if(((p[j][1]-r[i][1])==2(p[j][1]-r[i][1])==3(p[j][1]-r[i][1])==0)&&((p[j][2]-r[i][2])==2(p[j][2]-r[i][2])==3(p[j][2]-r[i][2])==0)&&((p[j][3]-r[i][3])==2(p[j][3]-r[i][3])==0(p[j][3]-r[i][3])==3)&&((p[j][4]-r[i][4])==2(p[j][4]-r[i][4])==0(p[j][4]-r[i][4])==3))
c++;
}
if(c==0)
{
if(r[i][1]==0)
cout<<"A'";
if(r[i][1]==1)
cout<<"A";
if(r[i][2]==0)
cout<<"B'";
if(r[i][2]==1)
cout<<"B";
if(r[i][3]==0)
cout<<"C'";
if(r[i][3]==1)
cout<<"C";
if(r[i][4]==0)
cout<<"D'";
if(r[i][4]==1)
cout<<"D";
cout<<"+";
}
c=0;
}
cout<<endl;
for(i=1;i<c5;i++)
{
if(p[i][1]==0)
cout<<"A'";
if(p[i][1]==1)
cout<<"A";
if(p[i][2]==0)
cout<<"B'";
if(p[i][2]==1)
cout<<"B";
if(p[i][3]==0)
cout<<"C'";
if(p[i][3]==1)
cout<<"C";
if(p[i][4]==0)
cout<<"D'";
if(p[i][4]==1)
cout<<"D";
cout<<"+";
}
// getch ();
}
if (n%2==0) sum=n/2*(n+1); else sum=(n+1)/2*n;
If these expressions are stand-alone (not nested), then they do the same thing, ie increment 'n'.
int n, i; for(n = 1; n <= 5; ++n) { for(i = 1; i <= n; ++i) { printf("%d", n); } }
int total = 0; int n; for( n = 112; n <= 212; ++n) { total += n; } printf("%d\n", total);
/* Bubble sort: code snippet only nos to be sorted are in the array named 'n' of size 'N' for(int i=0;i<N-1;i++) for(int j=i+1;j<N-1-i;j++) if(n[j]>n[j+1]) swap(n[j],n[j+1]); */ /* insertion sort int v,j; for(int i=1;i<N;i++) { v=n[j]; for(int j=i-1;j>0&&n[j]>v;j--) n[j+1]=n[j]; n[j+1]=v; } */
#include<iostream> int main() { std::cout << "*******\n" "*******\n" " *****\n" " ***\n" " *\n" " ***\n" " *****\n" "*******\n" "*******\n"; }
#include<iostream> #include<conio.h> #include<string> int main() { std::cout << "Enter your 10 digit code: "; size_t code=0; size_t len=0; while (len<10) { char c = (char) _getch(); if (c=='0' && !code) // leading zero not permitted! continue; if (c>='0' && c<='9') { ++len; std::cout << c; c -= '0'; code *= 10; code += c; } } std::cout << "\n\nYou entered: " << code << '\n' << std::endl; }
Subscripts have not changed since C++ evolved from C. Given an array x, the subscript x[n] returns a reference to the n-1th element of x. Note that Balaguruswamy is a book writer, he has not released any edition of C++.
Copy and paste this and it will say hello world! #include <iostream> int main() { std: :cout < < "Hello, world!\n ";
#include#includevoid main(){int a[10],i=0,c=0,n;printf("\n enter the gray code");scanf("%d",&n);while(n!=0){a[i]=n%10;n/=10;i++;c++;}for(i=c-1;i>=0;i--){if(a[i]==1){if(a[i-1]==1)a[i-1]=0;elsea[i-1]=1;}}printf("\n the binary code is");for(i=c-1;i>=0;i--)printf("%d",a[i]);getch();}
Here is the code to do it: #include<stdio.h> main() { int n, c, k, space = 1; //Here we ask for the number of rows would be : printf("Enter number of rows\n"); scanf("%d",&n); space = n - 1; //This is the first half of the diamond for ( k = 1 ; k <= n ; k++ ) { for ( c = 1 ; c <= space ; c++ ) printf(" "); space--; for ( c = 1 ; c <= 2*k-1 ; c++) printf("*"); printf("\n"); } space = 1; //Here is the second half of the diamond for ( k = 1 ; k <= n - 1 ; k++ ) { for ( c = 1 ; c <= space; c++) printf(" "); space++; for ( c = 1 ; c <= 2*(n-k)-1 ; c++ ) printf("*"); printf("\n"); } return 0; } Hope that helped :)
#include#includevoid main(){int a[10],i=0,c=0,n;printf("\n enter the gray code");scanf("%d",&n);while(n!=0){a[i]=n%10;n/=10;i++;c++;}for(i=c-1;i>=0;i--){if(a[i]==1){if(a[i-1]==1)a[i-1]=0;elsea[i-1]=1;}}printf("\n the binary code is");for(i=c-1;i>=0;i--)printf("%d",a[i]);getch();}
Did you mean 1-2+3-4+5-6....till n ?? If yes, then here it is: #include<iostream.h> void main() { int n,sum=0,check=1; cout<<"Enter n "; cin>>n; for(int i=1;i<=n;i++) { sum+=(check*i); check*=-1; } cout<<"The result of series is: "<<sum; }
if (n%2==0) sum=n/2*(n+1); else sum=(n+1)/2*n;
If these expressions are stand-alone (not nested), then they do the same thing, ie increment 'n'.
Depending on the setup, this problem can be unsolvable. It belongs to a class of problems known as NP complete, meaning that no easily solvable solution can be provided.
Find the Sum to n terms of the series 5 5+55+555+ +n Terms