Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System;
class pd
{
	public static void Main(String [] args)
	{
	long sum=1;
	long i=1;
		while(i<=1000)
		{
			sum=sum*2;
			i++;
		}
		Console.WriteLine(sum);
		pd1 ob=new pd1(sum);
		
	}
}
class pd1
{
	public pd1(long n)
	{
		long s=0,k;
		while(n!=0)
		{
			k=n%10;
			s+=k;
			n=n/10;
		}
		Console.WriteLine(s);
	}
	}
Posted
Updated 27-Aug-15 4:22am
v2
Comments
xszaboj 27-Aug-15 10:16am    
output value of what exactly?
Andy Lanng 27-Aug-15 10:22am    
Code dumps are not a question

1 solution

Um.
That isn't what you are supposed to do with classes.
All that is doing is moving the code from the Main method into a class constructor and hoping - it isn't a valid OOPs design.

And that's ignoring that it won't even work, as a long has only 64 bits, and can't hold 21000 - at best sum will end up as zero; at worst you will get an overflow exception.

I'd suggest that instead of trying to "get the output value" you go back to your homework question and re-read it: you are almost certainly going down the wrong path.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900