Debug - Original C++
Debug - Original C++
Debug - Original C++
1.Odd Or Even
#include<iostream.h>
#include<conio.h>
void main()
int no;
clrscr();
cin>>no;
if(no%2==0)
cout<<"Even num";
else
cout<<"Odd num";
getch();
#include<iostream.h>
#include<conio.h>
void main()
int i,no;
clrscr();
cin>>no;
if(no==1)
for(i=2;i<no;i++)
if(no%i==0)
break;
if(no==i)
{
cout<<"Prime num";
getch();
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
cin>>no;
for(i=1;i<=no;i++)
fact=fact*i;
cout<<"Factorial: "<<fact;
getch();
#include<conio.h>
void main()
int no,rev=0,r,a;
clrscr();
cin>>no;
a=no;
while(no>0)
r=no%10;
rev=rev*10+r;
no=no/10;
getch();
#include<iostream.h>
#include<conio.h>
void main()
int i,j,len,flag=1;
char a[20];
cout<<"Enter a string:";
cin>>a;
for(len=0;a[len]!='\0';++len);
for(i=0,j=len-1;i<len/2;++i,--j)
if(a[j]!=a[i])
flag=0;
if(flag==1)
cout<<"\nString is Palindrome";
}
else
getch();
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
int num,ans;
clrscr();
cin>>num;
ans=pow(num,0.5);
getch();
7.Operator Overloading
#include<iostream.h>
#include<conio.h>
class temp
private:
int count;
public:
temp():count(10)
{}
count=count+1;
void Display()
cout<<"Count: "<<count;
};
void main()
{
clrscr();
temp t;
t.Display();
getch();
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
char ch;
cin>>ch;
ch=ch+32;
getch();
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
cin >> N;
cin>>num;
getch();
#include<iostream.h>
#include<conio.h>
void main()
int y;
cin>>y;
if(y%4==0)
cout<<"Leap Year";
else
getch();
#include<iostream.h>
#include<conio.h>
void main()
int x[3][3],y[3][3],z[3][3],i,j;
clrscr();
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>x[i][j];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>y[i][j];
cout<<"MATRIX [X]";
for(i=0;i<3;i++)
cout<<"\n\n";
for(j=0;j<3;j++)
cout<<x[i][j];
cout<<"\nMATRIX [Y]";
for(i=0;i<3;i++)
{
cout<<"\n\n";
for(j=0;j<3;j++)
cout<<y[i][j];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
z[i][j]=x[i][j]+y[i][j];
cout<<"\nMATRIX [Z]";
for(i=0;i<3;i++)
cout<<"\n\n";
for(j=0;j<3;j++)
cout<<z[i][j];
getch();
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
cin>>cel;
getch();
#include<stdio.h>
#include<conio.h>
void main()
int sum = 0;
clrscr();
cout<<"\nEnter the number of Rows : ";
cin>>row;
cin>>col;
cin>>matrix[i][j];
if (i == j)
sum = sum + matrix[i][j];
getch();
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
cin>>mat1[i][j];
}
cin>>mat2[i][j];
sum=0;
mat3[i][j] = sum;
}
}
cout<<mat3[i][j]<<" ";
cout<<"\n";
getch();
15.Reverse an Array
#include<iostream.h>
#include<conio.h>
void main()
int a[20],b[20],i,j,n;
clrscr();
cin>>n;
cout<<"Enter any "<<n<<" elements in Array: ";
cin>>a[i];
for(i=n-1,j=0; i>=0;i--,j++)
b[i]=a[j];
cout<<b[i];
getch();
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cin>>bin_number;
while(bin_number!=0)
rem=bin_number%10;
dec_number=dec_number+rem*i;
i=i*2;
bin_number=bin_number/10;
getch();
#include<iostream.h>
#include<conio.h>
void main()
int i,j,k;
clrscr();
cout<<" ";
cout<<"*";
cout<<"\n";
getch();
#include<iostream.h>
#include<conio.h>
void main()
for(i=1;i<=5;i++)
for(j=1;j<i;j++)
cout<<k;
k++
cout<<"\n";
getch();
#include<iostream.h>
#include<conio.h>
void main()
int i,n,sum=0;
clrscr();
n=10;
for(i=1;i<=n;i++)
{
sum+=i;
cout<<"Sum: "<<sum;
getch();
#include<iostream.h>
#include<conio.h>
void main()
cin>>rows;
cout<<endl;
getch();