Posts

Showing posts from February, 2024

Tutorial_10

 ICT/2022/139 R.S.R.Ranathunga Print the following shapes using loop construct of C programming. *  * *  * * *  * * * *  * * * * *  * * * * * * #include <stdio.h> int main(){ int i,x; for(i=1;i<=6;i++){ for(x=1;x<=i;x++){ printf("*"); } printf("\n"); } return 0; } * * * * * * *  * * * * * * *  * * * * * * *  * * * * * * *  * * * * * * * #include <stdio.h> int main(){ int i,x; for(i=1;i<=5;i++){ for(x=1;x<=7;x++){ printf("*"); } printf("\n"); } return 0; } * * * * * *  * * * * *  * * * *  * * *  * *  * #include <stdio.h> int main(){ int i,x; for(i=6;i>=1;i--){ for(x=1;x<=i;x++){ printf("*"); } printf("\n"); } return 0; }            *           * *         * * *       * * * *     * * * * *  ...

Tutorial_09

 R.S.R. Ranathunga ICT/2022/139 2. Swap two values stored in two different variables.  #include<stdio.h> int main(){ int a=5, b=10, temp=0; temp=a; a=b; b=temp; printf("The values of a=%i and b=%i", a,b); return 0; } 3. Check whether an entered number is negative, positive or zero. #include<stdio.h> int main(){ int num=0; printf("Enter number:"); scanf("%i", &num); if(num<0) printf("Negative"); else if(num==0) printf("Zero"); else printf("Positive"); return 0; } 4. Check whether an entered year is leap year or not.  #include <stdio.h> int main(){ int n; printf("Enter Year:"); scanf("%i", &n); if(n%4==0) printf("Leap Year"); else printf("Not Leap Year"); return 0; } 5. Write a program that asks the user to type in two integer values at the terminal. Test these  two numbers to determine if the first is evenly...

Tutorial_8

 CT/2022/139 R.S.R. Ranathunga 1. Type in and run the all programs presented in lecture note 7 and 8. Briefly describe the theory/ concept you learned from these programs separately.  [01] #include <stdio.h> int main()  { int sum = 17, count = 5; double mean; mean = sum / count; printf("Value of mean : %f\n", mean ); return 0; } output: Value of mean : 3.000000 sum and count are integer data types. integer type sum value dividing by integer type count value. Data type of mean is double with 6 decimal zero values. [02] #include <stdio.h> int main() { int sum = 17, count = 5; double mean; mean = (double) sum / count;  printf("Value of mean : %f\n", mean ); return 0; } output : Value of mean : 3.400000 sum and count are integer data type. mean is double. first sum conveted to type double and divided by count.   #include <stdio.h> int main()  { int i = 17; char c = 'c'; /* ascii value is 99 */ int sum; sum...