//Program to find sum of n natural numbers
#include<iostream>
using namespace std;
int main()
{
int n,sum;
cout<<"\n enter a natual number:";
cin>>n;
sum=n*(n+1)/2;
cout<<"\n sum of "<<n<<" natural numbers is : "<<sum<<endl;
return 0;
}
04 August 2018
C/C++ Program to find sum of n natural numbers
C/C++ Program to print hello world
//Program to print hello world
#include<iostream>
using namespace std;
int main()
{
cout<<"\n HELLO! WORLD"<<endl;
return 0;
}
C/C++ Program to find FACTORS of a given number
//Program to find FACTORS of a given number
#include<iostream>
using namespace std;
int main()
{
int a;
cout<<"\n enter a positive number to find factors:";
cin>>a;
cout<<"\n Factors of "<<a<<endl;
for(int i=1;i<=a;i++)
{
if(a%i==0)
cout<<i<<" ";
}
cout<<endl;
return 0;
}
C/C++ Program to find a given number is STRONG (or) not.
//Program to find a given number is STRONG or not.
#include<iostream>
using namespace std;
int main()
{
int a;
cout<<"\n enter a number:";
cin>>a;
int i,f,r,sum=0,num;
num=a;
while(num>0)
{
i=1;f=1;
r=num%10;
while(i<=r)
{
f=f*i;
i++;
}
sum=sum+f;
num=num/10;
}
if(sum==a)
cout<<" Yes, "<<a<<" is a strong number."<<endl;
else
cout<<"No, "<<a<<"is not a strong number "<<endl;
return 0;
}
C/C++ Program to find sum of digits of a given number
//Program to find sum of digits of a given number
#include<iostream>
using namespace std;
int main()
{
int a,r,num,sum=0;
cout<<"\n enter a number:";
cin>>a;
if(a<0)
num=-a;
else
num=a;
while(num>0)
{
r=num%10;
sum=sum+r;
num=num/10;
}
if(a<0)
cout<<"\n sum of digits= -"<<sum<<endl;
else
cout<<"\n sum of digits="<<sum<<endl;
return 0;
}
C/C++ Program to find prime number between 1 and n
//Program to find prime number between 1 and n
#include<iostream>
using namespace std;
int main()
{
int n,m,i=2,is_prime=1;
cout<<"enter up to which number you want to find prime numbers:";
cin>>m;
for(n=2;n<=m;n++)
{
for(i=2;i<n;i++)
{
if(n%i==0)
{
is_prime=0;
break;
}
else
is_prime=1;
}
if(is_prime)
cout<<n<<" ";
}
cout<<endl;
return 0;
}
Similar program(s):
C++ Program to find a given number is Prime (or) not.
C++ Program to find a given number is even (or) odd.
02 August 2018
C/C++ Program to find a given number is even (or) odd.
// Program to find a given number is even (or) odd.
#include<iostream>
using namespace std;
int main()
{
int n,i,is_even=0;
cout<<"\n enter a number"<<endl;
cin>>n;
for(i=2;i<n;i++)
{
if(n%2==0)
is_even=1;
}
if(is_even)
cout<<n<<" is an even"<<endl;
else
cout<<n<<" is an odd"<<endl;
return 0;
}
Subscribe to:
Posts (Atom)
To convert from Upper case to lowercase(A to a)
//converting from Upper to lower(A to a) import java.util.*; class case { public static void main(String args[]) { System.out.pr...
-
//Program to calculate area of circle using SWITCH statement import java.util.*; class switch1 { public static void main(String a...
-
Perfect number : is a positive integers which is equal to the sum of its proper positive divisors, that is, the sum of its positive...
-
//Program to calculate area of circle using if-else statement import java.util.*; class areaofc { public static void main(String ...