Monday, August 16, 2010

TO SORT A SET OF NUMBERS IN ASCENDING ORDER

0 comments
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],l,i,j,k;
printf("Enter the limit:");
scanf("%d",&l);
for(i=0;i<l;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<l;i++)
{
for(j=0;j<l;j++)
if(a[i]<a[j])
{
k=a[i];
a[i]=a[j];
a[j]=k;
}
}
for(i=0;i<l;i++)
printf("%d",a[i]);
getch();
}
Continue reading →

SUM AND AVERAGE OF EVEN NUMBERS WITHIN THE LIMIT

0 comments
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,lower,upper,sum=0,count=0,temp;
float average;
clrscr();
printf("Enter the lower limit: ");
scanf("%d",&lower);
printf("Enter the upper limit: ");
scanf("%d",&upper); 
if(lower>upper)
{
temp=lower;
lower=upper;
upper=temp;
}
for(i=lower+1;i<upper;i++)
{
if(i%2==0)
{
sum=sum+i;
count++;
}
}
average=sum/count;
printf(" Sum of even numbers between %d and %d is=%d ",lower,upper,sum);
printf(" Average is=%f",average);
getch();
}
Continue reading →

TO CHECK GIVEN STRING IS PALINDROME OR NOT

0 comments
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[100];
int a,b,c=0,i,j,l;
printf("Enter your string:");
gets(str);
l=strlen(str);
j=l-1;
for(i=0;i<j/2;i++,j--)
{
if(str[i]==str[j])
{
c=1;
}
}
if(c==1)
printf("The string is palindrome");
else
printf("The string is not palindrome");
getch();
}
Continue reading →