KEMBAR78
Danyal Programming Fund Assig | PDF | Namespace | Onomastics
0% found this document useful (0 votes)
7 views10 pages

Danyal Programming Fund Assig

The document contains a series of C++ programming assignments focused on fundamental concepts such as conditional statements. It includes programs to check if a number is positive, negative, or zero, find the largest of three numbers, determine if a year is a leap year, check divisibility by 5 and 7, and assign grades based on marks. Each program is accompanied by code snippets demonstrating the implementation of the described functionality.

Uploaded by

abbasisaim480
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)
7 views10 pages

Danyal Programming Fund Assig

The document contains a series of C++ programming assignments focused on fundamental concepts such as conditional statements. It includes programs to check if a number is positive, negative, or zero, find the largest of three numbers, determine if a year is a leap year, check divisibility by 5 and 7, and assign grades based on marks. Each program is accompanied by code snippets demonstrating the implementation of the described functionality.

Uploaded by

abbasisaim480
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/ 10

1

PROGRAMMING FUNDAMENTAL:

PROGRAMMING FUNDAMENTAL LAB ASSIGNMENT


NAME = DANYAL AYUB ABBASI

STUDENT ID = 41223

PROGRAM= BS (SE)

• WRITE A C++ PROGRAM TO CHECK WHEATHER A GIVEN NUMBER


IS POSITIVE , NEGATIVE OR ZERO USING if – else statement .

#include <iostream>

using namespace std;

int main() {

int number ;

cout << "Enter a number : ";

cin >> number;

if (number > 0) {

cout << "The number is positive\n";

else if (number < 0){

cout << "The number is neagative\n";

}
1
PROGRAMMING FUNDAMENTAL:

else {

cout <<"The number is zero\n";

return 0;

}
1
PROGRAMMING FUNDAMENTAL:

• WRITE A PROGRAM TO FIND THE LARGEST AMONG THREE NUMBERS


USING nested-if statements.

#include <iostream>

using namespace std ;

int main (){

int num1,num2,num3;

cout << "Enter first number:\n";

cin >> num1;

cout << "Enter second number:\n";

cin >> num2;


1
PROGRAMMING FUNDAMENTAL:

cout << "Enter third number:\n";

cin >> num3;

if (num1 >= num2){

if (num1 >=num3){

cout << "The largest number is :"<<num1<<endl;

} else {

cout << "The largest number is :"<<num3<<endl;

}else{

if (num2>=num3){

cout << "The largest number is :"<<num2<<endl;

}else{

cout << "The largest number is :"<<num3<<endl;

return 0;

}
1
PROGRAMMING FUNDAMENTAL:

• CREATE A PROGRAM TO DETERMINE WHEATHER A GIVEN YEAR


IS A LEAP YEAR OR NOT USING if-else STATEMENTS.

#include <iostream>

using namespace std;

int main() {

int year;

cout<<("Enter a year: ");

cin>>(year);

if (year % 400 == 0) {

cout<<("%dis a leap year.", year);


1
PROGRAMMING FUNDAMENTAL:

else if (year % 100 == 0) {

cout<<("%dis not a leap year.", year);

else if (year % 4 == 0) {

cout<<("%dis a leap year.", year);

else {

cout<<("%dis not a leap year.", year);

return 0;

}
1
PROGRAMMING FUNDAMENTAL:

• WRITE A C++ PROGRAM THAT TAKES AN INTEGER AS INPUT AND


CHECKS IF IT IS DIVISIBLE BY BOTH 5 AND 7 USING if STATEMENT.

#include <iostream>

using namespace std ;

int main (){

int number;

cout << "Enter the number:\n";

cin >> number;

if (number%5==0&&number%7==0){

cout << number << " is divisible by both 5 and 7." << endl;
1
PROGRAMMING FUNDAMENTAL:

}else{

cout << number << " is not divisible by both 5 and 7." << endl;

return 0;

• IMPLEMENT A PROGRAM TO DETERMINE THE GRADE OF A


STUDENT BASED ON THEIR MARKS USING if-else LADDER .

#include <iostream>

using namespace std ;

int main (){

int marks;

cout << "Enter the marks :\n";


1
PROGRAMMING FUNDAMENTAL:

cin >> marks;

if (marks>=90&&marks<=100){

cout <<" Grade: A "<<endl;

else if (marks>=80&&marks<90){

cout << "Grade: B"<<endl;

else if (marks >=70&&marks <80){

cout << "Grade: c"<<endl;

else if (marks >=60&&marks <70){

cout << "Grade: D\n";

else if (marks >=0&&marks <60){

cout << "Grade: F [fail}\n";

else {

cout <<" invalid marks entered. Marks should be between 0 and


100."<<endl;

}
1
PROGRAMMING FUNDAMENTAL:

return 0;

You might also like