Distance between 2 points.
#include<stdio.h>
#include<math.h>
float findDistance (int x1, int y1, int x2, int y2)
{
return sqrt( ( (x2-x1)*(x2-x1) )+( (y2-y1)*(y2-y1) ) );
}
int main()
{
int x1,y1,x2,y2;
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
printf("Distance between the 2 points is %.2f",findDistance(x1,y1,x2,y2));
return 0;
}
Factorial
#include<stdio.h>
int factorial (int n)
{
if(n>1)
return n*factorial(n-1);
else
return 1;
}
int main()
{
int x;
scanf("%d",&x);
printf("%d",factorial(x));
return 0;
}
Lucky string
#include<stdio.h>
int checkLucky(char *a)
{
int sum=0;
while(*a!='\0')
{
sum+=(int)(*a);
++a;
}
if(sum%2==0)
return 1;
else
return 0;
}
int main()
{
printf("Enter the input string\n");
char str[100];
scanf("%s",str);
int a=checkLucky(str);
if(a)
printf("%s is lucky",str);
else
printf("%s is not lucky",str);
return 0;
}
0 comments :
Post a Comment