Anda di halaman 1dari 1

1)a) GENERAL STRUCTURES

Documentating
Pre processor
Globa; declarations
Void main (void)
{
Local declarations statements }
b) EVENLY DIVISIBLE BY 4
#include<stdio.h>
Int main ()
{
Int number;
Printf(enter a number\n);
Scanf(%d,&number); If(number %4==0)
{
Printf(evenly divisible by 4);
}
Else
{
Printf(not divisible by 4);
Return 0; }
C) 6 RELATIONAL OPERATOR
== check if the value of 2 operator are equal or not,
if yes then condition is true
!= not equal to
Greater than
< less than
>= greater than or equal to
<less than or equal to
d) h=(0.5)
#include<stdio.h>
#include<math.h>
Int main()
{
Float h,g,t,u,x;
Printf(please input, initial velocity, initial height,
acceleration due to gravity\n);
Scanf(%f %f %f %f, &t, &u, &x, &g)
Printf(height reached by the projectile = %f\n,h);
Return 0; }
2)i) 3 TYPE SELECTION STATEMENTS
a)if (single selection)
- if condition is true perform action,, if condition is
false, action is skipped, program continues
If(condition)
{
Statements;
}
b) if.. else(double selection)
-if condition is true perform action,, else (if
condition is false) perform a different action (this
will skip if condition is true)
If (expression)

Action statements -1
Else
Action statements -2
c) switch(multiple selection)
-allows selection among many actions depending on
the integral value of variable or expression
Switch(vor)
case constant 1; statement;
Break;
case constant 2; statement;
Break;
Default: statement;
Break;
}
ii) exmpl multiple
what is the output:
int x,y;
x=3; y=5; if (x<2)
printf(%d\n,x);
else
printf(%d\n,y);
b)RADIUS OF CIRCLE
#include<stdio.h>
#include<math.h>
Int main ()
{
float pi=3.142;
int choice;
float radius,circum,area,square;
printf(please input radius\n);
scanf(%f,&radius);
printf(1.circumference of circle\n);
printf(2.area of the circle\n);
printf(3.largest square in\n);
scanf(%d,&choice);
switch (choice)
{
Case 1: circum=2*pi*radius;
Printf(circumference is =%f\n, circum);
Break;
Case 2 : area = pi*radius*radius;
Printf(area of circle is %f\n,area);
Case 3 : square = 2*radius*radius;
Printf(largest square is = %f\n,square);
Break;
Default : printf(invalid selection\n);
}
Return 0;
}
3) b) TENSILE STRENGHT
#include<stdio.h>
Int main ()
{
Int tensile;

Printf(please input tensile strength\n);


Scanf(%d,&tensile);
If (tensile>=459)&&(tensile<507))
{
Printf(aluminum alloy\n);
}
Else if(.
{
Printf(rubber
}
Else
{
Printf(unknown material\n);
}
Return 0; }
c) i) collection of height
#include<stdio.h>
Int main()
{
Int height; int short =0; int average=0; int tall=0;
For(int i=0; i<30; i++;
{
Printf (please input height\n);
Scanf(%d,&height; if (height>170cm);
{
Tall++;
}
If ((height>=160)&&(height<=170))
{
Average ++;
}
Short ++;
}
{
printf(number of tall student= %d\n, tall);
printf(number of average student= %d\n,
averagel);
printf(number of short student= %d\n, short);
return 0; }
ii) AVERAGE HEIGHT
#include <stdio.h>
Int main()
{
Float height; float sum=0; float average;
For (int i=0, i<30,i++)
{
Printf (please input height\n);
Scanf(%d,%height);
Sum + = height
}
Average = sum/30;
Printf(average height of students =%f\n,average);
Return 0; }

Anda mungkin juga menyukai