NPTEL » Problem solving through Programming In C
https://www.youtube.com/channel/UCmt2xnmpmOmhiaB2BRqdLDA
Week 5: Programming Assignment 1
Due on 2021-09-02, 23:59 IST
Write a C program to count total number of digits of an Integer number (N).
SOLUTION
int n=N,count=0;
while(n>0)
{
n=n/10;
count++;
}
printf("The number %d contains %d digits.",N,count);
return 0;
}
NPTEL » Problem solving through Programming In C
https://www.youtube.com/channel/UCmt2xnmpmOmhiaB2BRqdLDA
Week 5: Programming Assignment 2
Due on 2021-09-02, 23:59 IST
Write a C program to check whether the given number(N) can be expressed as Power of Two (2) or not.
For example 8 can be expressed as 2^3.
SOLUTION
int n=N;
while(n>1)
{
if(n%2!=0)
break;
n=n/2;
}
if(n==1)
printf("The number %d can be expressed as power of 2.",N);
else
printf("The number %d cannot be expressed as power of 2.",N);
return 0;
}
NPTEL » Problem solving through Programming In C
https://www.youtube.com/channel/UCmt2xnmpmOmhiaB2BRqdLDA
Week 5: Programming Assignment 3
Due on 2021-09-02, 23:59 IST
Write a C program to find sum of following series where the value of N is taken as input.
1+ 1/2 + 1/3 + 1/4 + 1/5 + .. 1/N
SOLUTION
while(N>=1)
{
sum=sum+(1/(float)N);
N=N-1;
}
printf("Sum of the series is: %.2f\n",sum);
return 0;
}
NPTEL » Problem solving through Programming In C
https://www.youtube.com/channel/UCmt2xnmpmOmhiaB2BRqdLDA
Week 5: Programming Assignment 4
Due on 2021-09-02, 23:59 IST
Write a C program to print the following Pyramid pattern upto Nth row. Where N (number of rows to be printed)
is taken as input.
For example when the value of N is 5 the pyramid will be printed as follows
*****
****
***
**
*
SOLUTION
int i,j;
for(i=N;i>=1;i--)
{
for (j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}