1.
#include<stdio.h>
#define MIN 60
int main(void)
{
int a,b,c;
printf("Please enter minutes.\n");
scanf("%d",&a);
while (a > 0)
{
b = a / MIN;
c = a % MIN;
printf("%d minutes is %d hours and %d minutes.\n",a,b,c);
scanf("%d",&a);
}
return 0;
}
2.
#include <stdio.h>
int main(void)
{
int a,b;
printf("Please enter an interger.\n");
scanf("%d",&a);
b=a+11;
while (a<b)
{
printf("%d ",a);
a++;
}
return 0;
}
3.
#include<stdio.h>
#define WEEK 7
int main(void)
{
int a,b,c;
printf("Please enter number of days.\n");
scanf("%d",&a);
while (a > 0)
{
b = a / WEEK;
c = a % WEEK;
printf("%d days is %d weeks and %d days.\n",a,b,c);
scanf("%d",&a);
}
return 0;
}
4.
#include<stdio.h>
#define FEET 30.48
#define INCHES 2.54
int main(void)
{
int a;
float b,c;
printf("Enter a height in centimeters: ");
scanf("%f",&b);
while(b > 0)
{
a = b/FEET;
c = (b - a*FEET) /INCHES;
printf("%.1f cm = %d feet, %.1f inches\n",b,a,c);
printf("Enter a height in centimeters (<=0 to quit): ");
scanf("%f",&b);
}
printf("bye");
return 0;
}
5.
#include <stdio.h>
int main (void)
{
int count,sum,days;
count=0;
sum=0;
printf("Please enter days.\n");
scanf("%d",&days);
while (count++<days)
sum=sum+count;
printf("sum=%d\n",sum);
return 0;
}
6.
#include <stdio.h>
int main (void)
{
int count,sum,days;
count=0;
sum=0;
printf("Please enter days.\n");
scanf("%d",&days);
while (count++<days)
sum=sum+count*count;
printf("sum=%d\n",sum);
return 0;
}
7.
#include <stdio.h>
void cube(float n);
int main (void)
{
float count;
printf("Please enter a number of type float. \n");
scanf("%f",&count);
cube(count);
return 0;
}
void cube(float n)
{
printf("%f",n*n*n);
}
8.
#include <stdio.h>
int main (void)
{
int first, second, c;
printf("This program computer moduli.\n");
printf("Enter an interge to serve as the second operand:");
scanf("%d", &first);
printf("Now enter the first operand:");
scanf("%d", &second);
printf("%d %% %d is %d \n",second,first,second % first);
while(second>0)
{
printf("Enter an interge to serve as the second operand(<= 0 to quit):");
scanf("%d",&second);
if (second>0)
printf("%d %% %d is %d \n",second,first,second%first);
else
printf("Done\n");
}
return 0;
}
9.
#include <stdio.h>
void Temperatures(float Fahrenheit1);
int main (void)
{
float Fahrenheit1;
printf("Please enter Fahrenheit temperature: \n");
while(scanf("%f",&Fahrenheit1) == 1)
{
Temperatures(Fahrenheit1);
}
return 0;
}
void Temperatures(float Fahrenheit1)
{
const float C1 = 32.0;
const float C2 = 5.0 / 9.0 * (Fahrenheit1 - C1);
const float K1 = 273.16;
const float K2 = C2 + K1;
printf("Fahrenheit: %.2f Celsius:%.2f Kelvin:%.2f\n",Fahrenheit1,C2,K2 );
}