Jump to content

.net Prog-Rammers- Help-...cheyandi....


Recommended Posts

Posted

VB.NET only coding...cheppandi...

 

Urgent...nenu oka requirement ki test idi....

 

 

  • Given a list, array, of integers, find the index of the two consecutive numbers which have the largest sum.

     

For example, if the array is 1, 2, 3, 4, 5, the answer is 4, as 4+5 = 9.

Posted

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter Item Count: ");
            int n = int.Parse(Console.ReadLine());

            int[] a = new int[n];
            for (int count = 0; count < n; count++)
            {
                Console.WriteLine("Enter Number " + count.ToString() + ": ");
                a[count] = int.Parse(Console.ReadLine());
            }
         
          int max = 0, seq = 0;
          for (int fcount = 0; fcount < a.Length; fcount++)
          {
              seq= fcount==a.Length-1 ? 0 : a[fcount] + a[fcount+1];
                 if( seq> max)
                  max = fcount;
             
          }
            Console.WriteLine("fcount max is {0} and the sequence is {0}+{1} ",a[max],a[max+1]);
        

          Console.ReadLine();
        }
    }
}

Posted

two years back nannu same question adigadu vendor gadu ..... HCL gadu 

Posted

two years back nannu same question adigadu vendor gadu ..... HCL gadu ---Ippudu HP anta bro....

 

Thanks for quick response....

 

Right-to r-epr-esent form tho paatu ee code submit cheyyali anta bro...

 

desi screening too much asalu...ichedi bisket billing...mallie telephonic and skype kuda...slection process lo...full aadukuntaru process lo....

Posted

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter Item Count: ");
            int n = int.Parse(Console.ReadLine());

            int[] a = new int[n];
            for (int count = 0; count < n; count++)
            {
                Console.WriteLine("Enter Number " + count.ToString() + ": ");
                a[count] = int.Parse(Console.ReadLine());
            }
         
          int max = 0, seq = 0;
          for (int fcount = 0; fcount < a.Length; fcount++)
          {
              seq= fcount==a.Length-1 ? 0 : a[fcount] + a[fcount+1];
                 if( seq> max)
                  max = fcount;
             
          }
            Console.WriteLine("fcount max is {0} and the sequence is {0}+{1} ",a[max],a[max+1]);
        

          Console.ReadLine();
        }
    }
}

 

Same code ctrl-c and ctrl-v...

 

Thanks for the code.

 

Posted

if it is sorted then what's the point below code doesnt work %$#$

VB.NET only coding...cheppandi...

 

Urgent...nenu oka requirement ki test idi....

 

 

  • Given a list, array, of integers, find the index of the two consecutive numbers which have the largest sum.

     

For example, if the array is 1, 2, 3, 4, 5, the answer is 4, as 4+5 = 9.

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter Item Count: ");
            int n = int.Parse(Console.ReadLine());

            int[] a = new int[n];
            for (int count = 0; count < n; count++)
            {
                Console.WriteLine("Enter Number " + count.ToString() + ": ");
                a[count] = int.Parse(Console.ReadLine());
            }
         
          int max = 0, seq = 0;
          for (int fcount = 0; fcount < a.Length; fcount++)
          {
              seq= fcount==a.Length-1 ? 0 : a[fcount] + a[fcount+1];
                 if( seq> max)
                  max = fcount;
             
          }
            Console.WriteLine("fcount max is {0} and the sequence is {0}+{1} ",a[max],a[max+1]);
        

          Console.ReadLine();
        }
    }
}

 

Posted

if it is sorted then what's the point below code doesnt work %$#$

 

currently working bro...

 

can't test the code right away...

 

inoredr to respond to the email of vendor used the same code...

 

they haven't mentioned about the sort order in the question though....

Posted

Thanks for quick response....

 

Right-to r-epr-esent form tho paatu ee code submit cheyyali anta bro...

 

desi screening too much asalu...ichedi bisket billing...mallie telephonic and skype kuda...slection process lo...full aadukuntaru process lo....

yaaa kani honest suggestion inka dikku lekapothey vellu HCL vaditho .....

Posted

try with 5,7,-2,3,0,0 %$#$

havent mentioned ante anduke given a list of integers annaru leda lsorted list of integers annevallu...ina it is very obvious list, numbers yepudu sorted undav okavela unte I will write code in 2 lines...last 2 elements add cheste saripodhi kada %$#$

 

int a = list.Count

Sum = list[a-1] +list[a]

currently working bro...

 

can't test the code right away...

 

inoredr to respond to the email of vendor used the same code...

 

they haven't mentioned about the sort order in the question though....

 

Posted

simple man....

ascending order lo sor chey.....last rendu add chey 

Posted

simple man....

ascending order lo sor chey.....last rendu add chey 

 

Sorting will not work kada bhayya...sum adagaledhu..Index adigadu aa numbers vi array lo

Posted

yes thats my point...this boils down to finding the maximum and second maximum (which will give index) %$#$

Sorting will not work kada bhayya...sum adagaledhu..Index adigadu aa numbers vi array lo

 

 

simple man....

ascending order lo sor chey.....last rendu add chey 

 

Posted

yes thats my point...this boils down to finding the maximum and second maximum (which will give index) %$#$

 

Maximum and second maximum numbers of the array telsina saripodhu kada bhayya...

two consecutive integers with largest sum annadu kada...

 

array lo  -9  8 -6 -4  7 -5 3 2  unnayi anuko....max second max teslisthe saripodhu kadha...

Posted

Sorting will not work kada bhayya...sum adagaledhu..Index adigadu aa numbers vi array lo

ohh...edithene me....oka first two numbers sum chesi oka variable lo pettukuntav...aa variable tho next two elements sum kanukkuntav......aa sum ni max variable tho compare chesthav if greater than compare with next two ala end varaku chesukuntu pothav ante

Posted

int a[] = { -3, 100, -4, -2, 9, -63, -200, 55 };
int max_sum, temp_sum, i, n = 8, t;
temp_sum = max_sum = a[0];
for (i = 0; i < n; i++) {
if (a[i] > 0)
temp_sum += a[i];
else {
t = 0;
while (a[i] < 0 && i < n) {
t += a[i];
i++;
}
if (temp_sum + t > 0) {
temp_sum = temp_sum + t + a[i];
if (temp_sum > max_sum)
max_sum = temp_sum;
} else if (i < n)
temp_sum = a[i];
}
}
if (temp_sum > max_sum)
max_sum = temp_sum;
printf("Maximum Numbers is %d \n", max_sum);

×
×
  • Create New...