Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Name-Debojyoti Das

SUBJECT- Programming for problem solvign Practical


COURSE CODE: BCA191

Assignment

1. Write a C program to check whether a number is Armstrong or not.

#include<stdio.h>

int main() {
    int num, originalnum, remainder,
result= 0;
    printf("Enter a three digit integer:
");
    scanf("%d",&num);
    originalnum = num;

    while(originalnum!= 0) {
        remainder= originalnum% 10;
        result += remainder *remainder*
remainder;
        originalnum/= 10;
    }
    if(result == num){
        printf("%d is an Armstrong
number.\n", num);
    }else{
        printf("%d is not an Armstrong
number.\n",num);
    }
Name-Debojyoti Das
SUBJECT- Programming for problem solvign Practical
COURSE CODE: BCA191

Assignment

    return 0;
}
OUTPUT-
PS C:\Users\User\Desktop\lab assignment> gcc first.c
PS C:\Users\User\Desktop\lab assignment> ./a.exe
Enter a three digit integer: 153
153 is an Armstrong number.
PS C:\Users\User\Desktop\lab assignment>

2. Write a C program to find g.c.d and l.c.m of two numbers.

#include<stdio.h>

int main() {
    int num1, num2, gcd, lcm, remainder,
numerator, denominator;
    printf("Enter two numbers: \n");
    scanf("%d %d", &num1, &num2);
    while(remainder != 0){
        numerator= denominator;
        denominator = remainder;
        remainder= numerator %
denominator;
    }
    gcd = denominator;
    lcm= num1* num2/gcd;
    printf("GCD of %d and%d = %d\
n",num1, num2, gcd);
Name-Debojyoti Das
SUBJECT- Programming for problem solvign Practical
COURSE CODE: BCA191

Assignment

    printf("LCM of %d and %d = %d\n",


num1, num2, lcm);
    return 0;

}
OUTPUT-
PS C:\Users\User\Desktop\lab assignment> gcc 2.C
PS C:\Users\User\Desktop\lab assignment> ./a.exe
Enter two numbers:
45
45
GCD of 45 and45 = 2592768
LCM of 45 and 45 = 0

3. Write a Fibonacci series in a given range.

#include<stdio.h>

int main() {
    int i,n;

    int t1= 0, t2=1;

    int nexterm = t1+t2;


    printf("Enter the number of terms:
");
    scanf("%d", &n);
    printf("fibonacci series: %d,
%d",t1, t2);
    for(i = 3; i<=n; ++i) {
        printf("%d", nexterm);
Name-Debojyoti Das
SUBJECT- Programming for problem solvign Practical
COURSE CODE: BCA191

Assignment

        t1=t2;
        t2 = nexterm;
        nexterm = t1 +t2;
    }
    return 0;
}

OUTPUT-
PS C:\Users\User\Desktop\lab assignment> gcc 3.C
PS C:\Users\User\Desktop\lab assignment> ./a.exe
Enter the number of terms: 5
fibonacci series: 0, 1123
PS C:\Users\User\Desktop\lab assignment> ./a.exe
Enter the number of terms: 10
fibonacci series: 0, 112358132134

4. Write a C program to check whether a number is prime or not.

#include<stdio.h>

int main() {
    int n,i, flag=0;
    printf("Enter the positive integer:
");
    scanf("%d", &n);

    if(n== 0 || n== 1)
    flag=1;
    for(i=2; i<= n/2; ++i) {
        if(n%i ==0) {
Name-Debojyoti Das
SUBJECT- Programming for problem solvign Practical
COURSE CODE: BCA191

Assignment

            flag =1;break;
        }
    }
    if(flag== 0)
    printf("%d is a prime number.", n);
    else{
        printf("%d is not a prime
number.", n);
    }
    return 0;
}
OUTPUT-
PS C:\Users\User\Desktop\lab assignment> gcc 4.c
PS C:\Users\User\Desktop\lab assignment> ./a.exe
Enter the positive integer: 4
4 is not a prime number.

You might also like