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

Programming Fundamentals (Cs-116T) Assignment 1

1. This document contains an assignment for a programming fundamentals course. It includes 5 questions about basic C++ programming concepts like input/output, conditional statements, and mathematical functions. The student is asked to write code to solve each problem, provide sample input/output, and verify the output using a compiler. 2. The questions cover topics like conditional execution based on if/else statements, checking divisibility of numbers, validating triangles based on side lengths, calculating ceil and floor of floating point numbers. 3. For each question, the student has provided the required C++ code, sample input/output and expected output.

Uploaded by

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

Programming Fundamentals (Cs-116T) Assignment 1

1. This document contains an assignment for a programming fundamentals course. It includes 5 questions about basic C++ programming concepts like input/output, conditional statements, and mathematical functions. The student is asked to write code to solve each problem, provide sample input/output, and verify the output using a compiler. 2. The questions cover topics like conditional execution based on if/else statements, checking divisibility of numbers, validating triangles based on side lengths, calculating ceil and floor of floating point numbers. 3. For each question, the student has provided the required C++ code, sample input/output and expected output.

Uploaded by

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

PROGRAMMING

FUNDAMENTALS (CS-116T)
Assignment 1
• NAME: SHAIKH NEHAL AHMED
• ROLL NO.: 028
• Batch: 2020
• Department: IT
Question 1
What will be output of following codes, first solve it on page, and then verify it from visual studio compiler.

Question a)

#include<iostream>

using namespace std;

int main( )
{
int a = 300, b, c ;

if ( a >= 400 )
b = 300 ;
c = 200 ;

cout<<"b= "<<b<<"c= "<

return 0;
}

OUTPUT:

b= c=200
Question b)

#include<iostream>
using namespace std;
int main( ){

int x = 3, y = 5 ;

if ( x == 3 )
cout<<x<<" ";
else ;
cout<<y;

return 0;
}

• OUTPUT:

•3
Question c)

#include<iostream>
using namespace std;
int main( )
{

int x = 3, y, z ;

y = x = 10 ;
z = x < 10 ;

cout<<"x= "<<x<<", y= "<<y<<", z= "<<z;

return 0;
}

• OUTPUT:

• X=10 Y=10 Z=0


Question 2
1. If cost price and selling price of an item is input through the keyboard, write a program to determine whether
the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred.

INPUT:
#include <iostream>
using namespace std;
int main()
{
float cost, sell, loss, profit;

cout << "enter the cost price of an item: "; • OUTPUT:


cin >> cost;
cout << "enter the selling price of an item: ";
cin >> sell;

if (cost > sell)


{
loss = cost - sell;
cout << "seller has incurred loss of an item" << endl;
cout << "loss of an item seller incurred: " << loss;
}
else if (cost == sell)
cout << "seller has neither made profit nor incurred loss";
else if(sell>cost)
{
profit = sell - cost;
cout << "seller has made profit out of an item" << endl;
cout << "profit of an item seller gained: " << profit;
}
return 0;
}
2. Write a program that takes number X and Y from user. Your program checks whether Y is multiple of X or not. Example 16 is
multiple of 4, 20 is multiple of 10, 25 is not multiple of 10 etc.

INPUT:
#include <iostream>
using namespace std;
int main()
{
int X, Y; • OUTPUT:
cout << "please enter X value: ";
cin >> X;
cout << "please enter Y value: ";
cin >> Y;

if (X % Y == 0)
cout << "Y is a multiple of X";
else
cout << "Y is not a multiple of X";

return 0;
}
3. If the three sides of a triangle are entered through the keyboard, write a program to check whether the triangle is valid or
not. The triangle is valid if the sum of two sides is greater than the largest of the three sides.

INPUT:
#include <iostream>
#include<conio.h>
using namespace std;
int main()
• OUTPUT:
{
int a, b, c;

cout << "enter three triangle sides (a): ";


cin >> a;
cout << "b: ";
cin >> b;
cout << "c: ";
cin >> c;

if ((a + b > c) && (a + c > b) && (b + c > a))


cout << "Triangle is valid";
else
cout << "triangle is not valid";

return 0;
}
4. Write a program which takes as input a floating number and prints its ceiling Integer.

INPUT:
#include <iostream> • OUTPUT:
#include<conio.h>
#include<math.h>
using namespace std;
int main()
{
float number;

cout << "enter any number: ";


cin >> number;
cout << "ceiling integar is: " <<
ceil(number);
}
5. Write a program which takes as input a floating number and prints its floor value.

Input:
#include <iostream>
#include<conio.h>
#include<math.h> • OUTPUT:
using namespace std;
int main()
{
float number;

cout << "enter any number: ";


cin >> number;
cout << "floor integar is: " <<
floor(number);
}

You might also like