0% found this document useful (0 votes)
6 views5 pages

Question (1) : Write A Program To Find The Sum and Average of Two //numbers

The document contains C code for several programming questions including writing programs to find the sum and average of two numbers, calculate simple interest, check if a number is prime, find the sum of digits of a 5-digit number, convert decimal to binary, and convert binary to decimal.

Uploaded by

akmmbhakmmbh
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)
6 views5 pages

Question (1) : Write A Program To Find The Sum and Average of Two //numbers

The document contains C code for several programming questions including writing programs to find the sum and average of two numbers, calculate simple interest, check if a number is prime, find the sum of digits of a 5-digit number, convert decimal to binary, and convert binary to decimal.

Uploaded by

akmmbhakmmbh
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/ 5

#include<stdio.

h>

// Question(1) : Write a program to find the sum and average of two


//numbers.

int main(){

int r1, r2;

printf("r1 : ");
scanf("%d", & r1);

printf("r2 : ");
scanf("%d", & r2);

int sum = r1 + r2;

printf("Sum of two numbers is : %d" , sum);

return 0;

#include<stdio.h>

// Question(2) : Write a program to find simple interest.


int main(){

float p, r, t;

printf("Enter the Principal amount : ");


scanf("%f", & p);

printf("Enter Rate : ");


scanf("%f", & r);

printf("Enter the Time : ");


scanf("%f", &t);
float Si = (p * r * t) / 100;

printf("Simple Interest is : %f", Si);

return 0;

#include<stdio.h>

// Question(3) : Write a program to find whether the entered number is


prime or not.

int checkPrime(int n){

if(n == 1){
return 0;
}

for(int i = 2; i*i <= n; i++){

if(n % i == 0){

return 0;
break;
}

return 1;
}

int main(){

int number;
printf("Enter the number : ");
scanf("%d", &number);

if(checkPrime(number) == 1){
printf("It is a prime number.");
}
else{

printf("It is not a prime number.");


}

return 0;
}

#include<stdio.h>

// Question(4) : Write a program to find the sum of a 5-digit number.

int sumOfdigits(int n){

int sum = 0;

// Only for five digit numbers.


for(int i = 1; i <= 5; i++){

int t = n % 10;
sum += t;
n /= 10;

// For any number.


/*while(n != 0){

int t = n % 10;
sum += t;
n /= 10;

}*/

return sum;
}

int main(){
int number;
printf("Enter the number : ");
scanf("%d", &number);

printf("The sum of all digits is : %d", sumOfdigits(num));

return 0;
}

#include<stdio.h>

// Question(6a) : write a program to convert decimal to binary.

int main(){

int decimal, bin;


printf("Decimal : ");
scanf("%d", & decimal);

while(decimal > 0){

// For
bin = decimal % 2;
printf("%d", bin);
decimal /= 2;
}

return 0;
}

#include<stdio.h>

// Question(6b) : Find the binary to decimal form.

int main(){

long long int bin;


int decimal = 0;
int ind = 1;
printf("Binary : ");
scanf("%d", & bin);

while (bin != 0){

int t = bin % 10;


decimal += (t * ind);
ind *= 2;
bin /= 10;

printf("Decimal form is : %d", decimal);


return 0;
}

You might also like