For “YEAR” field, create a function to calculate the value (hint : use %)based on following categories:
Year 1 : Sem 1 – Sem 3
Year 2 : Sem 4 – Sem 6
Year 3 : Sem 7 – Sem 9
so, we must convert from given semester number to year..
pls.. help me!!
For “YEAR” field, create a function to calculate the value (hint : use %)based on following categories:
Year 1 : Sem 1 – Sem 3
Year 2 : Sem 4 – Sem 6
Year 3 : Sem 7 – Sem 9
so, we must convert from given semester number to year..
pls.. help me!!
hint : use %
That's a dead end hint that actually makes the solution more difficult. Instead, consider dividing the semester number by 3 and then taking the ceiling of the result. This will produce the correct year:
#include <math.h>
#include <stdio.h>
int main(void)
{
int i;
for (i = 1; i < 10; i++)
{
printf("%d -> %d\n", i, (int)ceil(i / 3.0));
}
return 0;
}
Basic arithmetic, baby. ;)
Alternatively, since you're looking at a tiny set of numbers, a brute force solution may be faster and easier to understand:
#include <stdio.h>
int main(void)
{
int i;
for (i = 1; i < 10; i++)
{
int year = 3;
if (i < 4)
{
year = 1;
}
else if (i < 7)
{
year = 2;
}
printf("%d -> %d\n", i, year);
}
return 0;
}
Note, of course, that range checking the semester number was excluded in these examples but should be included in your code.
alright.. thanks to you :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.