Problem Solving Through Programming In C Week5 Assignment July 2023

Problem-Solving-Through-Programming-In-C-Week5-Assignment-July-2023

NPTEL Problem solving through Programming In C Week5 All Programming Assignment Solutions | Swayam July 2023. With the growth of Information and Communication Technology, there is a need to develop large and complex software.

ABOUT THE COURSE:

This course is aimed at enabling the students to:
  • Formulate simple algorithms for arithmetic and logical problems
  • Translate the algorithms to programs (in C language)
  • Test and execute the programs and  correct syntax and logical errors
  • Implement conditional branching, iteration and recursion
  • Decompose a problem into functions and synthesize a complete program using divide and conquer approach
  • Use arrays, pointers and structures to formulate algorithms and programs
  • Apply programming to solve matrix addition and multiplication problems and searching and sorting problems 
  • Apply programming to solve simple numerical method problems, namely rot finding of function, differentiation of function and simple integration
COURSE LAYOUT
    • Week 1 : Introduction to Problem Solving through programs, Flowcharts/Pseudo codes, the compilation process, Syntax and Semantic errors, Variables and Data Types
    • Week 2 : Arithmetic expressions, Relational Operations, Logical expressions; Introduction to Conditional Branching
    • Week 3 : Conditional Branching and Iterative Loops
    • Week 4 : Arranging things : Arrays
    • Week 5 : 2-D arrays, Character Arrays and Strings 
    • Week 6 : Basic Algorithms including Numerical Algorithms
    • Week 7 : Functions and Parameter Passing by Value
    • Week 8 : Passing Arrays to Functions, Call by Reference
    • Week 9 : Recursion
    • Week 10 : Structures and Pointers
    • Week 11 : Self-Referential Structures and Introduction to Lists
    • Week 12 : Advanced Topics

Once again, thanks for your interest in our online courses and certification. Happy learning!

Problem Solving through Programming In C July 2023

Question : 1  Write a C program to check whether a given number (N) is a perfect number or not.
[Perfect Number – A perfect number is a positive integer number which is equals to the sum of its proper positive divisors. For example 6 is a perfect number because its proper divisors are 1, 2, 3 and it’s sum is equals to 6.]

				
					#include <stdio.h>
int main()
{
    int N; 
    scanf("%d",&N);
    int sum=0;	
	for(int i = 1; i <= N / 2; i++) 
    {
        if(N % i == 0) 
        {
            sum += i;
        }
    }

    if(sum == N){
        printf("%d is a perfect number.", N);
    }
	else{
        printf("%d is not a perfect number.", N);
    }
    return 0;
}
				
			

Problem Solving through Programming In C July 2023

Question : 2 Write a C program to count total number of digits of an Integer number (N).

				
					#include <stdio.h>
int main()
{
    int N; 
    scanf("%d",&N);
    int temp, count; 
    count=0;
    temp=N;
    while(temp>0)
    {
     	count++;
     	temp/=10;
    }
    printf("The number %d contains %d digits.",N,count);
}
				
			

Problem Solving through Programming In C July 2023

Question : 3  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.

				
					#include <stdio.h>
int main()
{
    int N;
    scanf("%d",&N);
    int temp, flag;
    temp=N;
    flag=0;
   
    while(temp!=1)
    {
        if(temp%2!=0){
            flag=1;
            break;
        }
        temp=temp/2;
    }
  
    if(flag==0)
        printf("%d is a number that can be expressed as power of 2.",N);
    else
        printf("%d cannot be expressed as power of 2.",N);
}
				
			

Problem Solving through Programming In C July 2023

Question : 4 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

				
					#include<stdio.h>
int main()
{
    int N;
    float sum = 0.0;
    scanf("%d",&N);
    int i;
    for(i=1;i<=N;i++)
    {
      	sum = sum + ((float)1/(float)i);
    }
    printf("Sum of the series is: %.2f",sum);
}