Vous êtes sur la page 1sur 3

Assignment # 02

Deadline:
5th January 2015

Total Marks = 100

1. Write Output of the following program (20)


#include<stdio.h>
int main()
{
int i=1,j,c ;
int fact=1;
//scanf("%d",&c);
while (i<=5)
//for(i=1;i<=c;i++)
{
//fact=0;
//while(j<=i)
for(j=1;j<=i;j++)
{
fact=fact*j;
}
printf("%d \t %d\n",i,fact);
i++;
}
}

2 . Write Output of the following program and also convert this program in Do while
loop?
(15)
#include<stdio.h>
int main()
{
int i=1,j,c ;
int fact=1;
//scanf("%d",&c);
while (i<=5)
//for(i=1;i<=c;i++)
{
fact=1;
//while(j<=i)
for(j=1;j<=i;j++)
{
fact=fact*j;
}
printf("%d \t %d\n",i,fact);
i++;

}
}

3 . Write Output of the following program

(10)

#include<stdio.h>
int main()
{
int i=1,j,c ;
int fact=1;
//scanf("%d",&c);
while (i<=5)
//for(i=1;i<=c;i++)
{
fact=1;
//while(j<=i)
for(j=1;j<=i;j++);
{
fact=fact*j;
}
printf("%d \t %d\n",i,fact);
i++;
}
}

4 . Write Output of the following program

(10)

int main(){
int n, count, sum=0;
printf("Enter the value of n. \n");
scanf("%d",&n);
for(count=1;count<=n;++count) //for loop terminates if count>n
{
sum+=count;
/* this statement i s equivalent to sum=sum+count */
}
printf("Sum=%d",sum);
// return 0;
}

5 . Write Output of the following program


int main()
{
int n, i;
printf("Enter an integer to find multiplication table: ");
scanf("%d",&n);
for(i=1;i<=10;++i)
{
printf("%d * %d = %d\n", i, n, n*i);
}

(10)

6 . Write Output of the following program

(10)

#include <stdio.h>
int main()
{
int n,i;
printf("Enter a positive integer: ");
scanf("%d",&n);
printf("Factors of %d are: ", n);
for(i=1;i<=n;++i)
{
if(n%i==0)
printf("%d ",i);
}
return 0;
}

7. Write Output of the following program and also convert in simple while loop. (15)
int main()
{
int rows,i,j,k=0;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;++j)
printf("%d ",k+j);
++k;
printf("\n");
}
}

8. Write Output of the following Program (20)


#include<stdio.h>
int main()
{
int row, c, n, temp;
temp = 6;
for ( row = 1 ; row <= 6 ; row++ )
{
for ( c = 1 ; c < temp ; c++ )
printf(" ");
temp--;
for ( c = 1 ; c <= 2*row - 1 ; c++ )
printf("*");
printf("\n");
}
}

Vous aimerez peut-être aussi