0% found this document useful (0 votes)
32 views15 pages

Programme To Print The Table of A Number: #Include Using Namespace STD Int Main

The document contains 7 code snippets showing C++ programs for: 1) Printing the multiplication table of a number 2) Reversing a given number 3) Checking if a number is an Armstrong number 4) Checking if a number is positive, negative, or zero 5) Swapping the values of two variables 6) Printing the multiplication table of a number 7) Finding the greatest of three numbers Each code snippet includes the code, sample input and output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views15 pages

Programme To Print The Table of A Number: #Include Using Namespace STD Int Main

The document contains 7 code snippets showing C++ programs for: 1) Printing the multiplication table of a number 2) Reversing a given number 3) Checking if a number is an Armstrong number 4) Checking if a number is positive, negative, or zero 5) Swapping the values of two variables 6) Printing the multiplication table of a number 7) Finding the greatest of three numbers Each code snippet includes the code, sample input and output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

1.

Programme to print the table of a number


#include<iostream>

using namespace std;

int main( )

int i,no,table=1;

cout<<"Enter any num : ";

cin>>no;

cout<<"Table of "<<no;

for(i=1;i<=10;i++)

table=no*i;

cout<<" \n"<<table;

cout<<"\n";

1
Sample programe:-

Output:-

2
2. Programme to show the reverse of a given number
#include <iostream>

using namespace std;

int main()

int n, reverse=0, rem;

cout<<"Enter a number: ";

cin>>n;

while(n!=0)

3
rem=n%10;

reverse=reverse*10+rem;

n/=10;

cout<<"Reversed Number: "<<reverse<<endl;

return 0;

Sample Programme:-

4
Output:-

3. Programme to show the no inputed is Armstrong number


#include<iostream>

using namespace std;

int main()

int n,r,sum=0,temp;

printf("enter the number=");

5
scanf("%d",&n);

temp=n;

while(n>0)

r=n%10;

sum=sum+(r*r*r);

n=n/10;

if(temp==sum)

printf("armstrong number ");

else

printf("not armstrong number");

return 0;

Sample programme:-

6
Output:-

4. Programme to display the number is positive or negative

7
#include<iostream>

using namespace std;

int main()

int number;

cout<<"Enter a number : ";

cin>>number;

if(number>0)

cout<<"Number is Positive";

else if(number<0)

cout<<"Number is Negative";

else

cout<<"Number is Zero";

8
Sample programme:-

Output:-

9
5. Programme to swap values of A & B
1. #include<iostream>

2. using namespace std;

3.

4. void swap(int &a, int &b)

5. {

6. b = a + b;

7. a = b - a;

8. b = b - a;

9. }

10.

11. int main()

12. {

13. int a, b;

14.

15. cout << "Enter two numbers to be swapped : ";

16. cin >> a >> b;

17. swap(a, b);

18. cout << "The two numbers after swapping become :" << endl;

19. cout << "Value of a : " << a << endl;

10
20. cout << "Value of b : " << b << endl;

Sample programme:-

Sample output:-

11
6.Programme to print the multiplication table
/* C++ Program - Print Table of Number */

#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int num, i, tab;

cout<<"Enter a number : ";

cin>>num;

cout<<"Table of "<<num<<" is \n\n";

for(i=1; i<=10; i++)

tab=num*i;

cout<<num<<" * "<<i<<" = "<<tab<<"\n";

getch();

12
Sample programme:-

Sample output:-

13
7.Programme tocheck the greatest among three
#include<iostream.h>

#include<conio.h>

void main()

clrscr();

int a, b, c, big;

cout<<"Enter three numbers : ";

cin>>a>>b>>c;

//let a is the biggest

big=a;

if(big<b)

if(b>c)

big=b;

else

big=c;

14
}

else if(big<c)

if(c>b)

big=c;

else

big=b;

else

big=a;

cout<<"Biggest number is "<<big;

getch();

15

You might also like