0% found this document useful (0 votes)
29 views27 pages

Ihsan ZZZZ

The document contains 24 programming questions and their solutions in C++. Each question includes the code for a C++ program to solve a problem, such as calculating area, distance, or time conversions. The programs demonstrate basic programming concepts like input/output, variables, operators, and conditional statements. The document lists the question number, program code, and expected output for each problem.

Uploaded by

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

Ihsan ZZZZ

The document contains 24 programming questions and their solutions in C++. Each question includes the code for a C++ program to solve a problem, such as calculating area, distance, or time conversions. The programs demonstrate basic programming concepts like input/output, variables, operators, and conditional statements. The document lists the question number, program code, and expected output for each problem.

Uploaded by

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

Programming exercise

NAME : Ihsan Ghani

ROLL NO : 23-CSE-10

DEPARTMENT : Computer Systems Engineering.

Programming question no1 :

#include<iostream>

#include<conio.h>

using namespace std;

int main()

char c='A';

int i=100;

float f=3.14;

cout<<"Welcome to programming!"<<endl;

cout<<"Character Value: "<<c<<endl;

cout<<"Integer Value: "<<i<<endl;

cout<<"Floating Point Value: "<<f<<endl;

return 0;

output of above program:


Programming question no 2

#include <stdio.h>

#include <math.h>

int main()

float radius;

float surface_area, volume;

cout<<"Enter radius of the sphere : \n";<<endl;

cin>>radius;

surface_area = 4 * (22/7) * radius * radius;

volume = (4.0/3) * (22/7) * radius * radius * radius;

cout<<"Surface area of sphere is: %.3f"<< surface_area<<endl;

cout<<"\n Volume of sphere is : %.3f"<< volume<<endl;

return 0;

Output of above program:


Programming question no 3 :

#include<iostream>

#include<conio.h>

#include<math.h>

using namespace std;

int main()

float a,b,c,s,area;

cout<<"Enter three sides of triangle:";

cin>>a>>b>>c;

s = (a+b+c)/2;

area = sqrt(s*(s-a)*(s-b)*(s-c));

cout<<"Area : "<<area<<endl;

return 0;

Output of above program:


Programming question no 4:

#include<iostream>

#include<conio.h>

using namespace std;

int main()

float miles, kilometers;

cout<<"Enter miles :"<<endl;

cin>>miles;

kilometers = miles/1.609;

cout<<"Kilometers :"<<kilometers<<endl;

return 0;

Output of above program:


Programming question no 5:

#include<iostream>

#include<conio.h>

using namespace std;

int main()

int n1, n2, n3, n4, sum, product;

float average;

cout<<"Enter 4 numbers: ";

cin>>n1>>n2>>n3>>n4;

sum=n1+n2+n3+n4;

average=sum/4.0;

product=n1*n2*n3*n4;

cout<<"Sum : "<<sum<<endl;

cout<<"Average : "<<average<<endl;

cout<<"Product : "<<product<<endl;

return 0;

Output of above program :

Programming question no 6 :
#include<iostream>

#include<conio.h>

using namespace std;

int main()

int ageInYears, ageInDays, ageInMonths;

cout<<"Enter your age in years: ";

cin>>ageInYears;

ageInMonths = ageInYears*12;

cout<<"Your age in months: "<<ageInMonths<<endl;

ageInDays = ageInYears*365;

cout<<"Your age in days :"<<ageInDays<<endl;

return 0;

Output of above program :

Programming question no 7 :

#include<iostream>

#include<conio.h>
#include<math.h>

using namespace std;

int main( )

int number, square, cube;

cout<<"Enter a number : ";

cin>>number;

square = pow(number,2);

cube = pow(number,3);

cout<<"Square : "<<square<<endl;

cout<<"Cube : "<<cube<<endl;

return 0;

Output of above program :

Programming question no 8 :

#include<iostream>

#include<conio.h>

using namespace std;

int main( )

