Hi,
This two parts of code both are intended to do one thing. get two numbers from user, calculate sum between them. print it.
now only the first code is working properly. second one is faulty. but why? what's the problem?
code no1:
#include <stdio.h>
int main()
{
int n, count, sum;
printf("Enter first number:\n");
scanf("%d",&count);
printf("Now second number:\n");
scanf("%d", &n);
sum=0;
if (n<0 || count<0)
puts("ERROR!!!\nCan't be negative!\n\n");
else
while(count<=n)
{
sum=sum+count;
++count;
}
printf("Sum = %d",sum);
return 0;
}
/* vahid.a1996@gmail.com */
code no2:
#include<stdio.h>
int main()
{
int num1, count, sum = 0;
printf("Please enter two numbers:\n");
scanf("%d", &num1);
printf("Please enter two numbers:\n");
scanf("%d", &count);
while(count<=num1)
{
sum = sum + num1;
++num1;
}
printf("is %d", sum);
return 0;
}