Sum of two or more number & ‘scanf’ in C language..

Sum of two number for beginners with basic.

According to mathematics….

If a=10 and b=20 then sum = a+b so, 10+20 then answer is ’30’

In this programme initially  you can take number before run. example a=10, b=20,c=30, d=40. This programme is only for basic and for beginners.

Some important symbols used in code.

  • () small bracket
  • && use for ‘and’ use for address
  • {} curly bracket
  • “” double code
  • #include<stdio.h>
  • #include<conio.h>
  • void main()
  • {
  • int a, b, c;
  • clrscr():
  • a=10;
  • b=20;
  • c=a+b;
  • printf(“Sum = %d”, c);
  • getch();
  • }

Inputs..

If a=10; b=20;

Results…

Sum = 30.

Sum of more than two number for beginners with basic..

  • #include<stdio.h>
  • #include<conio.h>
  • void main()
  • {
  • int a=10,b=20,c=30,d=40,e;
  • clrscr():
  • e=a+b+c+d;
  • printf(“Sum = %d”, e);
  • getch();
  • }

Inputs..

If a=10, b=20, c=30, d=40;

Results..

Sum= 100.

Sum of two number by using ‘scanf’.. Or desire number..

  • #include<stdio.h>
  • #include<conio.h>
  • void main()
  • {
  • int a, b, c;
  • clrscr():
  • printf(“Enter two number for addition”);
  • scanf(“%d%d”, &a, &b);
  • c=a+b;
  • printf(“n1%d + n2%d = %d”, a, b, c);
  • getch();
  • }

Inputs..

If a=10, b=20..

Results..

10+20 = 30..

Sum of more than two number by using ‘scanf’.. Or desire number..

  • #include<stdio.h>
  • #include<conio.h>
  • void main()
  • {
  • int a, b, c, d, e;
  • clrscr():
  • printf(“Enter two number for addition”);
  • scanf(“%d%d%d%d”, &a, &b, &c, &d);
  • e=a+b+c+d;
  • printf(“n1%d + n2%d +n3%d + n4%d = %d”, a, b, c, d, e);
  • getch();
  • }

Inputs..

If a=10,b=20,c=30,d=40;

Results..

10+20+30+40=100..

Design a site like this with WordPress.com
Get started