1.
#include <stdio.h>
#define minute 60
int main (void)
{
int Minute;
printf ("Please input time in minute: \n");
scanf ("%d", &Minute);
while(Minute > 0)
{
printf ("time is %d : %d\n", Minute / minute, Minute % minute);
printf ("Please input time in minute: \n");
scanf ("%d", &Minute);
}
return 0;
}
2.
#include <stdio.h>
int main (void)
{
int num;
int i;
printf ("Please input a number: ");
scanf ("%d", &num);
for (i = 0; i <= 10; i++)
{
printf ("%d\n", num + i);
}
return 0;
}
3.
#include <stdio.h>
#define days 7
int main (void)
{
int day;
printf ("Please input days: ");
scanf ("%d", &day);
while (day > 0)
{
printf ("%d days are %d weeks, %d days.\n", day, day / days, day %days);
printf ("Please input days: ");
scanf ("%d", &day);
}
return 0;
}
4.
#include <stdio.h>
#define inch 2.54
int main (void)
{
float height;
printf ("Enter a height in centimeters: ");
scanf ("%f", &height);
while (height > 0)
{
printf ("%.1f cm = %d feet, %.1f inches\n", height, (int)(height / inch / 12), height / inch - (int)(height / inch / 12) * 12);
printf ("Enter a height in centimeters (<=0 to quit): ");
scanf ("%f", &height);
}
return 0;
}
5.
#include <stdio.h>
int main (void)
{
int day, sum = 0;
int i;
printf ("Please input days: ");
scanf ("%d", &day);
for (i = 1; i <= day; i++)
{
sum += i;
}
printf ("sum = %d", sum);
return 0;
}
6.
#include <stdio.h>
int main (void)
{
int day, sum = 0;
int i;
printf ("Please input days: ");
scanf ("%d", &day);
for (i = 1; i <= day; i++)
{
sum += i * i;
}
printf ("sum = %d", sum);
return 0;
}
7.
#include <stdio.h>
double cube(double num);
int main (void)
{
double num;
printf ("Please input a num: ");
scanf ("%lf", &num);
printf ("The cube of %lf is %lf", num, cube(num));
return 0;
}
double cube(double num)
{
return num * num * num;
}
8.
#include <stdio.h>
int main (void)
{
int a, b;
printf ("This program computes moduli.\n");
printf ("Enter am integer to serve as the second operand: ");
scanf ("%d", &a);
printf ("Now enter the first operand: ");
scanf ("%d", &b);
while (b > 0)
{
printf ("%d %% %d is %d\n", b, a, b % a);
printf ("Enter next number for first operand (<= 0 to quit): ");
scanf ("%d", &b);
}
return 0;
}
9.
#include <stdio.h>
void Temperatures (double F);
int main (void)
{
double F;
printf ("Enter a temperature: ");
while (scanf ("%lf", &F))
{
Temperatures (F);
printf ("Enter a temperature(Enter 'q' to quit): ");
}
return 0;
}
void Temperatures (double F)
{
double K, C;
const double a = 5.0 / 9.0, b = 32.0, c = 273.16;
C = a * (F - b);
K = C + c;
printf ("F: %.2f\nC: %.2f\nK: %.2f\n", F, C, K);
return;
}