A simple c program based on eligibility criteria of voting. | Using if and else if conditions.

avatar

Process to create this program.

c-pogramming-language-of-2019_tiobe.jpg
src

First we define a hedra file, always define a header file to store the source code.

#include <stdio.h>

After that I define main function which is starting point of any c code,

int main()

Then define a variable"a" so that we can take age, this is an integer variable in which we can only enter the value of counting, Whatever we define Integer variable only we can store only Integer value and we had to store only age then we defined Integer variable only.

int a;

we took it so that we can To take input from the user, I can take his age and find out whether he is eligible to vote or not, now to take input from the user,"Enter the age" is printed with "printf".

printf("Enter your age:\n");

Now "scanf" function to take input from the user takes In which gives the variable and its address ("%d", &a) and takes input from the user in which the person enters his age,

scanf("%d", &a);

now after that apply the condition "if and else if" which is the basic format of this. In this condition we print these a in the condition if a is less than 18 then you can vote in the condition put the value of a in itx>= 18 and if that condition is true then you can vote is printed.

if (/* condition /)
{
/
code */
}

and else if condition format is, And if above condition is false then you can't vote gets printed.

else if (/* condition /)
{
/
code */
}

This is the full code.

#include <stdio.h>
int main()
{
int a;
printf("Enter your age:\n");
scanf("%d", &a);
if (a >= 18)
{
printf("You can vote!");
}
else if (a < 18)
{
printf("You can't vote!");
}
return 0;
}

Here are Link of full program with complier You can try it and it will help you also to learn something.
if you like it then upvote and reblog it.

Thanks for supporting this post......

Posted with STEMGeeks



0
0
0.000
3 comments
avatar

That is a really good explanation of the program man! I would just like to note that header files (.h) contain functions and macros. The source code goes in a .c file :)

0
0
0.000