C C++ program to convert binary to decimal

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

C और C++ दोनों भाषाओं में महत्वपूर्ण अंतर क्या है जानने के लिए देखें—C vs C++

Procedure Oriented Programming (POP) और Object Oriented Programming (OOP) में अंतर जानने के लिए देखें—POP vs OOP

C program to convert binary to decimal

#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;
}

C++ program to convert binary to decimal

#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 of C C++ program to convert binary to decimal

Enter binary number: 110100
Decimal number = 52
Enter binary number: 1001110
Decimal number = 78

Share it to:

C C++ program to convert decimal to binary

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

Procedure Oriented Programming (POP) और Object Oriented Programming (OOP) में अंतर जानने के लिए देखें—POP vs OOP

C program to convert decimal to binary

#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;
}

C++ program to convert decimal to binary

#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 of C C++ program to convert decimal to binary

Enter decimal number: 52
Binary number = 110100
Enter decimal number: 78
Binary number = 1001110

Share it to:

C C++ program to generate series of Armstrong numbers

C Language के बारे में अधिक जानने के लिए देखें—Brief Introduction of C

C और C++ दोनों भाषाओं में महत्वपूर्ण अंतर क्या है जानने के लिए देखें—C vs C++

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

C program to generate series of Armstrong numbers

#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;
}

C++ program to generate series of Armstrong numbers

#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;
}

Enter n: 200
1
153
Enter n: 500
1
153
370
371
407

Share it to:

C C++ program to check Armstrong number

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

Procedure Oriented Programming (POP) और Object Oriented Programming (OOP) में अंतर जानने के लिए देखें—POP vs OOP

Object Oriented Programming (OOP) की विभिन्न अवधारणाओं को जानने के लिए देखें—Concepts of OOP

C program to check Armstrong number

#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;
}

C++ program to check Armstrong number

#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 of C C++ program to check Armstrong number

Enter a number: 153
Armstrong
Enter a number: 121
Not an armstrong

Share it to:

C C++ program to check palindrome number

Switch statement और multibranching statements के बारे में अधिक जानने के लिए देखें—Switch statements in C

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

Unconditional branching statements के बारे में अधिक जानकारी के लिए देखें— Break, Continue and Goto in C

C program to check palindrome number

#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;
}

C++ program to check palindrome number

#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 of C C++ program to check palindrome number

Enter a number: 5665
Palindrome
Enter a number: 6438
Not a palindrome

Share it to:

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

C++ Language के बारे में अधिक जानने के लिए देखें—Brief Introduction of C++

Procedure Oriented Programming (POP) और Object Oriented Programming (OOP) में अंतर जानने के लिए देखें—POP vs OOP

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

C program to find reverse of digits of given number

#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;
}

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

#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 of C C++ program to find reverse of digits of given number

Enter a number: 639
Reverse of digits = 936
Enter a number: 1234
Reverse of digits = 4321

Share it to:

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

C Language में उपलब्ध Operators और इनके विभिन्न प्रकारो को जानने के लिए देखें—Operators in C

C-Language में Operator Precedence और Associativity Rule क्या होता है जानने के लिए देखें— Precedence and Associativity in C

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

C program to find sum of digits of given number

#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;
}

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

#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 of C C++ program to find sum of digits of given number

Enter a number: 472
Sum of digits = 13
Enter a number: 281
Sum of digits = 11

Share it to:

C C++ program to generate series of prime numbers

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

C Language में character set क्या होता है जानने के लिए देखें—Character set of C

C Language में Token क्या होता है जानने के लिए देखें—Tokens in C

C program to generate series of prime numbers

#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;
}

C++ program to generate series of prime numbers

#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;
}

Enter n: 10
1
2
3
5
7
Enter n: 20
1
2
3
5
7
11
13
17
19

Share it to:

Write a C C++ program to check entered number is prime or not

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

Unconditional branching statements के बारे में अधिक जानकारी के लिए देखें— Break, Continue and Goto in C

C program to check entered number is prime or not

#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;
}

C++ program to check entered number is prime or not

#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 of C C++ program to check entered number is prime or not

Enter a number: 5
Prime number
Enter a number: 10
Not a prime number

Share it to:

Write a C C++ program to generate Fibonacci series

C के विभिन्न control statements को जानने के लिए देखें— Control statements in C

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

C program to generate Fibonacci series

#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;
}

C++ program to generate Fibonacci series

#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;
}

Enter n: 10
0
1
1
2
3
5
8
Enter n: 30
0
1
1
2
3
5
8
13
21

Share it to: