SUM AND AVERAGE
Program number#
1
Program that takes 3 inputs and
process it for sum and average and its printout.
Program:
void main (void)
{
int num1, num2, num3, sum;
float avg;
printf(“enter 1st number”);
scanf(“%d”,&num1);
printf(“enter 2nd number”);
scanf(“%d”,&num2);
printf(“enter 3rd number”);
scanf(“%d”,&num3);
sum= num1+num2+num3;
avg=sum/3.0;
printf(“sum
of given number is =%d \n average of given number is = %f”, sum, avg);
}
CONDITIONAL
PROGRAM
LOSS AND
PROFIT
Program number#
2
Program that determine loss and
profit
Program:
void main (void
{
int sale, cost;
printf(“enter cost price”);
scanf(“%d”,
&cost);
printf(“enter
sale price”);
scanf(“%d”,
&sale);
if (sale
> cost)
printf(“you
are in profit”);
else
printf(“you
are in loss”);
}
PERCENTAGE
AND GRADE
Program number#
3
Program that determine percentage
and grade
Program:
void main ()
{
int math, physic, chemistry, computer, total,
sum, percentage;
printf(“enter number obtained in math”);
scanf(“%d”, &math);
printf(“enter number obtained in physic”);
scanf(“%d”, &physic);
printf(“enter number obtained in chemistry”);
scanf(“%d”, &chemistry);
printf(“enter number obtained in computer”);
scanf(“%d”, &computer);
printf(“enter total number”);
scanf(“%d”,
&total);
sum=
math+ physic+ chemistry+ computer;
percentage=
sum/total*100;
if (percentage>
= 80)
printf(“A+”);
else if
(percentage > = 70 && percentage < =79)
printf(“A”);
else if
(percentage > = 60 && percentage < =69)
printf(“B”);
else if (percentage > = 50 && percentage
< =59)
printf(“C”);
else if (percentage > = 40 && percentage
< =49)
printf(“D”);
else if (percentage > = 33 &&
percentage < =39)
printf(“E”);
else if (percentage < =32)
printf(“FAIL”);
else
printf(“invalid numbers”);
}
EVEN OR
ODD NUMBER
Program number#
4
Program which determine even or odd
number
Program:
void main (void)
int num, mod;
prnitf(“enter
a number”);
scanf(“%d”,
&num);
mod=num%2;
if(mod ==0 )
printf(“the
entered number is even ”);
else if(mod==1)
printf(“the
entered number is odd”);
else
printf(“the
entered is invalid”);
}
ITERATION PROGRAM
NAME PRINT
Program
number# 5
A program which print and name or
statement number of times
Program:
void main (void)
{
int a:
for (a=1;a<=10;a=a++)
printf(“its
thrown out gadgets”);
}
This program
will print the sentence ‘its thrown out gadgets’ 10 times.
TABLE
Program number#
6
Program which print table of given
number.
Program:
void main(void)
{
int num,
product,a;
printf(“enter
a number ”);
scanf(“%d”,
&num);
for (a=1;a<=10;a=a++)
{
product=
num*a;
printf (“%d
x %d = %d”, num, a, product );
}
}
0 comments:
Post a Comment
Please do not enter any spam link in the comment box