answersLogoWhite

0

AllQ&AStudy Guides
Best answer

#include<iostream.h> #include<conio.h> void main() { clrscr(); int i,k,a[10],c[10],n,l; cout<<"Enter the no. of elements\t"; cin>>n; cout<<"\nEnter the sorted elments for optimal merge pattern"; for(i=0;i<n;i++) { cout<<"\t"; cin>>a[i]; } i=0;k=0; c[k]=a[i]+a[i+1]; i=2; while(i<n) { k++; if((c[k-1]+a[i])<=(a[i]+a[i+1])) { c[k]=c[k-1]+a[i]; } else { c[k]=a[i]+a[i+1]; i=i+2; while(i<n) { k++; if((c[k-1]+a[i])<=(c[k-2]+a[i])) { c[k]=c[k-1]+a[i]; } else { c[k]=c[k-2]+a[i]; }i++; } }i++; } k++; c[k]=c[k-1]+c[k-2]; cout<<"\n\nThe optimal sum are as follows......\n\n"; for(k=0;k<n-1;k++) { cout<<c[k]<<"\t"; } l=0; for(k=0;k<n-1;k++) { l=l+c[k]; } cout<<"\n\n The external path length is ......"<<l; getch(); }

This answer is:
Related answers

#include<iostream.h> #include<conio.h> void main() { clrscr(); int i,k,a[10],c[10],n,l; cout<<"Enter the no. of elements\t"; cin>>n; cout<<"\nEnter the sorted elments for optimal merge pattern"; for(i=0;i<n;i++) { cout<<"\t"; cin>>a[i]; } i=0;k=0; c[k]=a[i]+a[i+1]; i=2; while(i<n) { k++; if((c[k-1]+a[i])<=(a[i]+a[i+1])) { c[k]=c[k-1]+a[i]; } else { c[k]=a[i]+a[i+1]; i=i+2; while(i<n) { k++; if((c[k-1]+a[i])<=(c[k-2]+a[i])) { c[k]=c[k-1]+a[i]; } else { c[k]=c[k-2]+a[i]; }i++; } }i++; } k++; c[k]=c[k-1]+c[k-2]; cout<<"\n\nThe optimal sum are as follows......\n\n"; for(k=0;k<n-1;k++) { cout<<c[k]<<"\t"; } l=0; for(k=0;k<n-1;k++) { l=l+c[k]; } cout<<"\n\n The external path length is ......"<<l; getch(); }

View page

for (n=1; n<1000; ++n) {

for (sum=0, k=1; k<=n/2; ++k)

if (n%k==0) sum += k;

if (sum==n) printf ("%d\n", n);

}

View page

k = f(n) = 7n

View page

#include

int main()

{

int count,i,j,k,n,*a,sum=0;

printf("Enter the value of 'n':");

scanf("%d",&n);

a=malloc(n*sizeof(int));

for(i=1;i<=n;i++)

{

count=0;

j=1;

while(j<=i)

{

if(i%j==0 && i!=2)

count++;

j++;

}

if(count==2 count==1)

{

for(k=0;k<=n;k++)

a[k]=i;

}

}

for(k=0;k<=n;k=k+1)

printf("%d\t",a[k]);

for(k=0;k<=n;k=k+2)

sum+=a[k] * a[k];

printf("The sum of squares of alternative prime numbers is=%d",sum);

getchar();

return 0;

}

Read more: Write_a_program_to_print_the_sum_of_squares_of_alternative_prime_numbers

View page

n(n+1)/2

You can see this from the following:

Let x=1+2+3+...+n

This is the same as x=n+(n-1)+...+1

x=1+2+3+...+n

x=n+(n-1)+...+1

If you add the corresponding terms on the right-hand side of the two equations together, they each equal n+1 (e.g., 1+n=n+1, 2+n-1=n+1, ..., n+1=n+1). There are n such terms. So adding the each of the left-hand sides and right-hand sides of the two equations, we get:

x+x=(n+1)+(n+1)+...+(n+1) [with n (n+1) terms on the right-hand side

2x=n*(n+1)

x=n*(n+1)/2

A more formal proof by induction is also possible:

(1) The formula works for n=1 because 1=1*2/2.

(2) Assume that it works for an integer k.

(3) Now show that given the assumption that it works for k, it must also work for k+1.

By assmuption, 1+2+3+...+k=k(k+1)/2. Adding k+1 to each side, we get:

1+2+3+...+k+(k=1)=k(k+1)/2+(k+1)=k(k+1)/2+2(k+1)/2=(k(k+1)+2(k+1))/2=((k+2)(k+1))/2=(((k+1)+1)(k+1))/2=((k+1)((k+1)+1)/2

View page
Featured study guide

Chemistry

3 cards

What kind of crystalline solid is graphite

How many moles of O2 gas in 1L container

How are oh and poh related

➡️
See all cards
1.0
1 Review
More study guides
No Reviews

No Reviews
Search results