0% found this document useful (0 votes)
27 views

This Lab Exercise Covers: An Introduction To C Programming Arithmetic Statements Standard Input Output Mathematical Functions

This lab covers C programming fundamentals like arithmetic statements, input/output functions, and mathematical functions. It includes 9 exercises to write programs demonstrating various concepts: 1) Printing and reading input, 2) Using operators with integers and floats, 3) Reading multiple inputs, 4) Calculating averages, 5) Pre/post-decrement, 6) Evaluating velocity using functions, 7) Evaluating oscillation frequency using functions.

Uploaded by

Sarang Hae Islam
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

This Lab Exercise Covers: An Introduction To C Programming Arithmetic Statements Standard Input Output Mathematical Functions

This lab covers C programming fundamentals like arithmetic statements, input/output functions, and mathematical functions. It includes 9 exercises to write programs demonstrating various concepts: 1) Printing and reading input, 2) Using operators with integers and floats, 3) Reading multiple inputs, 4) Calculating averages, 5) Pre/post-decrement, 6) Evaluating velocity using functions, 7) Evaluating oscillation frequency using functions.

Uploaded by

Sarang Hae Islam
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab 1

This lab exercise covers: an introduction to C programming arithmetic statements Standard input output Mathematical functions

Exercise 1.1 Write a program that prints the string Computing Systems & Programming to the screen, reads an integer from the keyboard, and print the integer to the screen.

Exercise 1.2 Write the following program. Compile, link and run it. #include<stdio.h> int main () { int year; float height; year = 21; height = 1.77; printf("Ali is %d years old and %f meter height\n", year, height); return 0; } Exercise 1.3 Write a program that demonstrates the use of the +,-,* and / operators for integers. Type the following program. Compile, link and run it. #include <stdio.h> int main( ) { int i=20; int j; printf("i=%d\n",i);

// Print the value of i and j


1

printf("j=%d\n",j); j= i+5; printf("j=%d\n",j); i= j-10; printf("i=%d\n",i); i= i* j * 2; printf("i=%d\n",i); j= i / 10; printf("j=%d\n",j); return 0; } Exercise 1.4

//Integer addition //Integer subtraction. //Integer multiplication. //Integer division

Write a program that demonstrates the use of the +,-,* and / operators for floating point numbers. Type the following program. Compile, link and run it. #include <stdio.h> int main( ) { double i=1000.1001; double j=123.234567; double k; k = i + j; printf("k=%10.10lf\n",k); k = i - j + 500.951; printf("k=%10.10lf\n",k); j = j * i; printf("j=%lf\n",j); i = k / j; printf("i=%f\n",i); return 0; }

Exercise 1.5 Write the following program. Compile, link and run it. #include <stdio.h> int main () { char name1, name2, name3; int age; printf("Kindly enter 3 character representing your name shortform:"); scanf("%c%c%c", &name1, &name2, &name3); printf("Enter your age: "); scanf("%d",&age); printf("Hello %c%c%c, next year you will be %d years old", name1, name2, name3, age+1); return 0; }

Exercise 1.6 Write a program using the following algorithm: Declare the integer variables num1, num2, num3, sum and average. Get three numbers from the user. Prompt the user for an integer. Read an integer from the keyboard. Store it in num1. Prompt the user for an integer. Read an integer from the keyboard. Store it in num2. Prompt the user for an integer. Read an integer from the keyboard. Store it in num3. Find the average of the three numbers. sum = num1 + num2 + num3. average = sum / 3. Print average to the screen.

Exercise 1.7 Write the following program that illustrates the use of predecrement and postdecrement. Compile link and run it.
3

#include <stdio.h> int main () { int a=10; int b; b=a--; printf(a=%d\n,a); printf(b=%d\n,b); b=--a; printf(a=%d\n,a); printf(b=%d\n,b); return 0; }

Exercise 1.8 Write a program to evaluate the velocity, v. Use pow() and sqrt() functions from the C library. Prompt a user for vo, a, x and xo value. Print the result on screen.

Exercise 1.9 Write a program to evaluate the Electrical oscillation frequency. Use sqrt() function from the C library. Prompt a user for c and L value. Print the result on screen.

You might also like