M3-R4: July 2013 (O-Level)
Q. 6(a):
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.
Ans:
Program to print a character n times using a function print_char():
#include <stdio.h>
#include <conio.h>
void print_char(char, int);
void main(){
print_char('%', 50);
print_char('*', 30);
getch();
}
void print_char(char ch, int n){
int i;
printf("\n");
for(i=0; i<n; i++)
printf("%c", ch);
getch();
}
Q. 6(a):
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.
Ans:
Program to print a character n times using a function print_char():
#include <stdio.h>
#include <conio.h>
void print_char(char, int);
void main(){
print_char('%', 50);
print_char('*', 30);
getch();
}
void print_char(char ch, int n){
int i;
printf("\n");
for(i=0; i<n; i++)
printf("%c", ch);
getch();
}
No comments:
Post a Comment