RSS

Category Archives: C/C++

No. Pyramid – 4

Output

5 5 5 5 5
4 4 4 4
3 3 3
2 2
1

Program

# include <iostream.h>
# include <conio.h>

void main()
{
int i,j;
for (i=5;i>=1;i–)
{
for(j=1; j<=i;j++)
{
cout<<i<<‘ ‘;
}
cout<<‘\n’;
}

getch();
}

 

 
Leave a comment

Posted by on October 7, 2013 in C/C++

 

No. Pyramid – 3

Output

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Program

# include <iostream.h>
# include <conio.h>

void main()
{
int i,j;
for (i=5;i>=1;i–)
{
for(j=1; j<=i;j++)
{
cout<<j<<‘ ‘;
}
cout<<‘\n’;
}

getch();
}

 

 
Leave a comment

Posted by on October 7, 2013 in C/C++

 

No. Pyramid – 2

Output

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Program

# include <iostream.h>
# include <conio.h>

void main()
{
int i,j;
for (i=1;i<=5;i++)
{
for(j=1; j<=i;j++)
{
cout<<j<<‘ ‘;
}
cout<<‘\n’;
}

getch();
}

 
Leave a comment

Posted by on October 7, 2013 in C/C++

 

No. Pyramid – 1

Output

1
2 2
3 3 3
4 4 4 4
5 5 5 5 5

Program

# include <iostream.h>
# include <conio.h>

void main()
{
int i,j;
for (i=1;i<=5;i++)
{
for(j=1; j<=i;j++)
{
cout<<i<<‘ ‘;
}
cout<<‘\n’;
}

getch();
}

 
Leave a comment

Posted by on October 7, 2013 in C/C++

 

Add Digits

# include <iostream.h>
# include <conio.h>

void main()
{
   int n, sum = 0, remain;

   cout<<"Enter an integer\n";
   cin>>n;

   while(n != 0)
   {
      remain = n % 10;
      sum = sum + remain;
      n = n / 10;
   }

   cout<<"Sum of digits of entered number = "<<sum<<'\n';

   getch();
}
 
Leave a comment

Posted by on October 7, 2013 in C/C++

 

Add 2 Numbers (C++)

# include <iostream.h>
# include <conio.h>

void main()
{
   int a, b, c;

   cout<<"Enter two numbers to add\n";
   cin>>a>>b;

   c = a + b;
   cout<<"Sum of entered numbers = "<<c<<endl;
 
   getch();

}
 
Leave a comment

Posted by on October 7, 2013 in C/C++