CS Programming
CS Programming
#include <stdio.h>
int main(){
char num[4];
int sum=0;
scanf("%3s",num);
return 0;
#include <stdio.h>
int main(){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
return 0;
#include <stdio.h>
int main(){
char num[4];
scanf("%3s",num);
#include <stdio.h>
#include <math.h>
int main(){
scanf("%lf",&mass1);
scanf("%lf",&mass2);
scanf("%lf",&d);
return 0;
PROBLEM 5. If you buy a 40 GB hard drive, then chances are that the actual storage
on the hard drive is not 40 GB. This is due to the fact that, typically, a manufacturer
uses 1000 bytes as the value of 1K bytes, 1000 K bytes as the value of 1 MB, 1 000
MB as the value of 1 GB. Therefore, a 40 GB hard drive contains 40 000 000 000
bytes. However, in computer memory, 1 KB = 1024 bytes, 1MB = 1024 KB and so on.
The units from the smallest to the largest are Byte, Kilobyte (KB), Megabyte (MB),
Gigabyte (GB), Terabyte (TB), Petabyte (PT), Exabyte (EB), Zettabyte (ZB). So the
actual storage on a 40 GB hard drive is approximately 37.25 GB. (You might like to
read the fine print next time you buy a hard drive.) Write a program that prompts
the user to enter the size of the hard drive specified by the manufacturer, on the
hard drive box, and outputs the actual storage capacity of the hard drive.
#include <stdio.h>
#include <math.h>
int main(){
printf("Enter size of the hard drive specified by the manufacturer (in GB): ");
scanf("%lf",&manufacturerGB);
actualBytes = manufacturerBytes;
printf("The actual storage capacity of the hard drive is approximately %.2f GB.\n", actualGB);
return 0;
#include <stdio.h>
#include <math.h>
int main(){
double a,b,c,discriminant,x1,x2,realpart,imaginarypart;
// Input a, b, c
printf("Enter a: ");
scanf("%lf",&a);
printf("Enter b: ");
scanf("%lf",&b);
printf("Enter c: ");
scanf("%lf",&c);
// Calculate discriminant
discriminant = b*b-4*a*c;
if(discriminant>0){
x1 = (-b + sqrt(discriminant))/(2*a);
x2 = (-b - sqrt(discriminant))/(2*a);
else if(discriminant==0){
x1 = -b/2*a;
else{
realpart = -b/(2*a);
imaginarypart = sqrt(-discriminant)/(2*a);
return 0;
PROBLEM 7.