Showing posts with label numbers. Show all posts
Showing posts with label numbers. Show all posts

Friday, February 13, 2015

C Program to find Greatest number among three numbers

#include<iostream.h>
#include<conio.h>

void main()
{
int x,y,z,max;
clrscr();
cout<<"Enter The Three Numbers ";
cin>>x>>y>>z;

max=x;
if (y>max)
max=y;
if (z>max)
max=z;

cout<<"
"<<"The Greatest Number among "<<x<<" "<<y<<" "<<z<<" is "<<max;

getch();
}

Read more »

Thursday, February 12, 2015

C Program to print first 10 Prime numbers


#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int i,j,count=1,b=0;

cout<<"First Ten Prime Numbers Are

"<<"2";
for(i=3;i>0;++i)
{
for(j=2;j<=i;++j)
{
if(i%j==0)
b=1;
break;
}
if(b==0)
{
cout<<"
"<<i;
count++;

}
b=0;
if(count==10)
break;
}
getch();
}
Read more »

C Program to find quotient and remainder of two numbers


#include<iostream.h>
#include<conio.h>


void main()
{
clrscr();
int a,b,q,r;
cout<<"Enter two numbers:";
cin>>a>>b;


if(a>b)
{
q=a/b;
r=a%b;
cout<<"
Quotient="<<q;

cout<<"
Remainder="<<r;

}
else
cout<<"
First no. should be greater than second no....!!!";



getch();
}

Read more »

C Program to calculate sum and average of three numbers


#include<iostream.h>
#include<conio.h>


void main()
{
clrscr() //to clear the screen
float a,b,c,sum,av;
cout<<"Enter three numbers:";
cin>>a>>b>>c;


sum=a+b+c;
av=sum/3;
cout<<"
SUM="<<sum;

cout<<"
Average="<<av;



getch(); //to stop the screen
}
Read more »

Wednesday, February 11, 2015

C Program to calculate and print the sum of even and odd integers of the first n natural numbers

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int n,i,sumeven=0,sumodd=0;
cout<<"Enter value of n:";
cin>>n;

for(i=1;i<=n;++i)
{
if(i%2==0)
sumeven+=i;
else
sumodd+=i;
}
cout<<"
Sum of even Numbers is "<<sumeven;

cout<<"
SUm of odd Numbers is "<<sumodd; 

getch();
}
Read more »