printf() and scanf() functions in C in Sinhala - Lesson 09
printf() සහ scanf() යන functions යොදාගනු ලබන්නේ C language එකෙහි data input කිරීම් සහ output සදහායි. මෙම functions දෙකම inbuilt library functions දෙකක්. ඒ කියන්නේ මේ function දෙක ක්රියා කිරීමට අවශ්ය instructions ඇතුලත් වෙලා තියෙන්නේ stdio.h (header file) එක තුල.
printf() function
printf() function එක යොදාගනු ලබන්නේ යම්කිසි දත්තයක් ප්රතිදානය කිරීමටයි. මෙමගින් c program එක compile කරගන්නා software එකෙහි console එක මත එම data එක print කිරීම සිදුකරනු ලබනවා.
scanf() function
scanf() function එක යොදාගනු ලබන්නේ යම්කිසි දත්තයක් input එකක් ලෙස program එකට ලබාගැනීමටයි. මෙමගින් c program එක compile කරගන්නා software එකෙහි console එකෙහි type කරන දත්ත c program එක මගින් read කරනු ලබනවා.
Code Example
(මුහුණතක දිග ඇතුලත් කර ඝණකයක වර්ගපලය සේවීම සදහා සරල c program එකක්)
#include<stdio.h> int main(){ int number; printf("enter a number:"); scanf("%d",&number); printf("cube of number is:%d ",number*number*number); return 0; }
Output
enter a number:5
cube of number is:125
scanf("%d",&number)
statement එක මගින් ඔබ විසින් console එකට ඇතුලත් කල අගය read කර number variable එකට store කරගනු ලබනවා.
printf("cube of number is:%d ",number*number*number)
statement එක මගින් ඔබ ඇතුලත් කල අගය එම අගයෙන්ම තුන් වරක් ගුණ කර console එක මත print කිරීම සිදු කරනු ලබනවා.
c programming kuppiya #09