0% found this document useful (0 votes)
39 views4 pages

Laboratory Exercise: 1 Laboratory Exercise: 5

The document contains code for several C programming laboratory exercises, including exercises to calculate gross pay and commissions from sales, convert between different units of measurement, calculate a student's periodic grade based on test, quiz, and class standing grades, and store positive and negative numbers or odd and even numbers in separate arrays. The exercises demonstrate basic input/output functions, conditional statements, and arrays in C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

Laboratory Exercise: 1 Laboratory Exercise: 5

The document contains code for several C programming laboratory exercises, including exercises to calculate gross pay and commissions from sales, convert between different units of measurement, calculate a student's periodic grade based on test, quiz, and class standing grades, and store positive and negative numbers or odd and even numbers in separate arrays. The exercises demonstrate basic input/output functions, conditional statements, and arrays in C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

LABORATORY EXERCISE: 1 LABORATORY EXERCISE: 5

#include <stdio.h> #include <stdio.h>


int main() int main()
{ {
int R,H,GP,D,NP; float A,g,B,kg,C,m,D,km;
int Z;
printf("Enter Rate:");
scanf("%d",&R); printf("[1]Gram To Kilogram\n");
printf("Enter Hour:"); printf("[2]Kilogram To Gram\n");
scanf("%d",&H); printf("[3]Meter To Kilometer\n");
printf("[4]Kilometer To Meter\n");
GP=R*H; printf("\nEnter The Unit You Want to
printf("\n\nGross Pay:%d",GP); Convert:");
scanf("%d",&Z);
D=0.05*GP;
printf("\nDeduction is:%d",D);
switch(Z){
NP=GP-D; case 1:
printf("\nNet pay is:%d",NP); printf("Enter The Unit in Gram:");
scanf("%f",&g);
return 0; A=g/1000;
printf("%f gram is equal to %.2f
} Kilogram",g,A);
break;

case 2:
LABORATORY EXERCISE: 3 printf("Enter The Unit in
Kilogram:");
#include <stdio.h> scanf("%f",&kg);
int main() B=kg*1000;
{ printf("%f kilogram is equal to %.2f
float C,F; gram",kg,B);
break;
printf("Enter The Celcius:");
scanf("%f",&C); case 3:

F=C*9/5+32; printf("Enter The Unit in Meter:");


printf("%.0f Celcius is equivalent to %.1f scanf("%f",&m);
Farenheit",C,F); C=m/1000;
printf("%f Meter is equal to %.2f
return 0; Kilometer",m,C);
} break;

case 4:

printf("Enter The Unit in


kilometer:");
LABORATORY EXERCISE: 4 scanf("%f",&km);
D=km*1000;
#include <stdio.h> printf("%f Kilometer is equal to
int main() %.2f meter",km,D);
{ break;
float ptg, aqg, csg, pg;

printf("Enter Your Periodic Test Grade:"); default:


scanf("%f",&ptg);
printf("Enter Your Average Quiz Grade:"); printf("Sorry Not Available
scanf("%f",&aqg); Conversion");
printf("Enter Your Class Standing Grade:"); }
scanf("%f",&csg); return 0;
pg=(ptg*.4) + (aqg*.3) + (csg*.3); }
printf("Your Periodic Grade is %.1f", pg);
if (pg>=75)
{
printf("\nPassed!");
}
else
{
printf("\nFailed!");
}
return 0;
}
com=PR*0.06;
LABORATORY EXERCISE: 6 printf("\nComission is %.1f",com);}
else if (PR>=5000 && PR<=8000){
#include <stdio.h> com=PR*0.08;
int main() printf("\nComission is %.1f",com);}
{
char PO; int PR, num; float com; else{
com=PR*0.1;
printf("\t\t\t\tPrice List\n\n"); printf("\nComission is %.1f",com);}
printf("\tProduct No.\t\t Product
Name\t\tPrice\n\n"); }
printf("\t 1\t\t\tProduct if (PO=='D'||PO=='d')
A\t\t750.00\n\n"); {
printf("\t 2\t\t\tProduct printf("\nQuantity:");
B\t\t599.00\n\n"); scanf("%d",&num);
printf("\t 3\t\t\tProduct PR=1200*num;
C\t\t645.00\n\n"); printf("\nAmount Sold is %d",PR);
printf("\t 4\t\t\tProduct
D\t\t1200.00\n\n"); if (PR<1000){
printf("\nEnter The Product Ordered:"); com=PR*0.05;
scanf("%c",&PO); printf("\nComission is %.1f",com);}
else if (PR>1000 && PR<5000){
com=PR*0.06;
if (PO=='A'||PO=='a'){ printf("\nComission is %.1f",com);}
printf("\nQuantity:"); else if (PR>=5000 && PR<=8000){
scanf("%d",&num); com=PR*0.08;
PR=750*num; printf("\nComission is %.1f",com);}
printf("\nAmount Sold is %d",PR);
else{
if (PR<1000){ com=PR*0.1;
com=PR*0.05; printf("\nComission is %.1f",com);}
printf("\nComission is %.1f",com);} }
else if (PR>1000 && PR<5000){
com=PR*0.06;
printf("\nComission is %.1f",com);}
else if (PR>=5000 && PR<=8000){ return 0;
com=PR*0.08; }
printf("\nComission is %.1f",com);}

else{
com=PR*0.1;
printf("\nComission is %.1f",com);}
}

if (PO=='B'||PO=='b')
{
printf("\nQuantity:");
scanf("%d",&num);
PR=599*num;
printf("\nAmount Sold is %d",PR);

if (PR<1000)
{
com=PR*0.05;
printf("\nComission is %.1f",com);}
else if (PR>1000 && PR<5000){
com=PR*0.06;
printf("\nComission is %.1f",com);}
else if (PR>=5000 && PR<=8000){
com=PR*0.08;
printf("\nComission is %.1f",com);}

else{
com=PR*0.1;
printf("\nComission is %.1f",com);}
}

if (PO=='C'||PO=='c')
{
printf("\nQuantity:");
scanf("%d",&num);
PR=645*num;
printf("\nAmount Sold is %d",PR);

if (PR<1000){
com=PR*0.05;
printf("\nComission is %.1f",com);}
else if (PR>1000 && PR<5000){
Array: Positive & Negative Array: Odd & Even
#include <stdio.h>
#include <stdio.h> int main()
{
int main(){ int a[20],n,e;

int list[20], pos[20], neg[20], x, y, num; printf("Input the number of element to be


stored in the array:");
printf("Enter number of elements to be stored: "); scanf("%d",&n);
scanf("%d", &x);
printf("Enter %d elements to array: \n", x);
printf("Input %d elements in the
for(y=0; y<=(x-1); y++){ array:\n\n",n);
printf("element-%d: ", y); for(e=0;e<=(n-1);e++){
scanf("%d", &num); printf("element- [%d]:",e);
scanf("%d",&e[a]);
if(num > 0){ }
pos[y] = num;
neg[y] = 0;
} printf("\n\nThe elements stored in the
array are:\n");
if(num < 0){ for(e=0;e<=(n-1);e++){
neg[y] = num; printf("[%d] ", e[a]);
pos[y] = 0; }
}
printf("\n\nThe even numbers in array
} are:\n\n");
for(e=0;e<=(n-1);e++){
printf("\n"); if(e[a] % 2==0){
printf("Positive elements are: "); printf("[%d] ",e[a]);
for(y=0; y<=(x-1); y++){ }
if(pos[y]>0){ }
printf("%d ", pos[y]); printf("\n\nThe odd numbers in array
} are:\n\n");
for(e=0;e<=(n-1);e++){
} if(e[a] % 2!=0){
printf("\n"); printf("[%d] ",e[a]);
printf("Negative elements are: "); }
for(y=0; y<=(x-1); y++){ }
if(neg[y]<0){
printf("%d ", neg[y]); return 0;
}
} }
return 0;
}

Array: Reverse
#include <stdio.h>
int main()
{
int a[20],n,e;

printf("Input the number of element to be


stored in the array:");
scanf("%d",&n);

printf("Input %d elements in the


array:\n\n",n);
for(e=0;e<=(n-1);e++){
printf("element- [%d]:",e);
scanf("%d",&e[a]);
}

printf("\n\nThe elements stored in the


first array are:\n");
for(e=0;e<=(n-1);e++){
printf("[%d] ", e[a]);
}
printf("\n\nThe elements stored in the
reverse array are:\n");
for(e=(n-1);e>=0;e--){
printf("[%d] ", e[a]);
}

return 0;
}
Strings: Concatenate

#include <stdio.h>
#include <string.h>

int main()
{
char j[20];
char n[20];

printf("Please Enter the First Strings:");


gets(j);

printf("\n\nPlease Enter The Second


Strings:");
gets(n);

if(strcmp(j,n)!=0){
strcat(j,n);
printf("\n%s ",j);
}

else{
printf("\nThey Are equal");
}

return 0;
}

Reverse String
#include <stdio.h>
#include <string.h>
int main()
{
char word[20];int x,y;

printf("Enter a word: ");


gets(word);

y=strlen(word);

printf("That word in reverse is ");


for(x=(y-1);x>=0;x--){
printf("%c", word[x]);
}
return 0;
}

You might also like