Week 01 - Assignments CSE115 (SAM)

You might also like

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

1. #include<stdio.

h>
int main()
{
int a,b,c,d,f;

printf ("Enter the distance (in km): ");


scanf ("%d",&a);

b = a * 1000;
c = b * 3.28;
d = c * 12;
f = d * 30;

printf ("\nDistance in meters = %d m",b);


printf ("\nDistance in feets = %d feet",c);
printf ("\nDistance in inches = %d inches",d);
printf ("\nDistance in centimeters= %d cm",f);

printf ("\n\npress any key to close.");

getch ();
return 0;
}
2. #include <stdio.h>
#include <conio.h>

void main()
{
float c,f;
printf("Fahrebheit Temperature = ");
scanf("%f",&f);
c=(f-32)*5/9;
printf("\nCelcius Temperature = %f",c);
getch();
}
3. #include<stdio.h>
int main()
{
int a,b,area_r,area_c,peri_r,peri_c,r;
printf ("Enter length and width of rectangle: ");
scanf ("%d%d",&a,&b);

printf ("Enter radius: ");


scanf ("%d",&r);

area_r = (a * b);
peri_r = ((2*a) + (2*b));

area_c = (3.14 * r * r);


peri_c = (3.14 * 2 * r);

printf ("\n\nArea of rectangle = %d",area_r);


printf ("\nPerimeter of rectabgle = %d",peri_r);

printf ("\n\nArea of the circle = %d",area_c);


printf ("\nCircumference of the circle = %d",peri_c);

printf ("\n\nPress any key to close.");

getch ();
return 0;
}
4. #include<stdio.h>

void main()
{
Int c,d,e;
Clrscr();
Printf(“\nEnter the number at locations C:”);
Scanf(“%d”,&c);
Printf(“\nEnter the number at locations D:”)
Scanf(“%d”,&d);
e=c;
c=d;
d=e;
Printf(“\nNew number at locations C=%d”,c);
Printf(“\nNew number at locations D=%d”,d);
Printf(“\n\n\n\n\nPress any key to exit”);
Getch();
}
5. #include <stdio.h>

#include <conio.h>

void main()

int num, a, n;

int sum = 0;

clrscr();

printf("\n Enter a 5 digit number(less than 32767):")

scanf("%d", &num);

a = num % 10;

n = num/10;

sum = sum + a;

a=n%10;
n=n/l0;

sum = sum + a;

a=n%10;

n=n/l0;

sum = sum + a;

a=n%10;

n=n/l0;

sum = sum + a;

a=n%10;

sum = sum + a;

printf(“\n The sum of the 5 digit of %d is %d",num,


sum);

printf("\n Press any key to exit.");

getch();

}
6. #include <stdio.h>
 
int main()
{
int n, reverse = 0;
 
printf("Enter a number to reverse\n");
scanf("%d", &n);
 
while (n != 0)
{
reverse = reverse * 10;
reverse = reverse + n%10;
n = n/10;
}
 
printf("Reverse of entered number is =
%d\n", reverse);
 
return 0;
}
7.#include<stdio.h>

#include<conio.h>

void main()

int n, a, sum = 0;

clrscr();

printf("\n Enter a four digit number: ");

scanf("%d", &n);

a = n/1000;

sum = sum + a;

a=n%10;

sum=sum+a;

printf("\n Sum of first and last digit of %d =%d”, n, sum);

printf (“\n press any key to exit.”);

getch();

}
8. #include<conio.h>
#include<stdio.h>
int main()
{
     float cost, sale, costitem, profit;

     printf("Please enter total selling price


of 15 items: ");
     scanf("%f",&sale);
    
     printf("\nNow enter total profit on 15
items: ");
     scanf("%f",&profit);
    
     //Calculations
     cost = sale - profit;
     costitem = cost / 15;

    
     printf("\nCost price per item:
%f",costitem);
    
     getche();
}
10.

a)

b)

c)

d)
e)

f)

You might also like