Loops

Program for Factorial in C

Here you will get program for factorial in C. We can find factorial of any number by multiplying it with all the numbers below it. For example, factorial of 3 will be 6 (3 * 2 * 1). Program for Factorial in C #include<stdio.h> int main() { long i,n,fac=1; printf(“Enter value of n:”); scanf(“%ld”,&n); for(i=n;i>=1;–i) fac*=i; …

Program for Factorial in C Read More »

C Program to Print First n Natural Numbers and their Sum

Here you will get C program to print first n natural numbers and their sum. #include<stdio.h> int main() { int n,i,sum=0; printf(“Enter the value of n:”); scanf(“%d”,&n); for(i=1;i<=n;++i) { printf(“\n%d”,i); sum+=i; } printf(“\n\nSum of first n natural numbers is:%d”,sum); return 0; }   Output Enter the value of n:7 1 2 3 4 5 6 …

C Program to Print First n Natural Numbers and their Sum Read More »

Prime Number in C++

Here you learn how to check prime number in C++. Prime number is a number which is only divided by 1 or itself. Below is the C++ program to check whether a number is prime of not.   Prime Number in C++ #include<iostream> using namespace std; int main() { int n,i,flag=1; cout<<“Enter any number:”; cin>>n; …

Prime Number in C++ Read More »

Convert Binary to Decimal in C++

Here you will learn how to convert binary to decimal in C++. We can convert a binary number into decimals in the following way. Also Read: Convert Decimal to Binary in C++ C++ Program to Convert Binary to Decimal Output: Enter any Binary number:111The Decimal conversion of 111 is 7

Convert Decimal to Binary in C++

Here you will get the program to convert a number from decimal to binary in C++. How to convert decimal numbers to binary? This program can only convert nondecimal numbers. Also Read: Convert Binary to Decimal in C++ C++ Program to Convert Decimal to Binary Output: Enter a number:5The binary conversion of 5 is 101

C++ Program to Print First 10 Prime Numbers

Here is the C++ program to print first 10 prime numbers. #include<iostream> using namespace std; int main() { int i,j,count=1,b=0; cout<<“First Ten Prime Numbers Are\n”<<“2”; for(i=3;i>0;++i) { for(j=2;j<=i/2;++j) { if(i%j==0){ b=1; break; } } if(b==0) { cout<<“\n”<<i; count++; } b=0; if(count==10) break; } return 0; } Output First Ten Prime Numbers Are 2 3 5 …

C++ Program to Print First 10 Prime Numbers Read More »

C++ Program for Fibonacci Series

A series in which each number is the sum of the preceding two numbers is called the Fibonacci series. For example 0 1 1 2 3 5 8 13 . . . . . Below is the program to find Fibonacci series in C++. Output: How many numbers?5Fibonacci series0 1 1 2 3