Back to Home & C
//Program to find sum of n even numbers using user defined functions.
#include<stdio.h>
#include<conio.h>
int sum(int l);
void main()
{
clrscr();
int n,s;
printf("Enter limit value\n");
scanf("%d",&n);
s=sum(n);
printf("Sum of even numbers=%d",s);
getch();
}
int sum(int l)
{
int i,sum=0;
for(i=0;i<l;i++)
{
if(i%2==0)
{
sum=sum+i;
}
}
return(sum);
}
===================================
Output :
Enter limit value
4
Sum of even numbers= 2
=========================================================================
Back to Home & C
//Program to find sum of n even numbers using user defined functions.
#include<stdio.h>
#include<conio.h>
int sum(int l);
void main()
{
clrscr();
int n,s;
printf("Enter limit value\n");
scanf("%d",&n);
s=sum(n);
printf("Sum of even numbers=%d",s);
getch();
}
int sum(int l)
{
int i,sum=0;
for(i=0;i<l;i++)
{
if(i%2==0)
{
sum=sum+i;
}
}
return(sum);
}
===================================
Output :
Enter limit value
4
Sum of even numbers= 2
=========================================================================
Back to Home & C
No comments:
Post a Comment