0% found this document useful (0 votes)
6 views

PPS Lab Solution

Uploaded by

razorbladefree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

PPS Lab Solution

Uploaded by

razorbladefree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

#include <stdio.

h>

int main() {

// Print the top line of asterisks

printf("###########################################################\n");

// Print the welcome message and menu options

printf("Welcome!\n\n");

printf("Please choose a number from the following options:\n");

printf("1. Play the game!\n");

printf("2. Demo the game!\n");

printf("3. Exit\n\n");

// Print the bottom line of dollar signs

printf("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");

return 0;

#include <stdio.h>

int main() {

// Variables to store the scores

int quiz1, quiz2, quiz3, midTerm, finalExam, quizTotal, totalScore;

// Quizzes section

printf("=======Quizzes===============\n");
printf("Enter the score of the first quiz: ");

scanf("%d", &quiz1);

printf("Enter the score of the second quiz: ");

scanf("%d", &quiz2);

printf("Enter the score of the third quiz: ");

scanf("%d", &quiz3);

// Mid-term section

printf("=======Mid-term==============\n");

printf("Enter the score of the mid-term: ");

scanf("%d", &midTerm);

// Final section

printf("=======Final=================\n");

printf("Enter the score of the final: ");

scanf("%d", &finalExam);

// Calculate the totals

quizTotal = quiz1 + quiz2 + quiz3;

totalScore = quizTotal + midTerm + finalExam;

// Display the results

printf("Quiz Total: %d\n", quizTotal);

printf("Mid-term: %d\n", midTerm);

printf("Final: %d\n", finalExam);

printf("……………………\n");

printf("Total: %d\n", totalScore);

return 0;

}
#include <stdio.h>

int main() {

// Variables to store user input

char name[50];

char rollNumber[20];

char address[100];

int age;

float weight;

double height;

float cgpa;

// Taking inputs

printf("Enter Name of Student: ");

fgets(name, sizeof(name), stdin); // Using fgets to allow spaces in the name

printf("Roll Number: ");

fgets(rollNumber, sizeof(rollNumber), stdin); // Using fgets for roll number as well

printf("Enter Address: ");

fgets(address, sizeof(address), stdin); // Using fgets to allow spaces in the address

printf("Enter Age (in years): ");

scanf("%d", &age);

printf("Enter Weight (in kg): ");

scanf("%f", &weight);
printf("Enter Height (in meters): ");

scanf("%lf", &height);

printf("Enter CGPA/Percentage: ");

scanf("%f", &cgpa);

// Displaying the information

printf("\nName of Student: %s", name);

printf("Roll Number: %s", rollNumber);

printf("Percentage Score Secured: %.1f%%\n", cgpa);

printf("Age: %d years\n", age);

printf("Weight: %.2f kg\n", weight); // Displaying weight with 2 decimal points

printf("Height: %.2f meters\n", height); // Displaying height with 2 decimal points

printf("Address: %s", address);

return 0;

#include <stdio.h>

int main() {

// Variables to store user input

char name[50];

char rollNumber[20];

float ageYears, weightGrams, heightCm, cgpa;

int ageMonths;

float weightKg;

float heightMeters;
// Taking inputs

printf("Enter Name of Student: ");

fgets(name, sizeof(name), stdin);

printf("Roll Number: ");

fgets(rollNumber, sizeof(rollNumber), stdin);

printf("Age in years: ");

scanf("%f", &ageYears);

printf("Weight in grams: ");

scanf("%f", &weightGrams);

printf("Height in cm: ");

scanf("%f", &heightCm);

printf("Enter CGPA/percentage: ");

scanf("%f", &cgpa);

// Convert units

ageMonths = (int)(ageYears * 12); // Convert age to months

weightKg = weightGrams / 1000; // Convert weight to kilograms

heightMeters = heightCm / 100; // Convert height to meters

// Display the information

printf("\nName of Student: %s", name);

printf("Roll Number: %s", rollNumber);

printf("Age in months: %d months\n", ageMonths);

printf("Weight in Kilogram: %.0f\n", weightKg); // Display weight as an integer

printf("Height in meters: %.2f\n", heightMeters);

printf("Percentage Score Secured: %.1f%%\n", cgpa);


return 0;

#include <stdio.h>

int main() {

// Variables to store input

long int hours, minutes, seconds;

long int totalSeconds;

// Taking inputs

printf("Enter hours: ");

scanf("%ld", &hours);

printf("Enter minutes: ");

scanf("%ld", &minutes);

printf("Enter seconds: ");

scanf("%ld", &seconds);

// Calculating total seconds

totalSeconds = (hours * 3600) + (minutes * 60) + seconds;

// Displaying the result

printf("Total: %ld seconds.\n", totalSeconds);

return 0;

}
#include <stdio.h>

int main() {

// Variables to store the input and results

double x, y;

double p, s, total;

// Step a: Read x

printf("Enter the value of x: ");

scanf("%lf", &x);

// Step b: Read y

printf("Enter the value of y: ");

scanf("%lf", &y);

// Step c: Compute p = x * y

p = x * y;

// Step d: Compute s = x + y

s = x + y;

// Step e: Compute total = s^2 + p * (s - x) * (p + y)

total = (s * s) + p * (s - x) * (p + y);

// Step f: Print total

printf("Total: %.2f\n", total);

return 0;

}
#include <stdio.h>

int main() {

// Variable to store temperature in Celsius

float celsius;

// Variable to store temperature in Fahrenheit

float fahrenheit;

// Prompt user for input

printf("Enter temperature in degrees Celsius: ");

scanf("%f", &celsius);

// Convert Celsius to Fahrenheit

fahrenheit = (celsius * 9/5) + 32;

// Print the result

printf("Temperature in degrees Fahrenheit: %.2f\n", fahrenheit);

return 0;

#include <stdio.h>

int main() {

// Declare a constant variable for the conversion factor

const int cv = 32;


// Variable to store temperature in Celsius

float celsius;

// Variable to store temperature in Fahrenheit

float fahrenheit;

// Prompt user for input

printf("Enter temperature in degrees Celsius: ");

scanf("%f", &celsius);

// Convert Celsius to Fahrenheit using the constant cv

fahrenheit = (celsius * 9 / 5) + cv;

// Print the result

printf("Temperature in degrees Fahrenheit: %.2f\n", fahrenheit);

return 0;

#include <stdio.h>

int main() {

// Display a statement at the start of the program

printf("Dollar amount formatted to two decimal places\n");

// Variables to store input values

int numberOfShares;

float purchasePrice, currentPrice, profit;


// Get the number of shares purchased

printf("Enter the number of shares purchased: ");

scanf("%d", &numberOfShares);

// Get the purchase price per share

printf("Enter the price of the stock (per share) when purchased: ");

scanf("%f", &purchasePrice);

// Get the current price per share

printf("Enter the current price of the stock (per share): ");

scanf("%f", &currentPrice);

// Calculate the profit

profit = (numberOfShares * currentPrice) - (numberOfShares * purchasePrice);

// Display the profit and other information

printf("You have made a profit of $%.2f dollars since you bought %d shares of this stock.\n", profit,
numberOfShares);

return 0;

You might also like