You are on page 1of 6

WEEK-9

NAME:SALMAN AHMED QUADRI


ROLL NO:16951A2172
SUBJECT:COMPUTER PROGRAMING
CODE:ACS101
YEAR : I
SEMISTER:II
Q(1) To compute the volume of the sphere of radius 5 ,10,15

ALGORITHM:
(1) Start
(2) Define PI constant value 3.142
(3) Define macro function to pass a radius value as a argument
(4) Call the macro function
(5) Print the result
(6) Stop

PROGRAM:
#include<stdio.h>

#include<math.h>

#define PI 3.14

#define volume(r)((4/3.0)*PI*pow(r,3))
void main()

int r;

float v;

printf("enter the radius of the sphere=r");

scanf("%d",&r);

v=volume(r);

printf("the volume of the sphere =%.3f",v);

}
Q(2) To print the elements of an array

ALGORITHM:
(1) Start
(2) Define macro function that receive array
(3) Repeat all the elements and print elements
(4) Call the macro function
(5) Stop
PROGRAM:
#include<stdio.h>

#define PRINTARRAY(a,l)\

int i=0;\

while(i<l)\

{\

printf("%5d",a[i]);\

i++;\

void main()

int a[10]={ 26,36,40,42,44,46,50,52,54,56};

PRINTARRAY(a,10);

}
Q(3) To illustrate the use of these symbolic constants

ALGORITHM:
(1) Start
(2) Define + as ADD
(3) Define as SUB
(4) Define * as MULT
(5) Define / as DIV
(6) Perform addition using ADD and print the result
(7) Perform substraction using SUB and print the result
(8) Perform multiplication using MULT and print the result
(9) Perform division using DIV and print the result
(10) Stop

PROGRAM:
#include<stdio.h>

#include<math.h>

#define PLUS +

#define MINUS -

#define MULTI *

#define DIVI /

#define MOD %

void main()

int a=30, b=50;

printf("\n addition =%d",a PLUS b);

printf("\n substraction =%d",a MINUS b);

printf("\n multiplication =%d",a MULTI b);


printf("\n division =%d",a DIVI b);

printf("\n modulus =%d",a MOD b);

You might also like