0% found this document useful (0 votes)
28 views5 pages

Structured Programming Cat

structured programming assignment

Uploaded by

intellect030
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views5 pages

Structured Programming Cat

structured programming assignment

Uploaded by

intellect030
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

INSTITUTION: MOUNT KENYA UNIVERSITY

SCHOOL: SCHOOL OF COMPUTINGAND INFORMATICS

DEPARTMENT: INFORMATION TECHNOLOGY

UNIT TITLE: STRUCTURED PROGRAMMING

UNIT CODE: BIT 1208

NAME: ERICK AMWAYI

REG NO: BIT/2017/75704

TASK: STRUCTURED PROGRAMMING CAT 1 AND CAT 2

SUBMITTED ON 31st OCTOBER 2019


With an example, of a c program, explain the various section of a c program

#include<stdio.h>

#include<conio.h>

Void main ()

Printf (“”hello, world\n”);

Return;

Comments: these are ways of explaining what makes a program. They are ignored by the
compiler. Comments can be used anywhere in the program.

#includes<stdio.h>: it is preprocessor command it notifies the compiler to include header files


before compiling the and executing the program.

Main (): this function show where the program execution begins.

Braces: the curly brackets show the main function scope

Printf (): it is a pre-defined function used to display the text on the screen.

Return 0: at the end of the main function it returns zero.

b) Write a program in c to find the greatest of the three different numbers using
conditional operator

#include<stdio.h>

Void main ()

{
Int x, y, z;

Printf (”Enter the three numbers :”);

Scanf (“%d %d %d”, &x &y, &z);

Big=x>y? (x>z? x: z) (y>z? y: z);

Printf (“\n the biggest number is: %d, big);

c) Using array structure, writes a program that accepts 5 values from the user, calculate
sum and average of these values and print them.

#include<stdio.h>

Include main () {

Int arr [5], I, sum=0, n;

Float average=0.0

Printf (“enter the number 0”)

Scanf (“%d”, &n);

Printf (“\n enter %d element for (I =<n; I++)

Scanf (“%d”, & arr [i]);

For (I =; I<n; I++);

Sum=sum+arr [I]

Age= (float)/n;

Printf (“\n the array element for (I =0; I <n I ++)

Printf (“%d\t”, arr [I]);


Printf (“\n the sum of elements”);

Printf (“\n the average of elements”);

Return 0;

d) Write a program to print the following:

* *

* * *

* * * *

#include < stdio.h>

Int main ()

Int I, j, rows;

Printf (“enter number of rows,”)’;

Scan f (“%d”, &rows);

{For (i=1; I <=rows; ++j)

For (j=1; j<I; ++j)

Printf (“\n”);

Return 0

You might also like