You are on page 1of 12

Sitwork 3

1.

#include <stdio.h>

#include <string.h>

void main()

int kilowatt;

float chg, payment, surtax,total;

char connm[25];

printf("NICOLJEN MANGUBAT BSCE-1\n");

printf("Input the unit consumed by the customer : ");

scanf("%d",&kilowatt);

if (kilowatt <= 250 )

chg = 7.50;

else if (kilowatt>200)

chg = 8.50;

payment = kilowatt*chg;

surtax = payment*.10;

total = payment+surtax;

printf("Total Amount Paid By the Customer: %.2f\n",total);

}
2.

#include<stdio.h>

int main(){

char code;

float gallon, charge;

printf("NICOLJEN MANGUBAT BSCE-1\n");

printf("Enter code: ");

scanf("%c", &code);

printf("Enter gallon: ");

scanf("%f", &gallon);

switch(code){

case 'H':

charge = 250 + (0.002 * gallon);

break;

case 'C':

if(gallon <= 4000000)

charge = 5000.0;

else

charge = 5000.0 + (gallon - 4000000) * 0.002;

break;

case 'I':

if(gallon <= 4000000)

charge = 8000;

else if(gallon > 4000000 && gallon <= 10000000)


charge = 14000;

else if(gallon > 10000000)

charge = 18000;

break;

default:printf("Incorrect gallon");

printf("Amount due from the user: %.3f", charge);

return 0;

}
#include<stdio.h>

int main()

int commission, totalsale;

char name[20];

printf("NICOLJEN MANGUBAT BSCE-1\n");

printf("Salesman's name: ");

scanf("%[^\n]", &name);

printf("Total monthly sale: ");

scanf("%d", &totalsale);

if(totalsale==0)

{commission = totalsale*0;

printf("Total commission: %d", commission);}

else if(totalsale>0 && totalsale<10000)

{commission = totalsale*0.02;

printf("Total commission: %d", commission);}

else if (totalsale>=10000 && totalsale<25000)

{commission = totalsale*0.05;

printf("Total commission: %d", commission);}

else if (totalsale>=25000 && totalsale<50000)

{commission = totalsale*0.10;

printf("Total commission: %d", commission);}


else if (totalsale>=50000 && totalsale<75000)

{commission = totalsale*0.13;

printf("Total commission: %d", commission);}

else if (totalsale>=75000 && totalsale<100000)

{commission = totalsale*0.15;

printf("Total commission: %d", commission);}

else{commission = totalsale*0.20;

printf("Total commission: %d", commission);}

return 0;

}
#include<stdio.h>

int main()

int num, word;

char name[20], type;

float cost;

printf("NICOLJEN MANGUBAT BSCE-1\n");

printf("\nEnter Customer's name: ");

scanf("%[^\n]",&name);

printf("\nInput number of words used in the telegram: ");

scanf("%d", &word);

printf("\nInput type of delivery (S-Special) or (N-None): ");

scanf(" %c", &type);

cost=0;

if (word<=12){

cost=28.99;

if (type=='S' || type=='s'){

cost=cost+5.00;

}else if (word>12){

word=word-12;

cost=28.99+(word*2.50);

if (type=='S' || type=='s'){

cost=cost+5.00;

}
printf("\n\nTotal cost is %.2f", cost);

return 0;

1. Do, while loop

#include<stdio.h>

int main()

char name[20];

int num;

int ctr = 1;

int sum = 0;

printf("Enter name: ");

scanf("%s", &name);
do

printf("Enter number: ");

scanf("%d", &num);

sum = sum + num;

ctr++;

} while (ctr<=7);

printf("The sum is %d\n", sum);

printf("My name is %s\n", name);

printf("This is my seatwork about Loops.\n");

printf("June 2, 2022");

return 0;

2. WHILE LOOP

#include<stdio.h>

int main()

char name[20];

int num;

int ctr = 1;

int sum = 0;

printf("Enter name: ");

scanf("%s", &name);
while (ctr<=7)

printf("\nEnter number: ");

scanf("%d", &num);

sum = sum + num;

ctr++;

printf("\nThe sum is %d\n\n", sum);

printf("My name is %s.\n\n", name);

printf("This is my seatwork about Loops.\n\n");

printf("June 2, 2022");

return 0;

3. FOR LOOP

#include<stdio.h>

int main ()

int num;

int ctr=1;

int sum=0;

char Name [50];

printf("Enter name: ");


scanf("%s", &Name);

for (int ctr=1; ctr<=7; ctr++ )

printf("\nEnter number: ");

scanf("%d", &num);

sum=sum+num;

printf("\nThe sum is %d", sum);

printf("\n\nMy name is Erlan John.");

printf("\n\nThis is my seatwork about loops.");

printf("\n\nJune 2 2022");

return 0;

#include<stdio.h>

int main()

int num1,num2,c=0,s=0;

printf("NICOLJEN MANGUBAT BSCE-1\n");

printf("\nEnter the first number: ");

scanf("%d", &num1);

printf("\nEnter the second number: ");

scanf("%d", &num2);

printf("\n%d %d ", num1, num2);


while(c<10)

s=num1;

num1=num2;

num2=s + num1;

printf("%d ", num2);

c++;

return 0;

#include<stdio.h>

int main() {

int i,n;

int num=1,sum=0;

for(i=1; i<11; i++)

printf(" %d",num);

sum=sum+num;
num=num+i;

return 0;

You might also like