Monday 25 July 2011

[chapter 3 part 2]let us c [SOLVED]



[E] Attempt the following:
(a)Write a program to print all prime numbers from 1 to 300. (Hint: Use nested loops, break and continue)


click here for Answer!!!



(b)Write a program to fill the entire screen with a smiling face. The smiling face has an ASCII value 1.


click here for Answer!!!


(c)Write a program to add first seven terms of the following series using a for loop: 1/1! + 2/2! + 3/3! + .........

click here for Answer!!!



(d)Write a program to generate all combinations of 1, 2 and 3 using for loop.

click here for Answer!!!


(e) According to a study, the approximate level of intelligence of a person can be calculated using the following formula: i = 2 + ( y + 0.5 x ) Write a program, which will produce a table of values of i, y and x, where y varies from 1 to 6, and, for each value of y, x varies from 5.5 to 12.5 in steps of 0.5.


click here for Answer!!!


(f)Write a program to produce the following output:
       A B C D E F G F E D C B A
       A B C D E F   F E D C B A
       A B C D E       E D C B A
      A B C D           D C B A
       A B C               C B A
       A B                   B A
       A                       A 
click here for Answer!!!


[7]int i=10;
(g)Write a program to fill the entire screen with diamond and heart alternatively. The ASCII value for heart is 3 and that of diamond is 4.

click here for Answer!!!


(h)Write a program to print the multiplication table of the number entered by the user. The table should get displayed in the following form. 29 * 1 = 29 29 * 2 =58 ....


click here for Answer!!!


(i) Write a program to produce the following output:

                1
               2 3
              4 5 6
             7 8 9 10 



click here for Answer!!!


(j)Write a program to produce the following output:
        

                1
               1 1
              1 2 1
             1 3 3 1
            1 4 6 4 1




click here for Answer!!!


(k)A machine is purchased which will produce earning of Rs. 1000 per year while it lasts. The machine costs Rs. 6000 and will have a salvage of Rs. 2000 when it is condemned. If 12 percent per annum can be earned on alternate investments what would be the minimum life of the machine to make it a more attractive investment compared to alternative investment?

click here for Answer!!!


(l) When interest compounds q times per year at an annual rate of r % for n years, the principle p compounds to an amount a as per the following formula
a = p ( 1 + r / q ) ^ nq
Write a program to read 10 sets of p, r, n & q and calculate the corresponding as.



click here for Answer!!!





(m)The natural logarithm can be approximated by the following series.
(x-1)/x + 1/2((x-1)/2)^2 + 1/2((x-1)/2)^3 + ...
If x is input through the keyboard, write a program to calculate the sum of first seven terms of this series.


click here for Answer!!!

15 comments:

  1. write a factorial program in c++ 1-1/1!+2/2!-3/3!+....+n/n! using for loop

    ReplyDelete
    Replies
    1. #include
      int i,j;
      static float total;

      int main(int argc,char ** argv) {

      for(i=1;i<=7;i++) {

      printf("\n");

      int factorialNumber = 1;
      static float sum;

      //calculating factorial
      for (j = 1; j <= i; j++) {
      factorialNumber *= j;
      }
      sum = i/factorialNumber;
      printf(" Factorial are : %d",factorialNumber);
      printf(" sum is : %f",sum);
      total +=sum;
      }
      printf("\n\n\n");
      printf("Total of all 7 is: %f\n",total);
      return 0;
      }

      Delete
  2. first question's answer is wrong.it is showing all numbers from 1 to 300

    ReplyDelete
    Replies
    1. answer is
      #include
      #include
      int main()
      {
      int i,a,n,pn;
      printf("prime number between 1 and 300 is ");
      for(i=2;i<=300;i++)
      {
      for(a=2;a<=i-1;a++)
      {
      if(i%a==0)
      break;
      else
      continue;
      }
      if(i==a)
      {
      printf("%d\t",i);
      }
      }
      return 0;
      getch();
      }

      Delete
  3. first question's answer is wrong.it is showing all numbers from 1 to 300

    ReplyDelete
    Replies
    1. #include
      #include
      #include
      void main(void)
      {clrscr();
      int num,i,n=300;
      for(num=1;num<=300;num++)
      {
      i=2;
      while(i<n-1)
      {
      if(num%i==0)
      break;
      i=i+1;
      }
      if(num==i)
      cout<<num<<" ";
      }
      getch();
      }

      Delete
  4. This is bullshit.....u should run ur code before pasting it here.
    Most of them are incorrect.

    ReplyDelete
  5. Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING

    Appreciation for nice Updates, I found something new and folks can get useful info about BEST ONLINE TRAINING

    ReplyDelete
  6. A B C D.......program is wrong

    ReplyDelete
    Replies
    1. #include
      #include
      #include
      void main(void)
      {clrscr();
      int a,x,n=71,o=70,y=1,c;
      for(x=1;x<=7;x++)
      {
      for(a=65;a<=n;a++)
      printf("%c",a);
      for(c=2;c=65;a--)
      printf("%c",a);
      printf("\n");
      n--;
      o--;
      y=y+2;
      }
      getch();
      }

      Delete
  7. #include


    main( )
    {

    int i,j,k=0,l;
    for(i=1;i<=7;i++) //loop for 7 rows
    {
    for(j=1;j<=8-i;j++) //ASCII values upto current value of i
    printf("%c ",64+j); //chracter + blank space
    j--; //at termination of loop,j will be max_value+1(>8-i),so decrement it;

    for(k=1;i>1&&k<=13-2*j;k++)//in first row no space is needed,but in later
    printf(" "); //rows,13-2*(chracterw printed uptill now in current row)
    k--; //same reason as j

    for(l=13-j-k;l>=1;l--) //chracters printed in reverse order of characters printed
    printf("%c ",64+l); //uptill now in current row(other than blanks)

    printf("\n"); //insert a newline
    sleep(100);
    }

    }

    ReplyDelete
  8. i am new to c,can u please explain f part in detail

    ReplyDelete
  9. Q. Five numbers are entered from the keyboard into an array. Write a program to find out the sum of all the numbers in the array.

    ReplyDelete
    Replies
    1. #include
      #include
      #include
      void main(void)
      {
      long num,sum;
      printf("\ngive any number which contain digit");
      scanf("%ld",&num);
      sum=num%10+(num%100)/10+(num%1000)/100+(num%10000)/1000+num/10000;
      printf("\nsum of number = %ld",sum);
      getch();
      }

      Delete
  10. Please check the soln of question [f] & do it correctly

    ReplyDelete