Professional Documents
Culture Documents
Start: Introduction To Programming GENG 200 Homework 1
Start: Introduction To Programming GENG 200 Homework 1
Homework 1
Problem 1.
A. Draw a flowchart to get a number from the user that represents the total number of
seconds. Then find and display: hours, minutes and remaining seconds.
B. Write a C program to solve part A above. (Note that in this part you have to use / and
% operators, do not use any subtraction operation).
Start
Compute:
Hours = T / (3600)
Minutes = (T%3600)/60
Remaining seconds = (T
%3600)%60
End
B
/*
Name
: Hasna Saif Alshamsi
ID
: 201404246
Section : sec No.62
Homeworh# : 1
*/
#include <stdio.h>
int main()
{
//1.Declaring all the variables.
int T,Houres,Minutes,Remaining_Seconds;
//2.get the total number of seconds, T.
printf("Enter the total number of seconds: ");
scanf("%d", &T);
//3.calculate the number of Hours, Minutes and the Remaining Seconds.
Houres = T/(3600);
Minutes = (T%3600)/60;
Remaining_Seconds = (T%3600)%60;
//4.display hours, minutes and the Remaining Seconds.
printf("houres = %d\n", Houres);
printf("minutes = %d\n", Minutes);
printf("Remaining Seconds = %d\n", Remaining_Seconds);
return 0;
}
#include <stdio.h>
#define Gravity 9.80
#define Efficiency 90/100
int main()
{
//1.Declaring all the variables.
int h;
double f;
double gravityPower;
double electricalPower;
//2.enter the values of the haight dam and the water flow.
printf("enter the hight of the dam in meters:");
scanf("%d",&h);
printf("enter the water flow in Meters^3/Sec :");
scanf("%lf", &f);
#include <stdio.h>
int main()
{
//1.Declaring all the variables.
int n,m;
double side1,side2,hypotenuse;
//2.enter positve values for n and m (m > n), and display them.
printf("Enter positive integer for n: ");
scanf("%d",&n);
return 0;
}
Problem 4. Write a program that gets an integer number between 0 and 999. Then the
program should display individual digits of the number and their sum.
Hint: Consider the number 123. To get ones digit use: 123%10 = 3 and to remove the
digit from the number use: 123/10 = 12. Repeat to get tens and hundreds digits.
#include <stdio.h>
int main()
{
//1.Declaring all the variables.
int
int
int
int
num;
x1,x2,x3;
Remaining_digit;
sum;
Remaining digit
x1 = num %10;
Remaining_digit = num /10;
x2 = Remaining_digit %10;
x3 = Remaining_digit /10;
sum = x1 + x2 + x3;
//4.display the ones digit, tens digit, hundreds digit,and the sum of all of
them.
printf("\nones digit = %d\n", x1);
printf("tens digit = %d\n", x2);
printf("hundreds digit = %d\n", x3);
printf("\nThe sum of the number one digit ten digit and hundred digit =
%d\n", sum);
return 0;
}