You are on page 1of 5

Muhammad waqas

23-CS-83
Lab Manual No 7

Program no 1:
#include<iostream>
using namespace std;
int main()
{
int wordcount=0,chcount=0;
char ch;
cout<<"enter a sentece";
cin>>ch;
while(cin.get(ch) && ch!='\n')
{
if(ch==' '||ch=='\t')
wordcount++;
else
chcount++;
}
if(chcount>0){
wordcount++;
}
cout<<"no of words"<<wordcount<<endl;
cout<<"no of char"<<chcount<<endl;
}

Output

Program 2:
#include <iostream>
int main() {
int originalNumber, reversedNumber = 0, remainder;

// Input a number
std::cout << "Enter a number: ";
std::cin >> originalNumber;

int temp = originalNumber;

// Reverse the number


do {
remainder = temp % 10;
reversedNumber = reversedNumber * 10 + remainder;
temp /= 10;
} while (temp != 0);

// Check if the original number is equal to its reverse


if (originalNumber == reversedNumber) {
std::cout << originalNumber << " is a palindrome." << std::endl;
} else {
std::cout << originalNumber << " is not a palindrome." << std::endl;
}
return 0;
}

Program 3
#include <iostream>

int main() {
double sum = 0;
int numerator = 1, denominator = 3;
// Calculate the sum using a do-while loop
do {
sum += static_cast<double>(numerator) / denominator;
numerator += 2;
denominator += 2;
} while (numerator <= 97);

// Display the result


std::cout << "Sum of the series: " << sum << std::endl;

return 0;
}

You might also like