Professional Documents
Culture Documents
int main() {
int a, b, c;
int max;
int main()
{
int n,a=0,b=1,c;
cout<<"Enter the number : ";
cin>>n;
cout<<a<<" "<<b;
for(int i=2;i<n;i++)
{
c=a+b;
cout<<" "<<c;
a=b;
b=c;
}
cout<<\n;
return 0;
}
int main()
{
char str[100];
int vowels = 0;
cout<<"Enter your desired sentence = ";
cin.getline(str, 100);
return 0;
}
#include<iostream>
int main()
cin>>n;
if(a%2==0)
y=y+i;
else
y=y-i;
a=a+1;
}
cout<<y;
6. Write a program to find out the sum of the digits of an integer number.
#include<iostream>
using namespace std;
int main() {
int x, s = 0;
cout << "Enter the number : ";
cin >> x;
while (x != 0) {
s = s + x % 10;
x = x / 10;
}
cout << "\nThe sum of the digits : "<< s;
}
int main() {
int x, y;
cout<<"Enter the first number : ";
cin>>x;
cout<<"Enter the second number : ";
cin>>y;
if (x > y) {
temp = x;
x = y;
y = temp;
}
9. Write a program to find out the sum of two matrixes and display the resultant matrix in its
form.
#include<iostream>
using namespace std;
int main()
{
int matOne[3][3], matTwo[3][3], matThree[3][3];
int i, j, k;
cout<<"Enter 9 Elements for First Matrix: ";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
cin>>matOne[i][j];
}
cout<<"\nEnter 9 Elements for Second Matrix: ";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
cin>>matTwo[i][j];
}
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
for(k=0; k<3; k++)
matThree[i][j] = (matOne[i][j] + matTwo[i][j]);
}
}
cout<<"\nSum of the matrix are :\n";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
cout<<matThree[i][j]<<"\t";
cout<<endl;
}
cout<<endl;
return 0;
}
10. Write a program to find the maximum and minimum of a list of integer.
#include <iostream>
using namespace std;
int main()
{
int array[50], *max, *min, size, i;
cout<<"Enter the number of integer in the list\n";
cin>>size;
cout<<"Enter integers\n";
for ( i = 0 ; i < size ; i++ )
cin>>array[i];
max = array;
min = array;
for (i = 0; i < size; i++)
{
if (*(array+i) > *max)
*max = *(array+i);
}
cout<<"Maximum integer in the list is "<< *max << "\n" ;
for (i = 0; i < size; i++)
{
if (*(array+i) < *min)
*min = *(array+i);
}
cout<<"Minimum integer in the list is "<< *min <<"\n";
return 0;
}
#include<iostream>
int main()
int x, y;
cin>>x;
y= (x*x)-2*x+1;
cout<<"The value of y : "<<y<<"\n";
int main()
{
int i,n,x,sum=0;
float avg;
for(i=1;i<=n;++i)
{
cout<<"\nEnter number "<<i<<" :: ";
cin>>x;
sum+=x;
}
avg=(float)sum/(float)n;
return 0;
}
13. Write a program to check a string is palindrom or not.
#include <iostream>
#include <string>
using namespace std;
return true;
}
int main()
{
string word;
cout<<"Enter the word : ";
std::getline(cin, word);
for (int i = 0; i < 1; i++)
{
if (isPalindrome(word))
{
cout << word << " -> Palindrome" << endl;
}
else
{
cout << word << " -> Not a Palindrome" << endl;
}
}
return 0;
}
#include <iostream>
struct student
char name[50];
int roll;
float marks;
} s[5];
int main()
s[i].roll = i+1;
cout << "For roll number" << s[i].roll << "," << endl;
return 0;
}