NAME : M ZUNNORAIN
CLASS: BSSE A1
ROLL NUMBER : 24K2016
Q1
CODE:
#include <iostream>
using namespace std;
int main() {
int num,i=0;
cout<<"enter number "<<endl;
cin>>num;
while(i<=num)
{
cout<<"number"<<i<<endl;
i++;
}
system("pause");
return 0;
}
OUTPUT:
Q2
CODE:
#include <iostream>
using namespace std;
int main() {
int num,i=2;
cout<<"enter number "<<endl;
cin>>num;
while(i<=10)
{
cout<<" even number"<<i<<endl;
i+=2;
}
system("pause");
return 0;
}
OUTPUT:
Q3
Code:
#include <iostream>
using namespace std;
int main() {
int num,i=1;
cout<<"enter number "<<endl;
cin>>num;
while(i<=10)
{
cout<<" odd number"<<i<<endl;
i+=2;
}
system("pause");
return 0;
}
Output:
Q4
CODE:
#include <iostream>
using namespace std;
int main() {
int num,i=2,J=1;
cout<<"enter number "<<endl;
cin>>num;
while(i<num)
{
if(num%i==0)
{ J=0;}
i++;
}
if(J==1)
{
cout<<"number is prime"<<endl;
}
else
{
cout<<" number is not prime"<<endl;
}
system("pause");
return 0;
}
OUTPUT:
Q6
Code:
#include <iostream>
using namespace std;
int main() {
int num,reminder;
cout<<"enter number "<<endl;
cin>>num;
while(num>0)
{
reminder=num%10;
num=num/10;
cout<<reminder;
}
system("pause");
return 0;
}
Output:
Q7
CODE:
#include<iostream>
using namespace std;
int main(){
int num,length=0,mod;
cout<<"Enter Any number"<<endl;
cin>>num;
while(0<num){
mod=num%10;
num=num/10;
length++;
}
cout<<length <<endl;
system("pause");
return 0;
}
OUTPUT:
Q8
CODE:
#include <iostream>
using namespace std;
int main() {
int num, i = 1;
cout << "Enter a number: ";
cin >> num;
// cout << "Table of " << num << ":\n";//
while (i <= 10) {
cout << num << " x " << i << " = " << num * i << endl;
i++;
}
return 0;
}
OUTPUT:
Q12
CODE:
#include <iostream>
using namespace std;
int main() {
int startRange, endRange;
cout << "Input number for starting range: ";
cin >> startRange;
cout << "Input number for ending range: ";
cin >> endRange;
cout << "The prime numbers between " << startRange << " and " << endRange << " are:\n";
int primeCount = 0;
int num = startRange;
while (num <= endRange)
{
bool isPrime = true;
if (num <= 1)
{
isPrime = false;
} else
{
int i = 2;
while (i<= (num/2))
{
if (num % i == 0)
{
isPrime = false;
break;
}
i++;
}
}
if (isPrime)
{
cout << num << " ";
primeCount++;
}
num++;
}
cout << endl;
cout << "The total number of prime numbers between " << startRange << " and " << endRange << "
is: " << primeCount << endl;
system("pause");
return 0;
}
OUTPUT:
Q10
CODE:
#Include <iostream>
using namespace std;
int main()
{
int size, i = 1;
cout<<"Enter the size of triangle: "<<endl;
cin>>size;
do {
for (int j = 1; j <= i; j++)
{
cout<<"*";
}
cout<<endl;
i++;
}
while (i <= size);
system("pause");
return 0;
}
OUTPUT:
Q14
CODE:
#include <iostream>
using namespace std;
int main()
{
int n,n1,largest;
char a;
cout << "Enter number:"<<endl;
cin>>n;
cout << "press y to continue, n to end:"<<endl;
cin>>a;
while (a == 'y')
{
cout << "Enter number:"<<endl;
cin>>n1;
cout << "press y to continue, n to end:"<<endl;
cin>>a;
largest = n;
if( n1 > largest){
largest = n1; }
else largest = n;
}
cout<<largest<<" is largest among the numbers"<<endl;
system("pause");
return 0;
}
OUTPUT:
Q 15
CODE: #include<iostream>
using namespace std;
int main()
{
int marks,sum=0,avg,count=0;
while(count<10)
{
cout<<"enter student marks "<<endl;
cin>>marks;
sum=sum+marks;
count++;
}
avg=sum/10;
cout<<"Average Marks of Ten students is_:"<<avg<<endl;
system("pause");
return 0;
}
OUTPUT:
Q19
CODE:
#include <iostream>
using namespace std;
int main() {
int base,e,b;
cout << "Enter the base:"<<endl;
cin>>base;
cout << "Enter the exponent:"<<endl;
cin>>e;
b=base;
while(e>1 )
{ b=b*base;
e--;
}
cout<<"Result is"<<b<<endl;
system("pause");
return 0;
}
OUTPUT:
Q20
CODE:
#include<iostream>
using namespace std;
int main()
{
int n,count=1;
cout<<"Enter number:"<<endl;
cin>>n;
while ( n >= count)
{
if( n%count ==0 )
{ cout<<count<<",";
}
count++;
}
cout<<" are the factors of "<<n<<endl;
system("pause");
}
OUTPUT:
Q16
CODE:
#include <iostream>
using namespace std;
int main() {
int intValue;
int index;
int replaceValue;
cout << "Enter integer value (greater than 1000): ";
cin >> intValue;
while (intValue <= 1000)
{
cout << "Please enter a value greater than 1000: ";
cin >> intValue;
}
cout << "Enter index number";
cin >> index;
cout << "Enter replace value (single-digit 0-9): ";
cin >> replaceValue;
if (replaceValue < 1 || replaceValue > 10)
{
cout << "Replace value must be a single-digit number (0-9)." << endl;
return 1;
}
if (index < 1 || index > 4)
{
cout << "Index must be between 1 and 4 for a 4-digit number." << endl;
return 1;
}
cout << "Original value: " << intValue << endl;
int updatedValue = intValue;
if (index == 1)
{
updatedValue = (updatedValue / 10) * 10 + replaceValue;
} else if (index == 2)
{
updatedValue = (updatedValue / 100) * 100 + replaceValue * 10 ;
} else if (index == 3)
{
updatedValue = (updatedValue / 1000) * 1000 + replaceValue * 100 ;
} else if (index == 4)
{
updatedValue = replaceValue * 1000 + (updatedValue % 1000);
}
cout << "Replaced value: " << updatedValue <<endl;
system("pause");
return 0;
}
OUTPUT: