Now we shall write a program who add two numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter the first number:");
scanf("%d",&a);
printf("Enter the second number:");
scanf("%d"&b);
c=a+b;
printf("The sum of two numbers is %d",c);
getch();
}
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter the first number:");
scanf("%d",&a);
printf("Enter the second number:");
scanf("%d"&b);
c=a+b;
printf("The sum of two numbers is %d",c);
getch();
}
Output:
Enter the first number:5
Enter the second number:6
The sum of two numbers is 11
Enter the first number:5
Enter the second number:6
The sum of two numbers is 11
Note:
1.Here 'int' enables integer no. For programming 'the sum of two numbers' we need three numbers.In this program we enter two numbers which is a and b.Both numbers are integer. Thus sum is also integer.Hence c which is the sum of a and b is also taken as integer.
1.Here 'int' enables integer no. For programming 'the sum of two numbers' we need three numbers.In this program we enter two numbers which is a and b.Both numbers are integer. Thus sum is also integer.Hence c which is the sum of a and b is also taken as integer.
2.We asume the three numbers any thing,like:
int a,b,sum;
int first,second,sum;
3.'scanf line' enables the computer to accept any value and '%d' for integer value and &a for value of 'a'.
4.After the entering of the value of 'a' the line:
Enter the second number:
occurs on the computer screen.
Similarly after the entering of second no. means value of 'b' the line:
Sum of two numbers is 11
occurs on computer screen.
Enter the second number:
occurs on the computer screen.
Similarly after the entering of second no. means value of 'b' the line:
Sum of two numbers is 11
occurs on computer screen.
Now care fully read the following programming.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sum;
printf("Enter both the numbers:");
scanf("%d%d",&a,&b);
sum=a+b;
printf("Sum=%d",sum);
getch();
}
#include<conio.h>
void main()
{
int a,b,sum;
printf("Enter both the numbers:");
scanf("%d%d",&a,&b);
sum=a+b;
printf("Sum=%d",sum);
getch();
}
Output:
Enter both the numbers:4 5
Sum=9
-----------------------------------------------
Must see:-
Enter both the numbers:4 5
Sum=9
-----------------------------------------------
Must see:-
#include<conio.h>
#include<stdio.h>
void main()
{
int a=5;
printf("Entered no. is a");
printf("\nEntered no. is %d");
printf("\nEntered no.is %d",a);
getch();
}
#include<stdio.h>
void main()
{
int a=5;
printf("Entered no. is a");
printf("\nEntered no. is %d");
printf("\nEntered no.is %d",a);
getch();
}
Output:
Entered no.is a
Enterad no. is %d
Entered no. is 5
Entered no.is a
Enterad no. is %d
Entered no. is 5
No comments:
Post a Comment