This program will print sum of all digits up to 10 on the output screen by using a simple
logic sum=sum+ n this will store value of n+ sum in sum and then it will add the new
number to the updated sum and by doing so we will get sum of all numbers up to 10.
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int
n=1,sum=0;
while
(n<=20)
{
sum=
sum+n;
n++;
}
printf("Sum of all no upto 10 are:%d\n",sum);
Output:
Post a Comment