1.write a program segment that computes 1+2+3+...+(n-1)+n, where n is a data value. follow the loop body with an if statement that compares this value to (n*(n+1)) /2 and displays a message that indicates whether the value are the same or different. what message do you think will be displayed.

this my code please i need help whether am right or not.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  int count=0,sum=0;
  int n,items;
  int sum_2=0;
  
  printf("enter the data value n>>");
  scanf("%d",&n);
  
  printf("enter the item to compute>>");
  scanf("%d",&items);
  
  do{
                     
  sum_2 = ((n *(n + 1))/ 2);
  
  sum +=items;
  
  count +=1;
}while(count < n);
printf("\n\nthe sum is %d\n\n",sum);

if(sum == sum_2)
{
printf("the two sums are the same");
}

else
{
printf("the two values are different \n\n");
}


  system("PAUSE");	
  return 0;
}

I honestly don't know what you're trying to do.
If you want to add two numbers, just use the addition symbol..
5 + 5 = 10.
Can you be a bit more descriptive?

>this my code please i need help whether am right or not
The best helper is your C compiler. Compile the code, run it - and see whether you are right or not. Didn't you know that way? Are you sure that DaniWeb forum is a some kind of remote compiler? Come here with your problems, not with codes.

Read this forum announcement: http://www.daniweb.com/forums/announcement118-3.html.
Next time use code tag for your snippets:
[code=c] source

[/code]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.