Showing posts with label C Prog. Show all posts
Showing posts with label C Prog. Show all posts

Tuesday, 8 November 2011

Write a program to print Pascal triangle

Algorithm:

 Step1:         start

Step2:         initialize binom =1, f=0

Step3:         check the condition f<p

Step4:         for r=40-3*f;r>0; --r

Step5:         print" "

Step6:         for x=0; x<f; ++x

Step7:         if x == 0 or f==0

          Binom = 1


Step8:         else

          Binom=(bimom*(f-x+1)/x


          Printf binom


Step9:         stop

 

Program:

Write a Program to find Armstrong number

Algorithm:

Step1:         start

Step2:         read the number

Step3:         while n!=0 calculate sum+pow(n%10,3);

          Else


          Goto 5


Step4:         n=n/10 goto 3

Step5:         if sum==n print the no is armstrong else goto 6

Step6:         print the no is not prime

Step7:         stop

 

Program:

Saturday, 5 November 2011

Program Using Switch Case

A Maruthi car dealer maintains a record of sales of various vehicles in the following form:

Vehicle type             Month of sales           Price(Rs)

Maruthi-800                 02/87                      75,000

Maruthi-van                 07/87                       95,000

Maruthi-DX                  04/88                      1,10,000

Gypsy                             08/88                      85,000

Write a c program to read this data in to a table of strings and o/p the details of particular  vehicle sold during a specified period the program should request the user to input the  vehicle type and the period.(starting month and ending month)

Algorithm:

Step 1: Start

Step 2: Enter your choice

Step 3: Read ch value

Step 4: if ch =1 then

4.1 printf "Month of sales is : 02/87”


4.2 printf "Price is : 75,000"


Step 5: if ch =2 then

5.1 print "Month of sales is : 07/87 "


5.2 print "Price is  : 95,000”


step 6: if ch=3 then

6.1 print "Month of sales is  : 04/88 "


6.2 print " Price is  : 1,10,000"


Step 7:

7.1 print "Month of sales is : 08/88 "

7.2 print " Price is  : 85,000"


Step 8 : end

Program:

Write a program to read x and to compute y=1 for x>0,y=0 for x=0 and y=-1 for x

Algorithm:

 Step1:         Start


Step2:         Read the value of x.


Step3:         if (x>0) y-1 else if (x=0) y=0 else x<0) y=-1


Step4:         Print y


Step5:         Stop.



Program:

evaluate the expression 2.5 log(x) +cos(a)+|x2-y2|+2(xy)1/2

Algorithm:

Step1:         Start


Step2:         Read the values of x,y and a.


Step3:         p=2.5*log(x)+ cos(a*3.14/180)+sqrt(2*x*y)+(x*x-y*y)


Step4:         Print p


Step5:         Stop.


 

 

Program: