Friday, February 19, 2010

C Program To Find Largest Number In An Array Using Function

/* C Program To Find Largest Number In An Array Using Function */

#include< stdio.h>
void main()
{
int i,n,a[5],max,min;
clrscr();
printf("enter the limit\n");
scanf("%d",&n);
printf("enter the array element \n");
for(i=0;i{
scanf("%d",&a[i]) ;
}
mn(a,n,max,min);
getch();
}


int mn(int *a,int n,int max,int min)
{
int i;
min=max=a[0];
for(i=1;i<=n;i++)
{
if(a[i]>max)
{
max=a[i];
}
if(a[i] {
min=a[i];
}
}
printf("maximum=%d",max);
printf("minimum=%d",min);
return 0;
}

Tuesday, February 16, 2010

C Program to Convert A String From Lower TO Upper Letters And Vice-Versa

/* C Program to Convert A String From Lower TO Upper Letters And Vice-Versa */

#include< stdio.h>
#include< ctype.h>
#include< conio.h>
void upper(char instr[])
{
int i=0;
while(instr[i])
{
instr[i]=toupper(instr[i]);
i++;
}
}

void lower(char instr[])
{
int i=0;
while(instr[i])
{
instr[i]=tolower(instr[i]);
i++;
}
}

void main()
{
char instr[100],inchar;
clrscr();
printf("input the string\n");
gets(instr);
printf("To upper-or-lower case(u/l)?\n");
scanf("%c",&inchar);

switch(inchar)
{
case 'u':
case 'U':
upper(instr);
break;
case 'l':
case 'L':
lower(instr);
break;
default:
printf("invalid");

}

printf("the converted string is...\n");
printf("%s\n",instr);
getch();
}

Wednesday, February 10, 2010

C Program To Find Sum Of Two Integer Numbers

/* C Program to find sum of two integer numbers */

# include< stdio.h>
# include< conio.h>
void main()
{
int a,b,sum;
clrscr();
printf("enter the number\n");
scanf("%d%d",&a,&b);
sum=a+b;
printf("SUM=%d",sum);
getch();
}

C Program To Find Simple Interest

/* C Program to find Simple Interest */
#include< stdio.h>
#include< conio.h>
void main()
{
float p,t,r,si;
clrscr();
printf("Enter the value for principle_amt,time,rate\n");
scanf("%f%f%f",&p,&t,&r);
si=p*t*r/100;
printf("Simple Interest=%f",si);
getch();
}

Sunday, February 7, 2010

Sample C Program

/* Sample C Program */

#include< stdio.h> // Preprocessor Directive
main() // Main Starts from Here
{
clrscr(); //Clear screen
printf("WELCOME TO C"); // Print Statement
}