11:56 PM 2009-2010 question 4 |
write a program that reads a sequence of integers when a negative number is read that many asterisk are to print ,, when a positive number is read that the factorial of the number is to be printed
#include<stdio.h>
main()
{
int i, n, val, j, fact;
printf("enter n : ");
scanf("%d", &n);
for(i=1;i<=n;i++){
printf("enter value no. %d : ", i);
scanf("%d", &val);
if(val<0){
val*=-1;
for(j=1;j<=val;j++)
printf("*");
printf("\n");
}else{
fact=1;
for(j=1;j<=val;j++)
fact*=j;
printf("fact = %d", fact);
printf("\n");
}
}
getch();
return 0;
}
|
|
Total comments: 0 | |