This Program performs the string functions STRCMP(), STRLEN() and GETLINE() using FOR looping statement
#include <iostream.h>
#include <string.h>
#include <conio.h>
int main()
{
int i;
char text[80];
cout << "Type \"end\" to quit\n";
for(cin.getline(text,80);strcmp(text,"end") !=0; cin.getline(text,80))
{
for(i = 1; i <= strlen(text); i++)
{
cout << "-";
}
cout << '\n';
}
return 0;
}
This Program performs simple user function
#include <iostream.h>
void showval(void);
int main()
{
int mainvar = 100;
showval();
cout << funcvar << '\n';
return 0;
}
void showval(void)
{
int funcvar = 10;
cout << funcvar << '\n';
cout << mainvar << '\n';
}
This Program performs simple user function#include <iostream.h>
#include <conio.h>
void tally(void);
int main()
{
while ( getch() != 'q')
tally();
return 0;
}
void tally(void)
{
static int called = 0;
called++;
cout << "Function tally called " << called <<" times\n";
}
This Program performs how the user declare variables as array to store numeric values inside the main() module#include <iostream.h>
int main()
{
float hours[52];
int week;
for (week = 0; week < 52; week++)
hours[week] = 0;
hours[0] = 32.5;
hours[1] = 44.0;
hours[2] = 40.5;
hours[3] = 38.0;
cout << "Element "<< "\tValue " << "\tAddress\n";
for (week = 0; week < 4; week++)
cout << "hours[" << week << "]" << '\t'<< hours[week] << '\t' << &hours[week] << '\n';
return 0;
}
#include <iostream.h>
#include <string.h>
#include <conio.h>
int main()
{
int i;
char text[80];
cout << "Type \"end\" to quit\n";
for(cin.getline(text,80);strcmp(text,"end") !=0; cin.getline(text,80))
{
for(i = 1; i <= strlen(text); i++)
{
cout << "-";
}
cout << '\n';
}
return 0;
}
This Program performs simple user function
#include <iostream.h>
void showval(void);
int main()
{
int mainvar = 100;
showval();
cout << funcvar << '\n';
return 0;
}
void showval(void)
{
int funcvar = 10;
cout << funcvar << '\n';
cout << mainvar << '\n';
}
This Program performs simple user function#include <iostream.h>
#include <conio.h>
void tally(void);
int main()
{
while ( getch() != 'q')
tally();
return 0;
}
void tally(void)
{
static int called = 0;
called++;
cout << "Function tally called " << called <<" times\n";
}
This Program performs how the user declare variables as array to store numeric values inside the main() module#include <iostream.h>
int main()
{
float hours[52];
int week;
for (week = 0; week < 52; week++)
hours[week] = 0;
hours[0] = 32.5;
hours[1] = 44.0;
hours[2] = 40.5;
hours[3] = 38.0;
cout << "Element "<< "\tValue " << "\tAddress\n";
for (week = 0; week < 4; week++)
cout << "hours[" << week << "]" << '\t'<< hours[week] << '\t' << &hours[week] << '\n';
return 0;
}
No comments:
Post a Comment