Anda di halaman 1dari 9

Q . WAP to find the average of three numbers .

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
float avg;

clrscr();

//read the three numbers

printf(“\nEnter the value of a ,b, and c:”);


scanf(“%d %d %d”,&a,&b,&c);

//calculate the average

avg=(a+b+c)/3.0;

//display the average


printf(“\nAverage = “,avg);

getch();

Q .WAP to swap two numbers without using the


third variable

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;

clrscr();

//read the two numbers

printf(“\nEnter the value of a and b :”);


scanf(“%d %d”,a,b);
//swap the values

printf(“\nBefore Swap , a= %d , b= %d “,a,b);

a=a+b;
b=a-b;
a=a-b;

printf(“\nAfter Swap , a= %d , b= %d “,a,b);

getch();
}

Q WAP to read the three digit number and find the


sum of the first and the last digit .

e.g.
num = 345

sum = 3+5=8

#include<stdio.h>
#include<conio.h>

void main()
{
int num,sum;

clrscr();

//read the three digit number

printf(“\nEnter the three digit number :”);

scanf(“%d”,&num) ;

//extract the first and the last digit

int a,b;

a=num/100;

b=num%10;
sum =a+b;

printf(“\nSum of digits =%d “,sum);

getch();
}

Q Write a program to readthe five digit number and


find the reverse

num = 12345

rev=54321

#include<stdio.h>
#include<conio.h>
void main()
{
long num,rev;

clrscr();
//read the five -digit number

printf(“\nEnter the five digit number :”);

scanf(“%d”,&num);

//find the reverse

rev=num%10;

num=num/10;

rev=rev*10+num%10;

num=num/10;

rev=rev*10+num%10;

num=num/10;

rev=rev*10+num;
printf(“\nReverse = %d “,rev);

getch();
}

Q A gold smith sells a one gram of 24 carat gold for


Rs 5500 .WAP to read the weight of gold in grams
and calculate its cost in 18,20,22, and 24 carat.

#include<stdio.h>
#include<conio.h>
void main()
{
float
weight,carat,carat18,carat20,carat22,carat24;

clrscr();

printf(“\nEnter the weight of gold in grams :”);


scanf(“%f”,&weight);
carat=5500/24.0;

carat18=carat*18*weight;

carat20=carat*20*weight;

carat22=carat*22*weight;

carat24=5500*weight;

printf(“\nCost in 18 carats = %f“,carat18);


printf(“\nCost in 20 carats = %f“,carat20);
printf(“\nCost in 22 carats = %f“,carat22);
printf(“\nCost in 24 carats = %f“,carat24);

getch();

Anda mungkin juga menyukai