Ex1 word
Ex1 word
No: URK22CS3007
26.09.2022
numbers.
Aim:
To write a program to perform addition, subtraction, division and multiplication of two numbers.
Algorithm:
Program
#include <stdio.h>
void main()
scanf("%d", &num1);
Output
Result
The program is executed successfully. The sum, difference, multiplication and division of two
numbers are performed using input and output functions.
Ex.No.2 Console Input and Output Functions Reg.No: URK22CS3007
26.09.2022
2. Write a program to display the size of every data type using “sizeof” operator.
Aim: To calculate the memory space occupied by all primitive data types such as
integer, float, char and double.
Algorithm:
Program:
#include<stdio.h>
int main()
int x=25;
float r=3.785;
char s= 'z';
double d=4.89999999;
return 0;
~
Output:
Result: The program is executed successfully by calculating the size of primitive data types.
26.09.2022
3. Write a C program to calculate area and circumference of a circle.
Aim:
To write a program to calculate the area and circumference of a circle using the formulae:
ci = 2 * PI * rad;
Algorithm:
#include<stdio.h>
int main()
float pi;
pi=3.14;
int r;
float area,circumference;
scanf("%d",&r);
area=pi*r*r;
circumference=2*pi*r;
return 0;
Output :
Result:
The program is executed successfully. The area and circumference of a circle are
calculated.
Ex.No.4 Console Input and Output Functions Reg.No: URK22CS3007
26.09.2022
4. Write a program to swap values of two variables with and without using third variable.
Aim:
To write a program to Swap the values of two variables with and without using third variable.
Step 3: Calculate
a=a+b
b=a-b
a=a-b
Program:
#include<stdio.h>
int main()
a=a+b;//a=30 (10+20)
b=a-b;//b=10 (30-20)
a=a-b;//a=20 (30-10)
Algorithm:
Step 3: Calculate
Temp=a;
a=b;
b=temp;
Program:
#include<stdio.h>
int main()
int a,b,temp;
a=20;
b=10;
printf("%d\n",a);
printf("%d\n",b);
printf("swapped values:\n");
temp=a;
a=b;
b=temp;
printf("%d\n",a);
printf("%d\n",b);
return 0;
Output:
Result:
The program is executed successfully by swapping the given two numbers without and with using third
variable.
Ex.No.5 Console Input and Output Functions Reg.No: URK22CS3007
26.09.2022
Aim:
Algorithm:
Step 4: Display the values of rollnum, name and marks of the student
Program:
#include <stdio.h>
struct student
char name[50];
int roll;
float marks;
};
int main()
struct student s;
scanf("%s",s.name);
scanf("%d",&s.roll);
scanf("%f",&s.marks);
printf("\nDisplaying Information\n");
printf("Name: %s\n",s.name);
printf("Roll: %d\n",s.roll);
printf("Marks: %.2f\n",s.marks);
return 0;
OUTPUT
Result:
Thus the program is successfully executed and the profile of the student is displayed.
Ex.No.6 Console Input and Output Functions Reg.No: URK22CS3007
03.10.2022
6. Write a C program to read in a three digit number and produce the following output
(assuming that the input is 347 and the output is 3 hundreds 4 tens 7 units).
Aim:
To write a c program to read a three digit number and produce the output in hundreds, tens and units.
Algorithm:
Step 4: Display the values of rollnum, name and marks of the student
Program:
#include<stdio.h>
#include<cono.h>
int main()
scanf("%d",&n);
hun=no/100;
no=no%100;
ten=no/10;
unit=no%10;
getch();
return 0;
OUTPUT:
Result:
03.10.2022
7. Write a program to input name, marks of 5 subjects of a student and display the name of
the student, the total marks scored, percentage scored and the class of result.
Aim:
To write a C program to input the 5 subject marks of the student and display the result, total
marks scored, percentage scored by the student and the result in class.
Algorithm:
STEP1: Start
STEP 8: Stop
Program:
#include <stdio.h>
int main()
float per;
/* Input marks of five subjects from user */
/* Calculate percentage */
printf("Grade A");
printf("Grade B");
printf("Grade C");
printf("Grade D");
printf("Grade E");
}
else
printf("Grade F");
return 0;
OUTPUT:
Result:
The five subject marks of the students are calculated and the grade of the student is printed successfully.
03.10.2022
8. In this program, accept number of days from user and convert it into years, weeks & days
Aim:
To write a C program to get the number of days from user and convert it into years, weeks and days.
Algorithm:
STEP 1: Start
STEP 2: Get the number of days num.
STEP 3: Number of year = (number of days) / 365. Explanation-: number of years will
be the quotient obtained by dividing the given number of days with 365.
STEP 4: Number of weeks = (number of days % 365) / 7
STEP 5: Number of days = days = days- ((years*365) + (weeks*7));
STEP 6: Stop
Program:
#include <stdio.h>
void main()
scanf("%d",&num);
OUTPUT
RESULT:
The program is executed successfully by converting the number of days into years, weeks and days.
03.10.2022
9. In this program, we will accept temperature in Fahrenheit then convert it into Celsius using
following formula.
Formula = (F - 32)/1.8
Aim:
Algorithm:
STEP 1: Start
STEP 3: Convert temperature in Farenheit into temperature in Celsius by using the formula
Formula=(F-32)/1.8
STEP 5: Stop
Program:
#include <stdio.h>
int main()
scanf("%f", &fahrenheit);
return 0; }
OUTPUT