Question about Operating Systems

1 Answer

Read n & m, display the sum of all the even and odd numbers between n to m.

Sample output
enter 1st no:3
enter 2nd no:
sum of even nos:10
sum of odd nos:12

Posted by on

1 Answer

  • Level 2:

    An expert who has achieved level 2 by getting 100 points

    MVP:

    An expert that gotĀ 5 achievements.

    Governor:

    An expert whose answer gotĀ voted for 20 times.

    Scholar:

    An expert who has written 20 answers of more than 400 characters.

  • Expert
  • 148 Answers

#include <stdio.h>

int main()
{
int n1, n2, i;
int sum = 0;
n1 = 3;
n2 = 11;

for (i = n1; i <= n2; i++) {
if (i % 2 == 0) {
printf("Adding %d\n", i);
sum = sum + i;
}
}
printf("sum = %d\n", sum);
return 0;
}

Posted on Feb 21, 2008

Add Your Answer

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

1 Answer

How can i display an even number if i enter an odd number in visual basic 6.0


To display an even number when an odd number is entered you can add 1.
n= val(text1.text) 'Take the value of n from the textbox.
If n mod 2 =1 then 'If n is an odd number n=n+1 'You make it an even number end if
text2.text = n 'Display it in another textbox.

Please give a good rating to this answer so that I will be encouraged to support people like you having problems with VB6.

Sep 22, 2011 | Operating Systems

3 Answers

9999555533331111 out of these numbers any 6 numbers total is 21? how


this would be explained on the basis of two FACTS below.......
sum of two odd numbers are always even and
sum of to even numbers are also always even

then how 6 odd numbers (consider 3 pairs, 9 5 3 1 being odd numbers) can make an odd number 21..!!
SO SIMPLE
Make your basics strong...


Aug 14, 2010 | Operating Systems

1 Answer

Program of matrix multiplication


In FORTRAN:

PROGRAM MATMULT
PARAMETER (N=3)
DIMENSION X(N,N), Y(N,N), Z(N,N)
DOUBLE PRECISION SUM
READ, X
READ, Y
DO 200 J=1, N
DO 100 K=1, N
SUM = 0.0
DO 50 L=1, N
SUM = SUM + X(J,L) * Y(L,K)
50 CONTINUE
Z(J,K) = SUM
100 CONTINUE
200 CONTINUE
WRITE, Z
END

Aug 04, 2010 | Operating Systems

1 Answer

I want to make a minor project in core java.....suggest me some new and different projet.....


Program 1
//Find Maximum of 2 nos.

Program 2
//Find Minimum of 2 nos. using conditional operator

/*Write a program to generate 5 Random nos. between 1 to 100, and it
should not follow with decimal point.

* Write a program to generate Harmonic Series.

Display Triangle as follow : BREAK DEMO.

and you can find projects from below link

http://www.freejavaguide.com/javasource3.htm

thanks

May 18, 2010 | Microsoft Windows XP Professional

1 Answer

How to make a program


Hi Friend,

This is a python command solution.you can download the python IDE from this link and get down to buisiness.

www.python.org/download

And here is my example.....

> >>> L=[]
> >>> L.append('10')
> >>> L.append('15')
> >>> L.append('20')
> >>> len(L)
> 3
> >>> print L
> ['10', '15', '20']
>
> is there a way to sum up all the numbers in a list? the number of
> objects in the list is vary, around 50 to 60. all objects are 1 to 3
> digit positive numbers.
>
> all i can think of is check the length of the list (in the above
> example, 3), then L[0]+L[1]+L[2] .....

Good Luck!!!

Jun 23, 2009 | Apple Mac OS X 10.4

2 Answers

HOW TO PROGRAM ARITHMETIC ALGORITHM( ADDITION)IN C++


above int main () you will want "using namespace std;" without quotes. Under that, "int main ()" without quotes, then a [ bracket to start the main function.
Please rate, thanks!

Mar 16, 2009 | Operating Systems

1 Answer

How to add two no in c without any operator (even assignment operator)?


This code doesn't include any overflow error checking mechanism. It is not much difficult to implement one however.
#include <stdio.h>
int main(){
unsigned num1,num2,result=0,i=0,temp=0;
printf("Enter the two numbers:\n");
scanf("%d",&num1);
scanf("%d",&num2);
for (i= ~0; i; i>>= 1){ //ensure that the body of the loop is executed 8*sizeof(unsigned) times where 8 is the number of bits in a byte. The number of bits in a byte can be more than 8 on some machines.
temp<<= 1;
temp|= (num1^num2^result)&1;
result= ((num1|num2)&result|num1&num2)&1;//to understand this line and the one above take a look at the full adder circuit above
//here temp is the equivalent of S1 in the full adder circuit above and result is the equivalent of C1
num1>>= 1;
num2>>= 1;
}
//the bit order in temp would be in the reverse order. the following code snippet reverses the order
for (i= ~0, result= ~i; i; i>>= 1){
result<<= 1;
result|= temp&1;
temp>>= 1;
}
printf("Sum: %d",result);
return 0;
}

Here is another elegant solution that uses recursion
#include <stdio.h>
int add(int a, int b){
if (!a) return b;
else
return add((a & b) << 1, a ^ b);
}
int main(){
printf("Enter the two numbers: \n");
int a,b;
scanf("%d",&a);
scanf("%d",&b);
printf("Sum is: %d",add(a,b));
}

Mar 05, 2009 | Microsoft Windows XP Professional

1 Answer

Re issue of product key


Hi,
 
Not to worry. As long as you have genuine windows you can get it activated. You call Microsoft Windows activation for US at: 1 888 571 2048 . The IVR will prompt you to enter read out the number on the activation screen. Punch in the numbers using the Phone dial rather than reading it out. This would be simpler. It would also ask you if this is the only computer windows is installed, and if this is the first time you are activating. Press 1 for Yes on both.
 
Hope this helps. Please rate your feedback!
Thanks,
VJ

Mar 04, 2009 | Microsoft Operating Systems

1 Answer

Odd or integer?


hmm here is a psuedo to consider

input number n
while
n = n / 2
if n = 0 then print n = even , break loop
if n < 0 then print n is odd
loop

Jul 12, 2008 | Operating Systems

1 Answer

A java program that prints # then says whether the # is odd or even


int number = 10 //Insert the number here
if ((number % 2) == 0)  {  System.out.println(number+" is a even number);  } else {  System.out.println(number+" is a odd number); 
{
Let me know if you need a complete java class for this

Apr 15, 2008 | Operating Systems

Not finding what you are looking for?
Operating Systems Logo

Related Topics:

128 people viewed this question

Ask a Question

Usually answered in minutes!

Top Operating Systems Experts

Les Dickinson
Les Dickinson

Level 3 Expert

18299 Answers

Brian Sullivan
Brian Sullivan

Level 3 Expert

27725 Answers

Prashant  Sharma
Prashant Sharma

Level 3 Expert

1127 Answers

Are you an Operating System Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...