Loops

Convert Decimal to Binary in C

Here you will get program to convert decimal to binary in C. We can convert a decimal number into binary by repeatedly dividing it by 2 and storing the remainder somewhere. Now display the remainders in reverse order. Also Read: Convert Binary to Decimal in C Convert Decimal to Binary in C #include<stdio.h> int main() { …

Convert Decimal to Binary in C Read More »

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

C program to find largest number of a list of numbers entered through keyboard

#include<stdio.h> #include<conio.h> void main() { int i,n,x,large=0; clrscr(); //to clear the screen printf(“How many numbers?”); scanf(“%d”,&n); for(i=0;i<n;++i) { printf(“nEnter number %d:”,i+1); scanf(“%d”,&x); if(x>large) large=x; } printf(“nnThe largest number is %d”,large); getch(); //to stop the screen }