Showing posts with label sum. Show all posts
Showing posts with label sum. Show all posts
Wednesday, February 18, 2015
C program to find the sum of series 1 2 4 5 7 8

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
clrscr();
float sum=0,x,a=1;
printf("1/2+4/5+7/8+......");
printf("
How many terms(ex: 1,2,3...n)?");
How many terms(ex: 1,2,3...n)?");
scanf("%d",&n);
for(i=0;i<n;++i)
{
x=a/(a+1);
sum+=x;
a+=3;
}
printf("
Sum=%f",sum);
Sum=%f",sum);
getch();
}
Thursday, February 12, 2015
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
}
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();
}
#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();
}
Subscribe to:
Posts (Atom)