{
int totalPages, pagesReadPerDay, noOfDays, pagesRead, pagesRemaining;

cout<<"Enter total pages of a book : ";

cin>>totalPages;

cout<<"Enter number of pages a person reads in one day : ";

cin>>pagesReadPerDay;

cout<<"Enter number of days a person has read the book : ";

cin>>noOfDays;

pagesRead = pagesReadPerDay * noOfDays;

cout<<"Total number of pages read by the person : "<<pagesRead<<endl;

pagesRemaining = totalPages - pagesRead;

cout<<"Total number of pages remaining : "<<pagesRemaining<<endl;

return 0;

Output of above program :

Programming question no 9 :

#include<iostream>

#include<conio.h>

using namespace std;

int main( )
{

int petrol, distance;

cout<<"Enter petrol in liters : ";

cin>>petrol;

distance = 5.3 * petrol;

cout<<"Distance : "<<distance<<" miles."<<endl;

return 0;

Output of above program :

Programming question no 10 :

#include<iostream>

#include<conio.h>

using namespace std;

int main( )

int noOfStudents, feePerStudent, totalFeeCollected;

cout<<"Enter total no. of students : ";

cin>>noOfStudents;
cout<<"Enter fee per student : ";

cin>>feePerStudent;

totalFeeCollected = noOfStudents * feePerStudent;

cout<<"Total fee collected from the class : "<< totalFeeCollected<<endl;

return 0;

Output of above program :

Programming question no 11:

#include<iostream>

#include<conio.h>

using namespace std;

int main( )

float F, C;

cout<<"Enter temperature in Farenheit : ";

cin>>F;

C = (5.0/9.0) * (F - 32);

cout<<"Temperature in Celsius : "<<C<<endl;

return 0;

}
Output of above program :

Programming question no 12 :

#include<iostream>

#include<conio.h>

using namespace std;

int main( )

int n, a, b, c;

cout<<"Enter a 3-digit number : ";

cin>>n;

a = n % 10;

n = n / 10;

b = n % 10;

n = n / 10;

c = n % 10;

cout<<c<<endl<<b<<endl<<a<<endl;

return 0;

}
Output of above program :

Programming question no 13 :

# include<iostream>

using namespace std ;

int main( )

cout<<"1\t2\t3\t4\t5\t\n6\t7\t8\t9\t10"<<endl;

return 0 ;

Output of above program :


Programming question no 14 :

#include<iostream>

#incule<conio.h>

using namespace std ;

int main( )

float volume,length,width,height;

cout<<"length\t:\t";

cin>>length;

cout<<"\nwidth\t:\t";

cin>>width;

cout<<"\nheight\t:\t";

cin>>height;

volume=length*width*height;

cout<<"\nvolume\t:\t"<<volume<<endl;

return 0 ;

Output of above program :


Programming question 15 :

#include<iostream>

#include<conio.h>

#include<math.h>

using namespace std;

int main( )

int x1, x2, y1, y2;

float distance;

cout<<"Enter x, y coordinate for point 1 : ";

cin>>x1>>y1;

cout<<"Enter x, y coordinate for point 2 : ";

cin>>x2>>y2;

distance = sqrt( pow(x2-x1,2) + pow(y2-y1,2) );

cout<<"Distance is: "<<distance;

getch();

return 0;

Output of above program :


Programming question no 16 :

#include<iostream>

using namespace std;

int main( )

int n1, n2, n3, n4;

cout<<"Enter three numbers : ";

cin>>n1>>n2>>n3;

n4 = n1;

n1 = n2;

n2 = n3;

n3 = n4;

cout<<"Values after swapping : ";

cout<<n1<<"\t"<<n2<<"\t"<<n3<<endl;

return 0;

Output of above program :

Programming question no 17 :

#include<iostream>
#include<conio.h>
using namespace std;
int main( )
{
float length, radius, angle;
cout<<"Enter radius of arc : ";
cin>>radius;
cout<<"Enter angle of arc : ";
cin>>angle;
length = radius * angle;
cout<<"Length of arc : "<<length<<endl;
return 0;
}

Output of above program :

Programming question no 18 :

#include<iostream>

#include<conio.h>

using namespace std;

int main( )

float pound, kilogram;

cout<<"Enter pounds : ";

cin>>pound;

kilogram = 2.205 * pound; // 1kg = 2.205 * pounds

cout<<"Kilograms for:\t "<<pound<<" \npounds is :\t "<<kilogram<<"kilograms."<<endl;


return 0;

Output of above program :

Programming question no 19 :

#include<iostream>

#include<conio.h>

using namespace std;

int main( )

// ((r*r)/2)*theta

float theta, radius, area;

cout<<"enter radius of circle :\t ";

cin>>radius;

cout<<"\nenter angle in radians between radii :\t ";

cin>>theta;

area = (theta/2)*radius*radius;

cout<<"\nArea of a sector of a circle :\t "<<area<<endl;

return 0;

