Escolar Documentos
Profissional Documentos
Cultura Documentos
#include<iostream>
int main ()
if (c1 != r2)
exit(0);
1
cin >> B[i][j];
C[i][j] = 0;
return 0;
2
Sample Programe :-
3
Sample output:-
4
2.program to print the calendar of a year/-
// A C++ Program to Implement a Calendar
// of an year
#include<bits/stdc++.h>
using namespace std;
Index Day
0 Sunday
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday*/
int dayNumber(int day, int month, int year)
{
/*
A Function that returns the name of the month
with a given month number
5
"October", "November", "December"
};
return (months[monthNumber]);
}
*/
int numberOfDays (int monthNumber, int year)
{
// January
if (monthNumber == 0)
return (31);
// February
if (monthNumber == 1)
{
// If the year is leap then February has
// 29 days
if (year % 400 == 0 ||
(year % 4 == 0 && year % 100 != 0))
return (29);
else
return (28);
}
// March
if (monthNumber == 2)
return (31);
// April
if (monthNumber == 3)
return (30);
// May
if (monthNumber == 4)
6
return (31);
// June
if (monthNumber == 5)
return (30);
// July
if (monthNumber == 6)
return (31);
// August
if (monthNumber == 7)
return (31);
// September
if (monthNumber == 8)
return (30);
// October
if (monthNumber == 9)
return (31);
// November
if (monthNumber == 10)
return (30);
// December
if (monthNumber == 11)
return (31);
}
7
// Print the columns
printf(" Sun Mon Tue Wed Thu Fri Sat\n");
if (++k > 6)
{
k = 0;
printf("\n");
}
}
if (k)
printf("\n");
current = k;
}
return;
}
return (0);
}
8
Sample output:-
9
3.program to check palindrome string /-
#include <stdio.h>
#include <string.h>
int main()
gets(a);
else
return 0;
10
Sample program :-
Sample output/-
11
4.program to display all the prime numbers of array/-
#include<iostream>
int main() {
int arr[10], i, s, j, p;
cin>>s;
j = 2;
p = 1;
if (arr[i] % j == 0) {
p = 0;
12
break;
j++;
if (p == 1) {
return 0;
Sample program:-
13
Sample output:-
14
5.Transpose of matrix/-
#include <iostream>
int main()
cout << endl << "Enter elements of matrix: " << endl;
cout << "Enter elements a" << i + 1 << j + 1 << ": ";
15
for(j = 0; j < c; ++j)
if(j == c - 1)
trans[j][i]=a[i][j];
if(j == r - 1)
16
return 0;
Sample programe:-
17
Sample output:-
18
6.program to find the number of vowels , consonant …. In a string/-
#include <iostream>
int main()
char line[150];
cin.getline(line, 150);
line[i]=='U')
++vowels;
19
++consonants;
++digits;
++spaces;
return 0;
20
Sample program /-
21
Sample output/-
22
7.program to convert octal to binary /-
#include <iostream>
#include <cmath>
int main()
int octalNumber;
cout << octalNumber << " in octal = " << convertOctalToBinary(octalNumber) << "in binary";
return 0;
int decimalNumber = 0, i = 0;
23
while(octalNumber != 0)
++i;
octalNumber/=10;
i = 1;
while (decimalNumber != 0)
binaryNumber += (decimalNumber % 2) * i;
decimalNumber /= 2;
i *= 10;
return binaryNumber;
24
Sample program
25
7.program to accept the marks of student and find average /-
#include <iostream>
int main()
string studentname;
cin>> students;
totalscores=0.0;
studentcount=0;
while(students>studentcount)
cin>>studentname;
cin>> score;
26
if(score<100 && score>89)
else
studentcount=studentcount+1;
totalscores=totalscores+score;
average=totalscores/students;
27
cout<<"The class average was :"<<average<<endl;
system("pause");
return 0;
Sample program/-
28
Sample output/-
29
8.Program to calculate the roots of quadratic equation/-
#include <iostream>
#include <cmath>
int main() {
if (discriminant > 0) {
else if (discriminant == 0) {
else {
realPart = -b/(2*a);
imaginaryPart =sqrt(-discriminant)/(2*a);
30
cout << "Roots are complex and different." << endl;
cout << "x1 = " << realPart << "+" << imaginaryPart << "i" << endl;
cout << "x2 = " << realPart << "-" << imaginaryPart << "i" << endl;
return 0;
Sample program/-
31
Sample output/-
32
9. Program to find the sum of the row and column of a matrix/-
#include<iostream>
#include<conio.h>
main()
int a[3][3];
int i, j, s = 0, sum = 0;
33
{
s = s + a[i][j];
cout << "sum of" << i + 1 << " Row is" << s;
s = 0;
s = s + a[j][i];
cout << "sum of" << i + 1 << " Column is" << s;
s = 0;
return 0;
getch();
34
Sample programme/-
35
Sample output/-
36
37
38
39
40
41