SlideShare a Scribd company logo
OCS752 INTRODUCTION TO C PROGRAMMING
UNIT 1 EXERCISE PROGRAMS
1. Check whether the required amount can be withdrawn based on the available amount
#include <stdio.h>
unsigned long amount=1000, deposit, withdraw;
int choice, pin, k;
char transaction ='y';
void main()
{
while (pin != 1520)
{
printf("ENTER YOUR SECRET PIN NUMBER:");
scanf("%d", &pin);
if (pin != 1520)
printf("PLEASE ENTER VALID PASSWORDn");
}
do
{
printf("********Welcome to ATM Service**************n");
printf("1. Check Balancen");
printf("2. Withdraw Cashn");
printf("3. Deposit Cashn");
printf("4. Quitn");
printf("********************************************nn");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("n YOUR BALANCE IN Rs : %lu ", amount);
break;
case 2:
printf("n ENTER THE AMOUNT TO WITHDRAW: ");
scanf("%lu", &withdraw);
if (withdraw % 100 != 0)
{
printf("n PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100");
}
else if (withdraw >(amount - 500))
{
printf("n INSUFFICENT BALANCE");
}
else
{
amount = amount - withdraw;
printf("nn PLEASE COLLECT CASH");
printf("n YOUR CURRENT BALANCE IS%lu", amount);
}
break;
case 3:
printf("n ENTER THE AMOUNT TO DEPOSIT");
scanf("%lu", &deposit);
amount = amount + deposit;
printf("YOUR BALANCE IS %lu", amount);
break;
case 4:
printf("n THANK U USING ATM");
break;
default:
printf("n INVALID CHOICE");
}
printf("nnn DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): n");
fflush(stdin);./*fflush() is typically used for output stream only. Its purpose is to clear
(or flush) the output buffer and move the buffered data to console*/
scanf("%c", &transaction);
if (transaction == 'n'|| transaction == 'N')
k = 1;
} while (!k);
printf("nn THANKS FOR USING OUT ATM SERVICE");
}
2. Menu-driven program to find the area of different shapes
#include <stdio.h>
void main ()
{
int choice,r,l,w,b,h;
float area;
printf("Input 1 for area of circlen");
printf("Input 2 for area of rectanglen");
printf("Input 3 for area of trianglen");
printf("Input your choice : ");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Input radious of the circle : ");
scanf("%d",&r);
area=3.14*r*r;
break;
case 2:
printf("Input length and width of the rectangle : ");
scanf("%d%d",&l,&w);
area=l*w;
break;
case 3:
printf("Input the base and hight of the triangle :");
scanf("%d%d",&b,&h);
area=.5*b*h;
break;
}
printf("The area is : %fn",area);
}
Copy
Sample Output:
Input 1 for area of circle
Input 2 for area of rectangle
Input 3 for area of triangle
Input your choice : 1
Input radious of the circle : 5
The area is : 78.500000
3. Find the sum of even numbers
#include <stdio.h>
int main()
{
int i, n, sum=0;
/* Input upper limit from user */
printf("Enter upper limit: ");
scanf("%d", &n);
for(i=2; i<=n; i+=2)
{
/* Add current even number to sum */
sum += i;
}
printf("Sum of all even number between 1 to %d = %d", n, sum);
return 0;
}
Unit 1 ocs752 introduction to c programming

More Related Content

What's hot (20)

PPSX
CISC & RISC ARCHITECTURES
Dr.YNM
 
PPTX
8257 DMA Controller
ShivamSood22
 
PPTX
Real Time Systems
leo3004
 
PPTX
String Handling in c++
Fahim Adil
 
PPTX
bus and memory tranfer (computer organaization)
Siddhi Viradiya
 
PDF
Pointers and Structures
Gem WeBlog
 
DOCX
Flag register 8086 assignment
Zia3130
 
PPTX
Programming in C Presentation upto FILE
Dipta Saha
 
PPTX
Software Project Management - Staffing
TanishqRongta1
 
PPTX
Function in C program
Nurul Zakiah Zamri Tan
 
PPTX
Introduction to C programming
Rokonuzzaman Rony
 
PPTX
Presentation on pointer.
Md. Afif Al Mamun
 
PDF
COMPUTER ORGANIZATION NOTES Unit 7
Dr.MAYA NAYAK
 
PPT
Introduction to c programming
ABHISHEK fulwadhwa
 
PPTX
Strings in c++
Neeru Mittal
 
PPTX
Conditional Statement in C Language
Shaina Arora
 
PPT
Embedded systems and its ports
nitin kumar
 
PPT
RECURSION IN C
v_jk
 
DOC
Ocs752 unit 1
mgrameshmail
 
PPTX
Type casting in c programming
Rumman Ansari
 
CISC & RISC ARCHITECTURES
Dr.YNM
 
