Program:
Add two numbers, values enter at run time:
#include<stdio.h>
1. The lines between the/*.................*/are remarks which are composed for the software engineer they are not assembled.
1. If Statement
2. Switch
1. If Statement:
The general sentence structure of then if proclamation is given underneath.
Sentence structure:
on the off chance that (articulation)
{
Expression;
}
2. Switch Statement:
The default explanation is executed if no matches are found. The default is discretionary, and on the off chance that it not present, no activity happens if all matches come up short.
Syntax:
switch(expression)
#include<stdio.h>
#include<conio.h>
/*main program began structure here*/
void main()
void main()
{
int
n1, n2, sum;
clrscr();
printf("Enter
the two numbers ");
scanf("%d
%d", &n1, &n2);
sum=n1+n2;
printf("Addition
of %d and %d is %d\n", n1,n2,sum);
getch();
}
Output:
Enter the two number qualities to be included 10
Enter the two number qualities to be included 10
10
Expansion of 10 and 10 is 20.
Clarification:
Coming up next is the bit by bit program portrayal:
Expansion of 10 and 10 is 20.
Clarification:
Coming up next is the bit by bit program portrayal:
1. The lines between the/*.................*/are remarks which are composed for the software engineer they are not assembled.
2. C program begins with #include<stdio.h>: this line incorporates the
"Standard I/O Library" into the program. The standard I/O library
lets to peruse contribution from the console called "standard in",
compose yield to the screen called "standard out", process content
documents put away on the circle, etc. It is an incredibly valuable library. C
has an enormous number of standard libraries like conio, string, time and math
libraries.
3. The line void primary() pronounces the principle work. Each C program must
have a capacity named primary some place in the code. At run time, program
execution begins at the primary line of the principle work.
4. In C, the '{' and '}' images mark the start and end of a square of
code.
5. The variable instatement is done in the configuration information type
var_name like int n1 where int is information type and n1 is variable
name.
6. 'scanf()' takes the contribution from the end client.
7. The printf() explanation in C permits to send output on the brief.
C has different types of statements that license the execution of
a solitary articulation, or a square of explanations, in light of the
assessment of a test articulation or grant the choice of the announcement to be
executed among a few explanations dependent on the estimation of an
articulation or a control variable.
Contingent stretching and determination articulations incorporate develops
like: 1. If Statement
2. Switch
1. If Statement:
The general sentence structure of then if proclamation is given underneath.
Sentence structure:
on the off chance that (articulation)
{
Expression;
}
Program : To check the number as even or odd utilizing if-else
proclamation.
#include<stdio.h>
void main()
{
int n;
clrscr();
printf("Enter any number");
scanf("%d"' &n);
if(n%2==0)
printf("%d number is even number",n);
else
printf("%d is an odd number",n);
getch();
}
Output:
Enter any number 10
10 number is much number
{
int n;
clrscr();
printf("Enter any number");
scanf("%d"' &n);
if(n%2==0)
printf("%d number is even number",n);
else
printf("%d is an odd number",n);
getch();
}
Output:
Enter any number 10
10 number is much number
2. Switch Statement:
C has a built-in multiple-branch selection statement, called switch, which
progressively tests the estimation of an articulation against a rundown of
number or character constants. At the point when a match is discovered, the
announcements related with that consistent are executed until break or end of
switch is experienced.
Break proclamation interferes with the typical progression of control and
afterward moves as far as possible of the code or continues to the ordinary
execution. This is another type of the multi-way choice.
The default explanation is executed if no matches are found. The default is discretionary, and on the off chance that it not present, no activity happens if all matches come up short.
Syntax:
switch(expression)
{
case constant1:
case constant1:
statement sequence
break;
case constant2:
statement sequence
break;
case constant3:
statement sequence
break;
.
.
.
.
default
statement sequence
}
Some other links:
No comments:
Post a Comment