Write a c code segment using a for loop that calculates and
prints the sum of the even integers from 2 to 30, inclusive?

Answer Posted / rukmanee

#include<stdio.h>
#include<conio.h>
main()
{
int i;
int sum=0;
clrscr();
for(i=2;i<=30;i++)
{
if(i%2==0)
{
sum=sum+i;
}
}
printf("%d",sum);
getch();
}
output:240

Is This Answer Correct ?    5 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Give basis knowledge of web designing ...

1567


Why shouldn’t I start variable names with underscores?

621


write a program to create a sparse matrix using dynamic memory allocation.

4365


Do pointers store the address of value or the actual value of a variable?

602


What functions are in conio h?

648






What does c mean in basketball?

554


What is use of integral promotions in c?

658


I have written a pro*C program to fetch data from the cursor. where in i have used the concept of BULK FETCH.... each FETCH statement is taking lots of time to fetch specified number of rows at...

9649


What's a good way to check for "close enough" floating-point equality?

617


Write a program in c to replace any vowel in a string with z?

680


What is the difference between near, far and huge pointers?

624


Explain how are 16- and 32-bit numbers stored?

776


Which built-in library function can be used to match a patter from the string?

733


What is putchar() function?

626


What is the use of structure padding in c?

555