8257 DMA Controller
ShivamSood22
 
Real Time Systems
leo3004
 
String Handling in c++
Fahim Adil
 
bus and memory tranfer (computer organaization)
Siddhi Viradiya
 
Pointers and Structures
Gem WeBlog
 
Flag register 8086 assignment
Zia3130
 
Programming in C Presentation upto FILE
Dipta Saha
 
Software Project Management - Staffing
TanishqRongta1
 
Function in C program
Nurul Zakiah Zamri Tan
 
Introduction to C programming
Rokonuzzaman Rony
 
Presentation on pointer.
Md. Afif Al Mamun
 
COMPUTER ORGANIZATION NOTES Unit 7
Dr.MAYA NAYAK
 
Introduction to c programming
ABHISHEK fulwadhwa
 
Strings in c++
Neeru Mittal
 
Conditional Statement in C Language
Shaina Arora
 
Embedded systems and its ports
nitin kumar
 
RECURSION IN C
v_jk
 
Ocs752 unit 1
mgrameshmail
 
Type casting in c programming
Rumman Ansari
 

Similar to Unit 1 ocs752 introduction to c programming (20)

PDF
The solution manual of programming in ansi by Robin
Shariful Haque Robin
 
PPT
Unit2 jwfiles
mrecedu
 
DOCX
Practical File of C Language
RAJWANT KAUR
 
PPT
C-Language Unit-2
kasaragadda srinivasrao
 
PPTX
Najmul
Najmul Ashik
 
DOCX
Fuzail_File_C.docx
SyedFuzail14
 
PDF
C lab programs
Dr. Prashant Vats
 
PDF
C lab programs
Dr. Prashant Vats
 
PDF
The solution manual of c by robin
Abdullah Al Naser
 
PDF
6 c control statements branching &amp; jumping
MomenMostafa
 
PPTX
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
PPTX
C Language Programming Introduction Lecture
myinstalab
 
PPTX
Introduction to Basic C programming 02
Wingston
 
PDF
C- Programming Assignment practice set 2 solutions
Animesh Chaturvedi
 
DOC
C-programs
SSGMCE SHEGAON
 
PDF
Subject:Programming in C - Lab Programmes
vasukir11
 
DOCX
Best C Programming Solution
yogini sharma
 
DOCX
C lab manaual
manoj11manu
 
The solution manual of programming in ansi by Robin
Shariful Haque Robin
 
Unit2 jwfiles
mrecedu
 
Practical File of C Language
RAJWANT KAUR
 
C-Language Unit-2
kasaragadda srinivasrao
 
Najmul
Najmul Ashik
 
Fuzail_File_C.docx
SyedFuzail14
 
C lab programs
Dr. Prashant Vats
 
C lab programs
Dr. Prashant Vats
 
The solution manual of c by robin
Abdullah Al Naser
 
6 c control statements branching &amp; jumping
MomenMostafa
 
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
C Language Programming Introduction Lecture
myinstalab
 
Introduction to Basic C programming 02
Wingston
 
C- Programming Assignment practice set 2 solutions
Animesh Chaturvedi
 
C-programs
SSGMCE SHEGAON
 
Subject:Programming in C - Lab Programmes
vasukir11
 
Best C Programming Solution
yogini sharma
 
C lab manaual
manoj11manu
 
Ad

More from vrgokila (6)

PPT
evaluation technique uni 2
vrgokila
 
PPT
Unit 2 HCI DESIGN RULES AND DESIGN PATTERNS
vrgokila
 
PPT
Unit 2 hci
vrgokila
 
DOC
Basic c programs updated on 31.8.2020
vrgokila
 
PPT
Array 31.8.2020 updated
vrgokila
 
PPT
Array
vrgokila
 
evaluation technique uni 2
vrgokila
 
Unit 2 HCI DESIGN RULES AND DESIGN PATTERNS
vrgokila
 
Unit 2 hci
vrgokila
 
Basic c programs updated on 31.8.2020
vrgokila
 
Array 31.8.2020 updated
vrgokila
 
Array
vrgokila
 
Ad

Recently uploaded (20)

PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PPTX
Snet+Pro+Service+Software_SNET+Pro+2+Instructions.pptx
jenilsatikuvar1
 
PDF
6th International Conference on Machine Learning Techniques and Data Science ...
ijistjournal
 
PPTX
UNIT DAA PPT cover all topics 2021 regulation
archu26
 
DOCX
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
PPTX
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
PDF
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
PPTX
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
PDF
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
DOCX
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
PPTX
Hashing Introduction , hash functions and techniques
sailajam21
 
PPTX
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
PDF
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
PPTX
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
PPTX
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PPTX
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
PPTX
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
PPTX
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
Snet+Pro+Service+Software_SNET+Pro+2+Instructions.pptx
jenilsatikuvar1
 
