Aim 1.1: Write a program to display “GUJARAT TECHNOLOGICAL UNIVERSITY” on the screen.
Code:
#include<stdio.h>
int main()
{
printf("GUJARAT TECHNOLOGICAL UNIVERSITY");
return 0;
}
Output screenshot:
Aim 1.2: Write a program which accepts a character from the keyboard and Display its ASCII code.
Code:
#include<stdio.h>
int main()
{
char c;
printf("Enter a character: ");
scanf("%c", &c);
printf("ASCII value of %c = %d", c, c);
return 0;
}
Output screenshot:
Aim 1.3: Write a program that reads two numbers from the keyboard and gives their addition, subtraction, multiplication, division and modulo.
Code:
#include<stdio.h>
int main()
{
int a,b;
printf("Enter First Number : ");
scanf("%d",&a);
printf("\nEnter Second Number : ");
scanf("%d",&b);
printf("\nAddition of %d & %d is : %d", a, b, a+b);
printf("\nSubtraction of %d & %d is : %d", a, b, a-b);
printf("\nMultiplication of %d & %d is : %d", a, b, a*b);
printf("\nDivision of %d & %d is : %d", a, b, a/b);
printf("\nModulo of %d & %d is : %d", a, b, a%b);
return 0;
}
Output screenshot:
Aim 1.4: Write a program to convert days into months and days.
Code:
#include<stdio.h>
int main ()
{
int months, days;
printf("Enter days : ");
scanf("%d", &days);
months = days/30;
days = days%30;
printf("Months = %d & Days = %d", months, days);
return 0;
}
Output screenshot:
Aim 1.5: The Distance between two cities (in Km.) is input through keyboard. Write a program to convert and print this distance in meters, feet, inches and centimetres.
Code:
#include<stdio.h>
int main()
{
float km, m, cm, feet, inch;
printf("Enter distance in kilometers: ");
scanf("%f",&km);
m = 1000 * km;
cm = 1000 * 100 * km;
feet = 3280.84 * km;
inch = 39370.08 * km;
printf("The distance in Feet: %f\n", feet);
printf("The distance in Inches: %f\n", inch);
printf("The distance in Meters: %f\n", m);
printf("The distance in Centimeters: %f\n", cm);
return 0;
}
Output screenshot:
Aim 1.6: Write a program to swap (interchange) values of two variables with and without using a third variable.
Code:
#include<stdio.h>
int main()
{
int a, b, temp;
printf("Enter first number: ");
scanf("%d",&a);
printf("Enter second number: ");
scanf("%d",&b);
printf("\nBefore swapping first number = %d & second number = %d",a,b);
temp=a;
a=b;
b=temp;
printf("\nAfter swapping first number = %d & second number = %d",a,b);
return 0;
}
Output screenshot:
Aim 1.7: Write a program to swap (interchange) values of two variables with and without using a third variable.
Code:
#include<stdio.h>
int main()
{
int a,b;
printf("Enter first number: ");
scanf("%d",&a);
printf("Enter second number: ");
scanf("%d",&b);
printf("\nBefore swapping first number = %d & second number = %d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter swapping first number = %d & second number = %d",a,b);
return 0;
}
Output screenshot:
No comments:
Post a Comment
If you have any doubts or suggestions, Please let me know