algorithm to find the age of a person whether he is eligible to vote or not if is eligible then ok else not
Answers
Answer:
import java.util.*;
public class Code
{
public static void main (String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter your age");
int a = sc.nextInt();
if(a>=18)
{
System.out.println("Your age = "+a);
System.out.println("You are eligible to vote");
}
else
{
System.out.println("You are not eligible to vote");
}
}
}
Answer:
I write or solve this algorithm in C programming language.
Method 1 :)
#include<stdio.h>
int main ()
{
int age;
printf ("Tell your age please:");
scanf ("%d", &age);
if (age>=18)
printf ("Ok");
else
printf ("Not");
}
Method 2 :)
#include<stdio.h>
int main ()
{
int age;
printf ("Tell your age please:");
scanf ("%d", &age);
(age>=18) ? printf ("Ok") : printf ("Not");
}
Explanation:
Here, we are using two method. The name of the first method is if else statement method in C language. The name name of the second method is ternary operator method in C language.
According to my knowledge you should use the second method of Algorithm which is is related to the concept of ternary operator. It is easier to first method. It takes less time to program.
Learn more from this link:
https://brainly.in/question/7926553