Coursework 1
Q1
#include <stdio.h>
#include <string.h>
int main()
{
int Numbers=0;
int
Numbers1;
int i;
for(i=1;i<11;i
)
{
printf("Enter Numbers %d :\n",i);
scanf("%d",&Numbers1);
Numbers=Numbers+Numbers1;
}
if (Numbers > 300)
printf("\n The total amount you entered is Higher than 300");
else if (Numbers < 300)
printf("\n The total amount you entered is Lower than 300");
else printf("\n The Amount you entered is equal to 300");
}
Q2
#include <stdio.h>
#include <string.h>
void main(void)
{
int number=300;
int i;
printf("Press 1 to get multiples of 5 between 300 and 800);
scanf("%d",&i);
if (i<1 || i>3)
printf("You have entered an incorrect number ");
switch( i )
case 1:
while(number<800){
number=number+5;
printf("\n %d\n",number-5);
}
break;
}
}
Q4
int main( void )
{
int years[ 20 ] = { 0 };
int counter;
for ( counter = 0; counter < 20; counter )
{
printf( "Number: " );
scanf( "%d", &years[ counter ] );
}
if ( input % 2 ) /* This is the test condition */
printf( "That is an odd number.\n" );
else
printf( "Invalid Input.\n" );
}
}