Friday, 21 April 2017

Functions and Pointers /Session VI

1.Functions – Lucky String


Write a program to find whether the given string is Lucky or not.

A string is said to be lucky if the sum of the ascii values of the characters in the string is even.


Function specifications:

int checkLucky(char * a)
The function accepts a pointer to a string and returns an int.
The return value is 1 if the string is lucky and 0 otherwise.

Input and Output Format:
Input consists of a string. Assume that all characters in the string are lowercase letters and the maximum length of the string is 100.
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.

Sample Input and Output 1:
Enter the input string
anitha
anitha is not lucky

Sample Input and Output 2:
Enter the input string
technology
technology is lucky


code: 



these the best code u can get ....yet it wont show perfect output if any one got better code with perfect output plz share n comments...


2.Factorial of a number


Write a program to find the factorial of a number using functions.

Function Specification:

int factorial(int n)
The function accepts a int and returns an int.

Input Format:
Input consists of 1 integer.

Output Format:
Output consists of a single integer. Refer sample output for formatting details.



code:





3.Distance between 2 points

Write a program to find the distance between 2 points using functions.

Function specification:

float findDistance(int x1, int y1, int x2, int y2)
The function accepts 4 integer and returns a float.

Input Format:
Input consists of 4 integers. The first and second integer corresponds to the x-coordinate and y-coordinate of the first point. The third and fourth integer corresponds to the x-coordinate and y-coordinate of the second point.

Output Format:
Output consists of a single floating point number (correct to 2 decimal places.) Refer sample output for formatting details.


code:




thankyou .....

No comments:

Post a Comment