[My site ]
Main » 2013 » December » 12 » 2009-2010 question 4
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;
}
Category: C Programming - 1 | Views: 353 | Added by: ahansaary | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Sign Up | Login ]