0% found this document useful (0 votes)
26 views11 pages

Week 01 - Assignments CSE115 (SAM)

The document contains code snippets in C programming language for various calculations and operations: 1) Converting distance units between km, meters, feet, and inches. 2) Converting between Fahrenheit and Celsius temperatures. 3) Calculating area and perimeter of a rectangle and circle. 4) Swapping values of two variables. 5) Calculating sum of digits of a number. 6) Reversing digits of a number. 7) Summing first and last digits of a number. 8) Calculating cost price of items from total sale price and profit.

Uploaded by

Fake Prio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views11 pages

Week 01 - Assignments CSE115 (SAM)

The document contains code snippets in C programming language for various calculations and operations: 1) Converting distance units between km, meters, feet, and inches. 2) Converting between Fahrenheit and Celsius temperatures. 3) Calculating area and perimeter of a rectangle and circle. 4) Swapping values of two variables. 5) Calculating sum of digits of a number. 6) Reversing digits of a number. 7) Summing first and last digits of a number. 8) Calculating cost price of items from total sale price and profit.

Uploaded by

Fake Prio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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