The C Program is given below is a program to define a number Odd or Even. When you will run this program then you will be asked to provide a number and you will see Enter the Number You Want to Check: text on the screen. Then if you provide 5 and press Enter Key, you will get 5 is an Odd Number in the result. And if you provide 8, you will get 8 is an Odd Number.
- #include<stdio.h>
- void main()
- {
- int a;
- printf("Enter the Number You Want to Check: ");
- scanf("%d",&a);
- if(a%2==1)
- {
- printf("%d is an Odd Number",a);
- }
- else
- {
- printf("%d is an Even Number",a);
- }
- }
Output for the Above Program
After running the program, you will get a message like...
Enter the Number You Want to Check: _
You may give any number you want to check if Even or Odd. If you provide the number 9 and press the Enter Key, then you will get the following result.
9 is an Odd Number
Description of the above Codes
First Line
In the first line there is written #include<stdio.h>. stdio.h is a Header File. So I have commanded the Computer to include the Header File stdio.h by the codes #include<stdio.h>. conio.h and math.h are also two Header files. If you want to add them then you have to write #include<conio.h> to include conio.h header file and #include<math.h> to add the math.h header file. When you need to add two or more header files in a program then you have to write like...
In the first line there is written #include<stdio.h>. stdio.h is a Header File. So I have commanded the Computer to include the Header File stdio.h by the codes #include<stdio.h>. conio.h and math.h are also two Header files. If you want to add them then you have to write #include<conio.h> to include conio.h header file and #include<math.h> to add the math.h header file. When you need to add two or more header files in a program then you have to write like...
#include<stdio.h>
#include<conio.h>
#include<math.h>
Fourth Line
In the fourth line there is written int a;. Here a is a variable where we will store the number we will provide from keyboard.
Fourth Line
In the fourth line there is written int a;. Here a is a variable where we will store the number we will provide from keyboard.
Second Line
In the Second Line I have written void main(). This is the main part of a C++ Program. You have to keep inside of void main() all of the command you want to use. The structure of void main() is given below.
void main()
{
Commads you want to use
}
Fifth Line
In the fifth line I have written printf("Enter the Number You Want to Check: ");. Here printf is a command included in stdio.h header file. We have used this command to show some text in the output. The structure of printf is printf("Enter the Number You Want to Check: "); That means you have to keep the text inside of the two double quotation (""). The program will show the text you will keep inside the Double Quotation. Though C++ does not support Capital Letter but you may use it here. That means you may write printf("YOUR TEXT"); if you want.
Sixth Line
In the sixth line there is written scanf("%d",&a);. By this line the computer will store the provided integer number in the memory location a.
Sixth Line
In the sixth line there is written scanf("%d",&a);. By this line the computer will store the provided integer number in the memory location a.
No comments:
Post a Comment