Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
74 views

Introduction To Programming Exam

The document contains questions and code snippets from an Introduction to Programming course, including code to calculate averages of exam grades, add fractions, and check pass/fail criteria or math scores. It also defines characteristics of third generation programming languages and includes a code sample to calculate a formula involving multiplication, addition, and powers.

Uploaded by

Nyambura Kinyua
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Introduction To Programming Exam

The document contains questions and code snippets from an Introduction to Programming course, including code to calculate averages of exam grades, add fractions, and check pass/fail criteria or math scores. It also defines characteristics of third generation programming languages and includes a code sample to calculate a formula involving multiplication, addition, and powers.

Uploaded by

Nyambura Kinyua
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

LUCY NYAMBURA KINYUA.

15/02506.

BBIT.

EVENING.

RUARAKA CAMPUS.

INTRODUCTION TO PROGRAMMING.
15/02506
QUESTION ONE.
#include <stdio.h> /* it is stdio.h not studio.h, stdio. h is the header file for standard input and
output. This is useful for getting the input from the user(Keyboard) and output result text to the
monitor(screen).*/

int main() {
char StudentName [100]; /*variable definition consists of only letters,digits or the underscore
character and the first letter must be an alphabet*/
float ExamValue, Sum,Avg; /* the semicolon is a statement terminator by default, statements in C
and C++ can have any number of lines So the semicolon tells C that the statement has been
terminated, and whatever follows is a new statement */
int students,exams;
for (students= 0; students < 5; students++){
Sum=0.0;
printf("Enter student name \n");
scanf("%c", StudentName); /* format specifier %c for character StudentName*/
for (exams = 0; exams < 3; exams++){ /* Exams is not a template, a nested loop for exams*/
printf("Enter exam grade: \n");
scanf("%f",& ExamValue);
Sum = Sum + ExamValue; /* semicolon is a statement terminator*/
}
Avg = Sum / 3.0; /* semicolon is a statement terminator*/
printf("Average for %c is %f\n", StudentName,Avg); /* format specifier%C for studentname*/
}
return 0;
}
15/02506
Question one B
#include<stdio.h>
#include<stdlib.h>
typedef struct
{
int n;
int d;
} fraction;
int main()
{
int n1, d1;
int n2, d2;
printf("Enter fraction 1 (numerator and denominator seperated by space):");
scanf("%d%d",&n1,&d1);
printf("Enter fraction 2 (numerator and denominator seperated by space):");
scanf("%d%d",&n2,&d2);
fraction f1={n1,d1};
fraction f2={n2,d2};
fraction r={f1.n*f2.d+f2.n*f1.d, f1.d*f2.d};
printf("Result=%d/%d", r.n, r.d); printf("\n");
return 0;

15/02506
QUESTION TWO

A.

#include <stdio.h>
int main(){
int math,physics,chemistry;
printf("Enter marks for math");
scanf("%d",&math);
printf("Enter marks for physics");
scanf("%d",&physics);
printf("Enter marks for chemistry");
scanf("%d",&chemistry);
if(math >= 80){
printf("Result : PASS ");
}
else if ( physics >=75){
printf("Result : PASS");
}
else if ( chemistry >=70){
printf("Result : PASS");
}
else {
printf("Result : Fail");
}
return 0;
}

B. Describe THREE characteristics of third generation programming languages.


(3 Marks)
1. Programmers follow a series of procedures or instructions in a precise order
to solve a problem.
2. A high level language that uses English-like language e.g COBOL and
BASIC.
3. Programmers could write in a familiar notation instead of numbers and
abbreviations.
4. Most high level languages are machine independent i.e they can be used on
more than one kind of computer.

15/02506
QUESTION TWO C
#include<stdio.h>
int main()
{
int x,y,s,p,total;
printf("Enter two numbers\n");
scanf("%d%d",&x,&y);
p=x*y;
s=x*y;
total=(s*s)+p*(p+y);
printf("%d",total);
return 0;
}

You might also like