Showing posts with label for loop programs. Show all posts
Showing posts with label for loop programs. Show all posts

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!!!