0% found this document useful (0 votes)
20 views3 pages

Assignment # 2 (CS)

The document provides details for an assignment that is due on January 5th, 2015 and is worth a total of 100 marks. It includes 8 programming problems to solve, providing the code for each problem and stating how many marks each one is worth. The problems involve writing the output of various for, while, and do-while loop programs and converting some programs between loop types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Assignment # 2 (CS)

The document provides details for an assignment that is due on January 5th, 2015 and is worth a total of 100 marks. It includes 8 programming problems to solve, providing the code for each problem and stating how many marks each one is worth. The problems involve writing the output of various for, while, and do-while loop programs and converting some programs between loop types.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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 is 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");
}
}

You might also like