Output of above tprogram :


Programming question no 20 :

#include<iostream>

#include<conio.h>

#include<math.h>

using namespace std;

int main( )

float number, logrithm;

cout<<"Enter a value: ";

cin>>number;

// logarith of x with base 2 = natural logarithm with base 10 of x / natural logarithm with base 10 of 2

logrithm=log10(number)/log10(2); //logarithm with base 2

cout<<"logarithm with base 2: "<<logrithm<<endl;

getch();

return 0;

Output of above program :


Programming question no 21 :

#include<iostream>

#include<conio.h>

using namespace std;

int main( )

char ch;

cout<<"enter a character : ";

cin>>ch;

cout<<"\n next two characters : ";

ch++;

cout<<ch<<"\t";

ch++;

cout<<ch<<"\t";

return 0;

Output of above program :

Programming question no 22 :

#include<iostream>

#include<conio.h>

using namespace std;

int main( )
{

int n;

cout<<"enter a five digit number : ";

cin>>n;

int a, b, c, d, e, sum=0;

a = n % 10;

n = n / 10;

b = n % 10;

n = n / 10;

c = n % 10;

n = n / 10;

d = n % 10;

n = n / 10;

e = n % 10;

sum = a + b + c + d + e;

cout<<"Sum of "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<" is : "<<sum<<endl;

return 0;

Output of above program :

Programming question no 23 :

#include<iostream>

#include<conio.h>

using namespace std;


int main( )

int basicSalary, grossSalary;

float da, hr; //dearness allowance, house rent

cout<<"enter basic salary : ";

cin>>basicSalary;

da = basicSalary * (35.0/100.0);

hr = basicSalary * (25.0/100.0);

grossSalary = basicSalary + da + hr;

cout<<"Gorss Salary : "<<grossSalary<<endl;

return 0;

Output of above program :

Programming question no 24 :

#include<iostream>

#include<conio.h>

using namespace std;

int main( )

int hh1, hh2, mm1, mm2, ss1, ss2;

hh=0, mm=0, ss=0;


cout<<"enter time 1 in hh:mm:ss format : ";

cin>>hh1>>mm1>>ss1;

cout<<"enter time 2 in hh:mm:ss format : ";

cin>>hh2>>mm2>>ss2;

ss = ss1 + ss2;

mm = ss / 60;

ss = ss % 60;

mm = mm + (mm1 + mm2);

hh = mm / 60;

mm = mm % 60;

hh = hh + (hh1 + hh2);

cout<<"Sum of two times is : "<<hh<<":"<<mm<<":"<<ss<<endl;

return 0;

Output of above program :

Programming question no 25 :

#include<iostream>

#include<conio.h>

#include<math.h>

using namespace std;

int main( )
{

float principal, rate, time, CompoundInterest;

cout<<"enter principal amount :";

cin>>principal;

cout<<"enter rate of interest:";

cin>>rate;

cout<<"enter total time:";

cin>>time;

CompoundInterest=principal*pow(1+(rate/100),time);

cout<<"Compound Interest: "<<CompoundInterest<<endl;

getch();

return 0;

Output of above program :

Programming question no 26 :

#include<iostream>

#include<conio.h>

using namespace std;

int main( )

char ch;

cout<<"enter a number : ";


cin>>ch;

cout<<"ASCII : "<<(int)ch<<endl;

return 0;

Output of above program :

Programming question no 27 :

#include<iostream>

#include<conio.h>

#include<math.h>

using namespace std;

int main( )

cout<<"Number \t Square \t Cube"<<endl;

cout<<"1 \t 1 \t 1"<<endl;

cout<<"2 \t 4 \t 8"<<endl;

cout<<"3 \t 9 \t 27"<<endl;

cout<<"4 \t 16 \t 64"<<endl;

cout<<"5 \t 25 \t 125"<<endl;

getch( );

return 0;

Output of above program :


Programming question no 28 :

#include<iostream>

#include<conio.h>

using namespace std;

int main( )

int m1, m2, m3, m4, m5, totalMarks;

float percentage;

cout<<"enter marks of five subjects : ";

cin>>m1>>m2>>m3>>m4>>m5;

totalMarks = m1 + m2 + m3 + m4 + m5;

cout<<"total marks : "<<totalMarks<<endl;

percentage = (totalMarks / 500.0) * 100.0;

cout<<"percentage : "<<percentage<<"%"<<endl;

return 0;

Output of above program :

You might also like