Loops

C++ Program to Print Truth Table of XY+Z

Here you will get C++ program to print truth table of XY+Z. #include<iostream> using namespace std; int main() { int x,y,z; cout<<“X\tY\tZ\tXY+Z”; for(x=0;x<=1;++x) for(y=0;y<=1;++y) for(z=0;z<=1;++z) { if(x*y+z==2) cout<<“\n\n”<<x<<“\t”<<y<<“\t”<<z<<“\t1”; else cout<<“\n\n”<<x<<“\t”<<y<<“\t”<<z<<“\t”<<x*y+z; } return 0; }   Output X Y Z XY+Z 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 …

C++ Program to Print Truth Table of XY+Z Read More »

Program to Reverse Number in C

Here you will learn how to reverse number in C. #include<stdio.h> int main() { long n,rev=0,d; printf(“Enter any number:”); scanf(“%ld”,&n); while(n!=0) { d=n%10; rev=(rev*10)+d; n=n/10; } printf(“The reversed number is %ld”,rev); return 0; }   Output Enter any number:16789 The reversed number is 98761

Program to Reverse Number in C++

Here you will get program to reverse number in C++. #include<iostream> using namespace std; int main() { long n,rev=0,d; cout<<“Enter any number:”; cin>>n; while(n!=0) { d=n%10; rev=(rev*10)+d; n=n/10; } cout<<“The reversed number is “<<rev; return 0; }   Output Enter any number:12674 The reversed number is 47621