0% found this document useful (0 votes)
14 views4 pages

Lab Assessment Week 9

Uploaded by

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

Lab Assessment Week 9

Uploaded by

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

LAB ASSESSMENT WEEK 9

Exercise 1
#include<stdio.h>
int main()
{
int num;

for(num=8;num>=2;num-=2)
{
printf("\nHello %d",num);
}
return 0;
}

Exercise 2
#include<stdio.h>
int main()
{
int degree,fahrenheit;

printf("\nDegrees celcius \t Degrees fahrenheit\n");


for(degree=5;degree<=50;degree+=5)
{
fahrenheit=(9*degree/5)+32;
printf("\n\t%d\t\t\t%d",degree,fahrenheit);
}
return 0;
}
Exercise 3
#include<stdio.h>

int main()
{
int total,i,first,second,odd,even,oddsum,evensum;
printf("FirstNum must be less than secondNum.\n");
printf("Enter first number:");
scanf("%d",&first);
printf("Enter second number:");
scanf("%d",&second);
printf("\nOdd number\t Even number\n");
evensum=0;
oddsum=0;
for(first=first;first<=second;first++)
{
even=first%2;
odd=first%2;

for(odd=odd;odd==1;odd++)
{
oddsum+=first;
printf(" %d\t\t ",first);
}

for(even=even;even==0;even++)
{
evensum+=first;
total=oddsum+evensum;
if(first==total)
printf("\t\t ");
printf(" %d\n",first);
}
}
printf("\nSum of odd number:%d\n",oddsum);
printf("Sum of even number:%d\n\n",evensum);

return 0;
}
Exercise 4
#include <stdio.h>
int main()
{
int i;

for(i=1;i<=10;i++)
{
if (i < 5 && i != 2)
printf("X");
}
return 0;
}
Exercise 5
#include<stdio.h>
int main()
{
int w,d;
for(w=1;w<=2;w++)
{
printf("week: %d\n",w);
for(d=1;d<=7;d++)
printf("\tday: %d\n",d);

}
return 0;
}
Exercise 6
#include<stdio.h>
int main()
{
int w,odd,d;
for(w=1;w<=2;w++)
{
printf("week: %d\n",w);
for(d=1;d<=7;d++)
{
odd=d%2;
if(odd==0)
continue;
printf("\tday: %d\n",d);
}
}
return 0;
}
Exercise 7
#include<stdio.h>
int main()
{
int input=1,num,sum=0;

while(input)
{
if(num<0)
break;
{
printf("Enter a number:");
scanf("%d",&num);
if(num>=0)
sum+=num;
}
input++;
}
printf("sum:%d",sum);
return 0;
}

You might also like