Computer Science, asked by Jain6596, 1 year ago

C program to find sum of n numbers using do while loop

Answers

Answered by sanjay7556
7

Explanation:

hope this helps u

I didn't write it because u will confuse with my handwriting

Attachments:
Answered by Jasleen0599
0

C program to find sum of n numbers using do while loop

#include <stdio.h>  

#include <conio.h>  

void main()  

{  

   int num, i, sum = 0; // declare local variables  

   printf(" Enter a positive number: ");  

   scanf("%d", &num); // take any positive number  

   // executes until the condition remains true.  

   for (i = 0; i <= num; i++)  

   {  

       sum = sum + i; // at each iteration the value of i is added to the sum variable  

   }  

   // display the sum of natural number  

   printf("\n Sum of the first %d number is: %d", num, sum);  

   getch();  

}  

  • We first set the program's condition, such as the desire to add numerous integers, in the while loop. If the condition is true, the while loop is then executed until the condition becomes false by the compiler. The loop will end and the sum of the integers will be printed if the condition is false.
  • S=n(n+1)2 is the formula for the sum of the first n natural integers. Find n if the sum of the first n natural numbers is 325.
  • printf ("Enter two integers:") scanf ("%d%d", &number1, &number2) The sum of these two values is then added together using the + operator and kept in the sum variable. The total of numbers is displayed using the printf() function. printf (number1, number2, "%d +%d =%d".

#SPJ3

Similar questions