Assignment 01-cmis1223
1). School Teacher of a Primary School want a software program to calculate the average marks for
Maths, English, Science and Art for a Student.
1. Use the first three steps of the Development Cycle(Define the
problem:input/output/processing, Outline the solution:main Computation/input
variables/intermediate results, Develop an algorithm) to come up with an algorithm.
Inputs :
Maths mark , Englsh mark , Science mark
Process : Calculate average marks
Output : Average mark
calAverage
1.sum <- (math_mark + English_mark+Science_marrk)
2.average <- sum / 3
2. Write a C program for the Problem.
#include<stdio.h>
main(){
float M_marks , E_marks , Sc_marks;
float Average;
printf("Please enter Maths marks \n");
scanf("%f \n"&M_marks);
printf("Please enter English marks \n");
scanf("%f \n"&E_marks);
printf("Please enter English marks \n");
scanf("%f \n"&Sc_marks);
Average = (M_marks+E_marks+Sc_marks)/3;
printf("Average marks for three subject is %f \n", Average);
}
2). This program is developed to calculate the Age of a living person.
#include <stdio.h>
main() {
int day,month,year;
int bday,bmonth,byear;
printf("\n********Quiz01!********\n");
printf("\nEnter the Todays Date:\f");
scanf("%d/%d/%d",&day,&month,&year);
printf("\nEnter your Birth Day:\f");
scanf("%d/%d/%d",&bday,&bmonth,&byear);
printf("Your Age for Today: %d\n",year-byear);
}
1. Explain the Execution of this program.
#include <stdio.h>
main() {
int day,month,year; // create memory locations in the main memory
int bday,bmonth,byear; // create memory locations in the main memory
printf("\n********Quiz01!********\n"); // print the text on screen ********Quiz01!********
printf("\nEnter the Todays Date:\f"); // prin the text Enter the Todays Date
scanf("%d/%d/%d",&day,&month,&year); // blinking curser , values are assign to the relavant memory locations
printf("\nEnter your Birth Day:\f"); // print the text Enter your Birth Day
scanf("%d/%d/%d",&bday,&bmonth,&byear); //blinking curser , values are assign to the relavant memory locations
printf("Your Age for Today: %d\n",year-byear); // your age for tody year-byear
}
2. Does this program correctly calculates the age of a person? If not explain why?
NO , there is unused variables in this program , day , bday , month , bmonth . Tocalulate the age precisely have to use this variables as well .
right code to calulate the age precisely -
printf("Your Age for Today: %d yaers %d months %d days \n",year-byear , month - bmonth , day-bday);