Write a C program that creates a security access code from a social security number entered by a user as follows: Using a recursive function it adds all of the digits of the social security number and then using a regular function gets the square number of the sum and displays it. The access code displayed should be initialized as an integer number but using type casting is displayed as a floating number.
#include<stdio.h>
#include<math.h>
int add(int n) //recursive function to calculate sum of digits of number
{
if(n==0) return 0; //base condtion
return n%10+add(n/10); //adding digits
}
int Square(int n)
{
return n*n; //return square of number
}
int main()
{
int ssn,sac;
printf("Enter Social Security Number : ");
scanf("%d",&ssn); //ask user to input SSN
int x=add(ssn); //finding sum of digits
sac=Square(x); //finding square of a number
printf("Security Access Code is : %f\n\n",(float)sac); //print float of SAC by using type cast
}
Sample Input/Output Screenshot:
Get Answers For Free
Most questions answered within 1 hours.