KEMBAR78
Cse115 Lab Manual 1 Introduction | PDF
0% found this document useful (0 votes)
85 views3 pages

Cse115 Lab Manual 1 Introduction

The document introduces programming concepts in C including input/output functions like scanf and printf. It provides examples demonstrating how to take various data types as input and print output. Examples show calculating mathematical operations on user inputs and converting between temperature units. Home tasks are assigned including swapping variable values and calculating averages.

Uploaded by

Abid
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)
85 views3 pages

Cse115 Lab Manual 1 Introduction

The document introduces programming concepts in C including input/output functions like scanf and printf. It provides examples demonstrating how to take various data types as input and print output. Examples show calculating mathematical operations on user inputs and converting between temperature units. Home tasks are assigned including swapping variable values and calculating averages.

Uploaded by

Abid
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/ 3

North South University

Department of Electrical and Computer Engineering


CSE 115L: Fundamentals of Computer Programming
Week 01 – Introduction

Example 1: Write a program that prints: Example 2: Write a program that prompts the user to
insert an integer value, a decimal number and his name
“North South University” and print the inserted value as output.
Hello class of cse115L!! Welcome to NSU.
#include<stdio.h> #include<stdio.h>
#include<stdlib.h> int main(){
int num;
int main() float deci;
{ char name[20];
printf("\t \" North South University\" \n \n");
printf("Hello class of cse115L!! Welcome to NSU. \n"); printf("Enter a number:");
scanf("%d",&num);
}
printf("The number is %d\n",num);

printf("Enter a decimal number:");


scanf("%f",&deci);
printf("The number is %.2f\n",deci);

printf("Enter your name:");


scanf("%s",&name);
printf("Your name is: %s", name);

return 0;
}

Example 3: Data types and their size in C. Example 4: Write a program that reads in the radius of a
circle and prints the circle’s diameter, circumference and
area.

#include<stdio.h> #include<stdio.h>
int main(){ int main()
int a; {
float b; float const PI = 3.142;
double c; float radius;
char d; float area, circumference, diameter;
long int longInt; printf("Enter the radius of a circle:");
signed int no; scanf("%f",&radius);

printf("Size of int: %d bytes\n",sizeof(a)); diameter= 2*radius;


printf("Size of float: %d bytes\n",sizeof(b)); circumference= 2*PI*radius;
printf("Size of double: %d bytes\n",sizeof(c)); area= PI * radius * radius;
printf("Size of char: %d byte\n",sizeof(d)); printf("The Diameter is: %.2f \n",diameter); printf("The
printf("Size of Long int: %d byte\n",sizeof(longInt)); Circumference is: %.2f \n",circumference); printf("The
printf("Size of signed int: %d byte\n",sizeof(no)); area is: %.2f \n",area);
return 0; }
}

Summary
scanf ( use to take input from user) printf( display something on the screen)

%d use to take integer input %d to display integer


%f use to take floating number input %f to display float or double
%s string input %c to display character
%c character input %s to display string
%lf use to take double number input
NOTES: To take string as input including ‘Space’ use gets(stringVariableName ).

Task (10 marks)


Task 1. Write a program that asks the user to enter two numbers, obtains the two
numbers from the user and prints the sum, product, difference, quotient and remainder
of the two numbers.

Input: Output:

Sum = 15
Insert first number: 10 Product = 50
Insert second number: 5 Difference = 5
Quotient = 2
Remainder = 0
Task 2. Write a program that reads in 3 numbers and prints their average.

Input: Output:

Insert first number: 3


Insert second number: 8 The average is: 4.3
Insert third number: 2
Task 3: Convert Celsius to Fahrenheit unit using the following formula. Take the value
of C as input from user and calculate the value of F.

F= C * (9/5) + 32

Home Tasks
1. Ask user for two integers a and b. Then swap (interchange) the values of a and
b. That means, a should get the value of b and b should get the value of a.
Enter a: 7
Enter b: 3
After swapping, a: 3 and b: 7

You might also like