Solution with out using functions
Solution with out using functions(Using Conditional operator)
Solution using functions without passing arguments
Solution : Without using function
Program/Source Code
#include <stdio.h>
int main()
{
int age;
char name[20];
printf("Enter name ");
scanf("%s",name);
printf("Enter age ");
scanf("%d",&age);
if(age>=18)
printf("You can vote");
else
printf("You cannot vote");
return 0;
}
Output:
case :1
Enter name Amit
Enter age 15
You cannot vote
case :2
Enter name Sumit
Enter age 21
You can vote
Solution : Without using function(Using Conditional Operator)
Program/Source Code
#include <stdio.h>
int main()
{
int age;
char name[20];
printf("Enter name ");
scanf("%s",name);
printf("Enter age ");
scanf("%d",&age);
(age>=18)?printf("You can vote"):printf("You cannot vote");
return 0;
}
Output:
case :1
Enter name Mohit
Enter age 12
You cannot vote
case :2
Enter name Komal
Enter age 25
You can vote
Solution : Using function Without Passing Arguments
Program/Source Code
#include <stdio.h>
void check()
{
int age;
char name[20];
printf("Enter name ");
scanf("%s",name);
printf("Enter age ");
scanf("%d",&age);
if(age>=18)
printf("You can vote");
else
printf("You cannot vote");
}
int main()
{
check();
return 0;
}
Output:
case :1
Enter name Amita
Enter age 12
You cannot vote
case :2
Enter name Kapil
Enter age 25
You can vote
|
Previous:
Next: |
Tutorials | Technical Questions | Interview Questions |
|---|---|---|
|
C Programming C++ Programming Class 11 (Python) Class 12 (Python) |
C Language C++ Programming Python |
C Interview Questions C++ Interview Questions C Programs C++ Programs |




