Sie sind auf Seite 1von 5

ASSIGNMENT 02

Q.2) If a three digit number is input through keyboard, write a C program to calculate the sum of its
digits.

#include<stdio.h>

main()

int num,a,b,c,d,sum;

printf("Enter a number\n");

scanf("%d",&num);

a=num%10, b=num/10;

c=b%10, d=b/10;

sum=a+c+d;

printf("Sum of the digit is %d",sum);

}
ASSIGNMENT 02
Q.3) Write a C program to print out all Armstrong numbers between 100 to 999.

#include<stdio.h>

main()

int i,a,b,c,d,sum;

printf("Armstrong numbers are\n");

for(i=100;i<=999;i++)

a=i%10, b=i/10;

c=b%10, d=b/10;

sum=a*a*a+c*c*c+d*d*d;

if(i==sum)

printf("%d\n",sum);

}
ASSIGNMENT 02
Q.4) Write a C program to input four real numbers and print the maximum, minimum of these
numbers and also find out the difference between the maximum and minimum numbers.

#include<stdio.h>

main()

float a,b,c,d,max,min,dif;

printf("Enter the values of a,b,c and d\n");

scanf("%f%f%f%f",&a,&b,&c,&d);

max=a;

if(b>max)

max=b;

if(c>max)

max=c;

if(d>max)

max=d;

printf("Maximum=%f\n",max);

min=a;

if(b<min)

min=b;

if(c<min)

min=c;

if(d<min)

min=d;

printf("Minimum=%f\n",min);

dif=max-min;

printf("Difference=%f",dif);

Das könnte Ihnen auch gefallen