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

Assignment 1 Input and Output

assignment

Uploaded by

areejabid2004
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Assignment 1 Input and Output

assignment

Uploaded by

areejabid2004
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

ALPHACOACHINCENTRE

R-415 sector 10 n.karachi (Cont. #


031686486)
Assignment 1
Subject: Computer Topic: Input & Output
Class: SECOND YEAR -XII Instructor: Sir Moiz

Q1. Write a C program that prompts the user to print a string.

Q2. Identify and correct the errors in the code below to ensure it correctly reads two integer inputs
from the user and calculates their sum.

1. #include <stdio.h>
2. Int main()
3. {
4. int num1, num2;
5. printf("Enter first number: ");
6. scanf("%d", num1);
7. printf("Enter second number: ")
8. scanf("%d", num2);
9. sum = num1 + num2;
10.printf("Sum: %d\n", sum);
11.}

Q3. Write a C program that prompts the user to enter the length and width of a rectangle. The
program should then calculate and display the area of the rectangle.

Q4. What is the output of the following C program if the user inputs the integers 14 and 7?

1. #include <stdio.h>
2. int main() {
3. int num1, num2;
4. printf("Enter two integers: ");
5. scanf("%d %d", &num1, &num2);
6. int average = (num1 + num2) / 2;
7. printf("The integers entered are: %d and %d\n", num1, num2);
8. printf("The average of the two integers is: %d\n", average);
9. return 0;
10.}
Q5. Write a C program to calculate the force given the mass and acceleration. The formula to
calculate force is Force= Mass × Acceleration. Prompt the user to enter the mass (in kilograms)
and acceleration (in meters per second squared).
Q6. What is the output of the following C program if the user inputs a length of 7.0 and a width of
3.5?
1. #include <stdio.h>
2. int main() {
3. float length, width, perimeter;
4. printf("Enter the length of the rectangle: ");
5. scanf("%f", &length);
6. printf("Enter the width of the rectangle: ");
7. scanf("%f", &width);
8. float lengthPlusWidth = length + width;
9. float doubleLengthPlusWidth = 2 * lengthPlusWidth;
10. perimeter = doubleLengthPlusWidth;
11. printf("The perimeter of the rectangle is: %.2f\n", perimeter);
12. return 0;
13. }

You might also like