C C++ program to convert binary to decimal

 

Flowchart

Binary to decimal conversion flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int binary, decimal=0, digit, base=1;
printf(“Enter binary number: “);
scanf(“%d”,&binary);
while(binary!=0)
{
digit=binary%10;
decimal=digit*base+decimal;
base=base*2;
binary=binary/10;
}
printf(“Decimal number = %d”,decimal);
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int binary, decimal=0, digit, base=1;
cout<<“Enter binary number: “;
cin>>binary;
while(binary!=0)
{
digit=binary%10;
decimal=digit*base+decimal;
base=base*2;
binary=binary/10;
}
cout<<“Decimal number = “<<decimal;
return 0;
}

 

Output

Binary to decimal conversion output

 

Share it to:

C C++ program to convert decimal to binary

 

Flowchart

Decimal to binary conversion flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int decimal, binary=0, digit, base=1;
printf(“Enter decimal number: “);
scanf(“%d”,&decimal);
while(decimal!=0)
{
digit=decimal%2;
binary=digit*base+binary;
base=base*10;
decimal=decimal/2;
}
printf(“Binary number = %d”,binary);
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int decimal, binary=0, digit, base=1;
cout<<“Enter decimal number: “;
cin>>decimal;
while(decimal!=0)
{
digit=decimal%2;
binary=digit*base+binary;
base=base*10;
decimal=decimal/2;
}
cout<<“Binary number = “<<binary;
return 0;
}

 

Output

Decimal to binary conversion output

 

Share it to:

C C++ program to generate series of armstrong numbers

 

Flowchart

Generate series of armstrong numberrs upto n flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int num=1,rem,sum,org,n;
printf(“Enter n: “);
scanf(“%d”,&n);
while(num<=n)
{
org=num;
sum=0;
while(num!=0)
{
rem=num%10;
sum=sum+rem*rem*rem;
num=num/10;
}
if(sum==org)
{
printf(“%d\n”,sum);
}
num=org+1;
}
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int num=1,rem,sum,org,n;
cout<<“Enter n: “;
cin>>n;
while(num<=n)
{
org=num;
sum=0;
while(num!=0)
{
rem=num%10;
sum=sum+rem*rem*rem;
num=num/10;
}
if(sum==org)
{
cout<<sum<<“\n”;
}
num=org+1;
}
return 0;
}

 

Output

Generate series of armstrong numberrs upto n output

 

Share it to:

C C++ program to check armstrong number

 

Flowchart

Check whether given number is armstrong or not flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int num,rem,sum=0,org;
printf(“Enter a number: “);
scanf(“%d”,&num);
org=num;
while(num!=0)
{
rem=num%10;
sum=sum+rem*rem*rem;
num=num/10;
}
if(sum==org)
{
printf(“Armstrong”);
}
else
{
printf(“Not an Armstrong”);
}
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int num,rem,sum=0,org;
cout<<“Enter a number: “;
cin>>num;
org=num;
while(num!=0)
{
rem=num%10;
sum=sum+rem*rem*rem;
num=num/10;
}
if(sum==org)
{
cout<<“Armstrong”;
}
else
{
cout<<“Not an armstrong”;
}
return 0;
}

 

Output

Check whether given number is armstrong or not output

 

Share it to:

C C++ program to check palindrome number

 

Flowchart

Check whether given number is palindrome or not flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int num,rem,rev=0,org;
printf(“Enter a number: “);
scanf(“%d”,&num);
org=num;
while(num!=0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
if(rev==org)
{
printf(“Palindrome”);
}
else
{
printf(“Not a palindrome”);
}
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int num,rem,rev=0,org;
cout<<“Enter a number: “;
cin>>num;
org=num;
while(num!=0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
if(rev==org)
{
cout<<“Palindrome”;
}
else
{
cout<<“Not a palindrome”;
}
return 0;
}

 

Output

Check whether given number is palindrome or not output

 

Share it to:

C C++ program to find reverse of digits of given number

 

Flowchart

Reverse of digits given number flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int num,rem,rev=0;
printf(“Enter a number: “);
scanf(“%d”,&num);
while(num!=0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
printf(“Reverse of digits = %d”,rev);
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int num,rem,rev=0;
cout<<“Enter a number: “;
cin>>num;
while(num!=0)
{
rem=num%10;
rev=rev*10+rem;
num=num/10;
}
cout<<“Reverse of digits = “<<rev;
return 0;
}

 

Output

Reverse of digits given number output

 

Share it to:

C C++ program to find sum of digits of given number

 

Flowchart

Sum of digits of given number flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int num,rem,sum=0;
printf(“Enter a number: “);
scanf(“%d”,&num);
while(num!=0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf(“Sum of digits = %d”,sum);
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int num,rem,sum=0;
cout<<“Enter a number: “;
cin>>num;
while(num!=0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
cout<<“Sum of digits = “<<sum;
return 0;
}

 

Output

Sum of digits of given number output

 

Share it to:

C C++ program to generate series of prime numbers

 

Flowchart

Generating prime numbers upto n flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int num=1, c=2, n;
char prime=’t’;
printf(“Enter n: “);
scanf(“%d”,&n);
while(num<=n)
{
c=2;
prime=’t’;
while(c<num)
{
if(num%c==0)
{
prime=’f’;
break;
}
c++;
}
if(prime==’t’)
{
printf(“%d\n”,num);
}
num++;
}
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int num=1, c=2, n;
char prime=’t’;
cout<<“Enter n: “;
cin>>n;
while(num<=n)
{
c=2;
prime=’t’;
while(c<num)
{
if(num%c==0)
{
prime=’f’;
break;
}
c++;
}
if(prime==’t’)
{
cout<<num<<“\n”;
}
num++;
}
return 0;
}

 

Output

Generating prime numbers upto n output

 

Share it to:

C C++ program to check prime number

 

Flowchart

Checking whether given number is prime or not flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int num, c=2;
char prime=’t’;
printf(“Enter a number: “);
scanf(“%d”,&num);
while(c<num)
{
if(num%c==0)
{
prime=’f’;
break;
}
c++;
}
if(prime==’t’)
{
printf(“Prime number”);
}
else
{
printf(“Not a prime number”);
}
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int num, c=2;
char prime=’t’;
cout<<“Enter a number: “;
cin>>num;
while(c<num)
{
if(num%c==0)
{
prime=’f’;
break;
}
c++;
}
if(prime==’t’)
{
cout<<“Prime number”;
}
else
{
cout<<“Not a prime number”;
}
return 0;
}

 

Output

Checking whether given number is prime or not output

 

Share it to:

Write a C C++ program to generate fibonacci series

 

Flowchart

Fibonacci series upto n flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int a=0,b=1,c=1,n;
printf(“Enter n: “);
scanf(“%d”,&n);
printf(“%d\n”,a);
printf(“%d\n”,b);
while(c<=n)
{
printf(“%d\n”,c);
a=b;
b=c;
c=a+b;
}
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int a=0,b=1,c=1,n;
cout<<“Enter n: “;
cin>>n;
cout<<a<<“\n”;
cout<<b<<“\n”;
while(c<=n)
{
cout<<c<<“\n”;
a=b;
b=c;
c=a+b;
}
return 0;
}

 

Output

Fibonaccy series upto n output

 

Share it to: