C++ PROGRAMMING
Q)0-structure.cpp
#include <iostream>
int main()
{
return 0;
}
=====================================================================
Q)abc.cpp
// Your First C++ Program
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
return 0;
}
====================================================================
Q)s2d.cpp
#include <iostream> //io -> input/output, stream -> flow
//#include <curses.h>
int main()
{
int n, d, s = 0, m = 1;
std::cout << "Enter a number\n"; //endl -> new line
std::cin >> n;
int k = n;
if (n >= 10 && n <= 99)
{
while (n > 0)
{
d = n % 10;
s = s + d;
m = m * d;
n = n / 10;
}
if (s + m == k)
std::cout << "special\n";
else
std::cout << "not\n";
}
else
std::cout << "not a 2 digit no\n";
return 0;
}
====================================================================
Q)fn_call.cpp
#include <iostream>
//#include <curses.h>
using namespace std;
int sum(int z)
{
int p = 0;
for (; z > 0; z = z / 10)
p = p + (z % 10);
return p;
}
int multi(int w)
{
int v = 1;
for (; w > 0; w = w / 10)
v = v * (w % 10);
return v;
}
int main()
{
int s = 0, n, k = 0;
std::cout << "Enter a no\n";
std::cin >> n;
s = sum(n);
k = multi(n);
if (s + k == n)
std::cout << "special\n";
else
std::cout << "not\n";
return 0;
}
====================================================================
Comments
Post a Comment