Solution Assignment5
Solution Assignment5
Please use the concept of Arrays, functions and loops to work out the
following C++ programs.
1. Write a C++ program using an array to calculate the value of the sum of
100 natural numbers in the series: 1+2+3+....+100.
Solution:
#include <iostream>
using namespace std;
int main()
{
int num[100];
int sum = 0;
return 0;
}
Solution:
#include <iostream>
using namespace std;
average = sum/size;
return average;
}
int main()
{
int num[100];
return 0;
}
Solution:
#include <iostream>
using namespace std;
#define num_row 10
#define num_column 10
int main()
{
int num[num_row][num_column];
for(int i=0;i<num_row;i++)
{
for(int j=0;j<num_column;j++)
{
num[i][j] = i*j;
cout << i << " * " << j << " = " << num[i][j] << endl;
}
}
return 0;
}
4. Write a C++ program that will read the strings “Merry Christmas.” and
“Happy New Year 2023.” from the user prompt and Concatenate them
using <cstring> class.
Solution:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char str1[100];
char str2[100];
cin.getline(str2, sizeof(str2));
return 0;
}