Tuesday, 17 January 2012

Write a function called printChar having two value parameters c and n. The parameter c is of type char, and n is of type int. The function prints a single line of n copies of the character c. For example, if n = 5 and c = &, the function would print &&&&&. Use for loop.



Write a function named "sum_from_to" that takes two integer arguments, call them "first" and "last", and returns as its value the sum of all the integers between first and last inclusive





#include<iostream>

#include<conio.h>



using namespace std;



int main()

{

    void printChar(char m, int n);

    char k;

    int l;



    cout << " Enter a Character = ";

    cin >> k ;

    cout << "\n Enter the number of times to print that character : ";

    cin >> l ;

    printChar(k,l);



    getche();

    return 0;

}

void printChar(char m, int n)

{

    for(int a=1;a<=n;a++)

    cout << m ;

}

1 comment: