Professional Documents
Culture Documents
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;
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);
return 0;
}