6th International Conference on Machine Learning Techniques and Data Science ...
ijistjournal
 
UNIT DAA PPT cover all topics 2021 regulation
archu26
 
8th International Conference on Electrical Engineering (ELEN 2025)
elelijjournal653
 
The Role of Information Technology in Environmental Protectio....pptx
nallamillisriram
 
Biomechanics of Gait: Engineering Solutions for Rehabilitation (www.kiu.ac.ug)
publication11
 
Product Development & DevelopmentLecture02.pptx
zeeshanwazir2
 
International Journal of Information Technology Convergence and services (IJI...
ijitcsjournal4
 
CS-802 (A) BDH Lab manual IPS Academy Indore
thegodhimself05
 
Hashing Introduction , hash functions and techniques
sailajam21
 
Introduction to Neural Networks and Perceptron Learning Algorithm.pptx
Kayalvizhi A
 
GTU Civil Engineering All Semester Syllabus.pdf
Vimal Bhojani
 
美国电子版毕业证南卡罗莱纳大学上州分校水印成绩单USC学费发票定做学位证书编号怎么查
Taqyea
 
Heart Bleed Bug - A case study (Course: Cryptography and Network Security)
Adri Jovin
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
Arduino Based Gas Leakage Detector Project
CircuitDigest
 
Solar Thermal Energy System Seminar.pptx
Gpc Purapuza
 
MPMC_Module-2 xxxxxxxxxxxxxxxxxxxxx.pptx
ShivanshVaidya5
 

Unit 1 ocs752 introduction to c programming

  • 1. OCS752 INTRODUCTION TO C PROGRAMMING UNIT 1 EXERCISE PROGRAMS 1. Check whether the required amount can be withdrawn based on the available amount #include <stdio.h> unsigned long amount=1000, deposit, withdraw; int choice, pin, k; char transaction ='y'; void main() { while (pin != 1520) { printf("ENTER YOUR SECRET PIN NUMBER:"); scanf("%d", &pin); if (pin != 1520) printf("PLEASE ENTER VALID PASSWORDn"); } do { printf("********Welcome to ATM Service**************n"); printf("1. Check Balancen"); printf("2. Withdraw Cashn"); printf("3. Deposit Cashn"); printf("4. Quitn"); printf("********************************************nn"); printf("Enter your choice: "); scanf("%d", &choice); switch (choice) { case 1: printf("n YOUR BALANCE IN Rs : %lu ", amount); break; case 2: printf("n ENTER THE AMOUNT TO WITHDRAW: "); scanf("%lu", &withdraw); if (withdraw % 100 != 0) { printf("n PLEASE ENTER THE AMOUNT IN MULTIPLES OF 100"); } else if (withdraw >(amount - 500)) { printf("n INSUFFICENT BALANCE"); } else { amount = amount - withdraw; printf("nn PLEASE COLLECT CASH"); printf("n YOUR CURRENT BALANCE IS%lu", amount); } break;
  • 2. case 3: printf("n ENTER THE AMOUNT TO DEPOSIT"); scanf("%lu", &deposit); amount = amount + deposit; printf("YOUR BALANCE IS %lu", amount); break; case 4: printf("n THANK U USING ATM"); break; default: printf("n INVALID CHOICE"); } printf("nnn DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): n"); fflush(stdin);./*fflush() is typically used for output stream only. Its purpose is to clear (or flush) the output buffer and move the buffered data to console*/ scanf("%c", &transaction); if (transaction == 'n'|| transaction == 'N') k = 1; } while (!k); printf("nn THANKS FOR USING OUT ATM SERVICE"); } 2. Menu-driven program to find the area of different shapes #include <stdio.h> void main () { int choice,r,l,w,b,h; float area; printf("Input 1 for area of circlen"); printf("Input 2 for area of rectanglen"); printf("Input 3 for area of trianglen"); printf("Input your choice : "); scanf("%d",&choice);
  • 3. switch(choice) { case 1: printf("Input radious of the circle : "); scanf("%d",&r); area=3.14*r*r; break; case 2: printf("Input length and width of the rectangle : "); scanf("%d%d",&l,&w); area=l*w; break; case 3: printf("Input the base and hight of the triangle :"); scanf("%d%d",&b,&h); area=.5*b*h; break; } printf("The area is : %fn",area); } Copy Sample Output: Input 1 for area of circle Input 2 for area of rectangle Input 3 for area of triangle Input your choice : 1 Input radious of the circle : 5 The area is : 78.500000 3. Find the sum of even numbers #include <stdio.h> int main() { int i, n, sum=0; /* Input upper limit from user */ printf("Enter upper limit: "); scanf("%d", &n); for(i=2; i<=n; i+=2) { /* Add current even number to sum */ sum += i; } printf("Sum of all even number between 1 to %d = %d", n, sum); return 0; }