0% found this document useful (0 votes)
13 views4 pages

Assignment 4

Uploaded by

talent.thread
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)
13 views4 pages

Assignment 4

Uploaded by

talent.thread
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/ 4

ASSIGNMENT -4 (BASICS OF C PROGRAMMING)

Basic instructions:
1. Check every line of your program for semicolon (;)
2. Check printf for format specifier %d for integer numbers
3. Check scanf for %d and & sign before variable name

 Write a simple C program to add two integer values and


print the output.
 #include<stdio.h>
 int main(){
 int a,b;
 scanf("%d,%d",&a,&b);
 printf("%d",a+b);
 return 0;
 }

 Write a simple C program to subtract two integer values


and print the output.
#include<stdio.h>

int main(){
int a,b;
scanf("%d,%d",&a,&b);
printf("%d",a-b);
return 0;
}

 Write a simple C program to multiply two integer values


and print the output.
 #include<stdio.h>
 int main(){
 int a,b;
 scanf("%d,%d",&a,&b);
 printf("%d",a*b);
 return 0;
 }
 Write a simple C program to divide two integer values and
print the output.
 #include<stdio.h>
 int main(){
 int a,b;
 scanf("%d,%d",&a,&b);
 printf("%d",a/b);
 return 0;
 }

 Ramesh’s basic salary is input through the keyboard. His


dearness allowance is 40% of basic salary. Write a program
to calculate his gross (total) salary.
 #include<stdio.h>
 int main(){
 int a,b;
 printf("enter base salary");
 scanf("%d",&a);
 b=a*0.4;
 printf("%d",a+b);
 return 0;
 }

 The distance between two cities (in kms) is input through


the keyboard. Write a program to convert and print this
distance in meters.
 #include<stdio.h>
 int main(){
 int a;
 printf("entyer dist in km");
 scanf("%d",&a);
 printf("%d meters",a*1000);
 return 0;
 }

 The distance between two cities (in kms) is input through


the keyboard. Write a program to convert and print this
distance in centimeters.
 #include<stdio.h>
 int main(){
 int a;
 printf("entyer dist in km");
 scanf("%d",&a);
 printf("%d centimeters",a*100000);
 return 0;
 }

 The distance between two cities (in kms) is input through


the keyboard. Write a program to convert and print this
distance in millimeters.
 #include<stdio.h>
 int main(){
 float a;
 printf("enter dist in km");
 scanf("%f",&a);
 printf("%f milimeters",a*(pow(10,6)));
 return 0;
 } //ask maam why integer data type not working for power func

 Height of a student (in feet) is input through the keyboard.


Write a program to convert this height into inches. Print
the height in inches on output screen.

#include<stdio.h>
#include<math.h>
int main(){
int a;
printf("enter height in feet");
scanf("%d",&a);
printf("%d inches",a*12);
return 0;
}

 Temperature of a city in Fahrenheit degrees is input


through the keyboard. Write a program to convert this
temperature into Centigrade degrees.
 #include<stdio.h>
 #include<math.h>
 int main(){
 float a;
 printf("enter temp in f");
 scanf("%f",&a);
 printf("%f Centigrate",(a-32)*5/9);
 return 0;
 }

You might also like