Pages

Saturday, 16 September 2017

print a character as per given number


Q : Write a program having function print_char( ) which receives a character and n integer as arguments. The function should print n times the entered character.

Solution : 

#include<stdio.h>
void print_char(char,int);
void main()

{
     int n;
     char ch;
     printf("Enter character>> ");
     scanf("%c",&ch);
     printf("Enter n>> ");
     scanf("%d",&n);
     print_char(ch,n);
}
void print_char(char ch,int n)
{
     int i;
     for(i=1;i<=n;i++)
          printf("%c",ch);
}

Download Source Code
Next Question

No comments:

Post a Comment