Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Showing posts with label C-Functions. Show all posts
Showing posts with label C-Functions. Show all posts

Saturday, February 19, 2011

C30 : Sum of n even numbers using user defined functions

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

C29 : Add two numbers(Using user defined functions)

Back to Home   &  C


//Program to add two numbers using user defined functions.

#include<stdio.h>
#include<conio.h>
add();
void main()
{
clrscr();
getch();
}
int add()
{
int a,b,c;
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
c=a+b;
printf("addition=%d",c);
return(0);
}
-----------------------------------------------------------
Output
Enter 2 numbers
12
12
Addition=24
===============================================
Back to Home   &  C


C28 : Display a string(Using user defined functions)

Back to Home   &  C


//Program to display a string using user defined functions.


#include<stdio.h>
#include<conio.h>
display();
void main()
{
clrscr();
getch();
}
int display()
{
printf("Welcome");
return(0);
}
---------------------------------------------------------
Output
Welcome
===============================================
Back to Home   &  C

C27 : Manipulate strings(using string library functions)

Back to Home   &  C


//Program to manipulate string using library functions.

#include<stdio.h>
#include<conio.h>
void main()
{
char s1[20];
char s2[20];
int l;
clrscr();
printf("Enter two strings\n");
scanf("%s%s",s1,s2);
l=strlen(l);
printf("Length of string=%d\n",l);
strcat(s1,s2);
printf("Combined string=%s",s1);
getch();
}
---------------------------------------------------------------
Output
Enter two strings
Welcome
C
Length of the string=7
Combined string=Welcome C
===============================================

//Error in output
Back to Home   &  C