Sei sulla pagina 1di 13

NFC Institute of Engineering&Fertilizer

Research Faisalabad

Department of Electrical Engineering


Second Semester
Course Title:
Programming Fundamentals
Topic:
Programming Assignments
Submitted To:
Engr. Salman Arain
Submitted By:
Hafeez Ali
Roll.No:
18-ELE-43
Reg.#:
2018-UET-NFC-FD-ELECT-43
Assignment.No.1
Task#1
Write a C program that declares three variables (a, b, c), assigns the values 5, 7, 9 (
respectively), and calculates the sum of them. Modify the program to read the values on
the keyboard, means it should ask the integers from the user. Input:

Output:

Task#2
Write a program to calculate the remainder of the division of two integers. Use the
modulus operator (%).
Input:

Output:
Task#3
Write a generalized program to calculate the average between 4 numbers. The program
should ask the numbers from the user.
Input:

Output:

Task#4
Write a program that asks the user to enter two numbers obtains the two numbers from
the user and prints the sum, product, difference, quotient and remainder of the two
numbers.
Input:
Output:

Task#5
Find the errors in the following code, Kindly mention the errors with marking
1 int main (void)
2 {
3 it radius, circum;
4 print(type the radius);
5 scanf("%d",&radius);
6 circum=2*PI*radius
7 printf("%f",circum);
8 getch();
9 return 0;
10 }

Errors:
#include <stdio.h> is missing in the start of program.
In line 3 the int is not properly typed.
In c language “printf” use for output however in line 4 print is used and statement should be
typed with commas.
In line 6 the “PI” variable is not defined in the program and ; is missing in the end. The
circum should be declared as a float in the start in order to print in line 7.
Corrected Program:

Output:

Task#6
Write a program that reads an integer and determines and prints whether it’s odd or
even. Input:

Output:
Task#7
Write a program that ask for a temperature in the Fahrenheit scale and transforms it
into the Celsius scale. (NOTE: Celsius = (Fahrenheit – 32) * 5 / 9).
Input:

Output:

Task#8
Write a program that reads in five integers and then determines and prints the largest
and the smallest integers in the group. Use only the programming techniques you have
learned in Lecture 1.
Input:
Output:

Task#9
Write a program using increment and decrement operators only to give output like
223221.
Input:

Output:

Task#10
Using the relational operators write a program that will give output like 111.
Input:

Output:
Task#11
While purchasing an item, discount of 10% is offered if the purchasing amount is more
than 1000. If quantity and price per item are input through keyboard, write a program
to calculate total expenses.
Input:

Output:

Task#12
Write a program that will calculate the roots of a quadratic equation.
Input:
Output:

Task#13
If the ages of Ali, Ahmed and Mustafa are input by the user, write a program to
determine the youngest of the three.
Input:

Output:

Task#14
A library charges a fine for every book returned late for first five days is 50 rupees/day.
From 6th to 10th day fine is 100 rupees/day and above 10 days is 200 rupees/day and if
you returned the book after 30 days then your membership will be cancelled. Write a
program that accept the numbers of days a student is late in returning the books and
prints the appropriate message.
Input:

Output:

Task#15
Write a program to find the greater number from the two numbers that are inputted
by the user using conditional operator.
Input:

Output:
Task#16
Given a point (x,y), write a program to find if it lies on x axis, y axis, or on the origin.
Input:

Output:

Task#17
If five digits are input through the keyboard, write a program to find the sum of the
digits.
Input:

Output:
Task#18
Write a code to check, if a year entered by the user is a leap year or not.
Input:

Output:

Task#19
Write a C Program to Find the Largest Number among Three Numbers.
Input:

Output:
Task#20
Write a C program to check if a number is prime or not.
Input:

Output:

Potrebbero piacerti anche