0% found this document useful (0 votes)
11 views10 pages

Codes

sample codes

Uploaded by

hihihello1006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
11 views10 pages

Codes

sample codes

Uploaded by

hihihello1006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
Exercise 1: Write a program in C to read 10 integer values from the user and find their sum and average. (You should define maximum 4 variables) #include int main(void) int nunbe! int sum=0; float average; 03 printf("Enter the 10 numbers for (int d=1; d Ant main(void) int nunber=2; int nunber1=0; printf("Enter a nunber: scanf("30",énumber) ; for (int i=1; icenumber; i++) { if (number’si==0) (nunber1++;} + if (numbert: ) {printt("Entered number is a prime number, > else {printf("Entered number is not a prime number. > return 03 Console shell Markdown Caer ee Cn Tne Scy Sass ] Coors a prine number.» ff Exercise 5: Write a C program to get any day number in integer from the user and display day name in the word using the following table: 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday 7 Sunday #include int main (void) { int nunber3; printf("Input Day No : "); scanf(""sd", Gnumber); switch(numbert) { case 1: printf("Monday \n"); break; case 2: printf("Tuesday \ break; case 3: printf("Wednesday \n' break; case 4: printf("Thursday \n"); break; case 5: printf("Friday \n"); break: case 6: printf("Saturday \n"); break; case 7: printf("Sunday \n"); break; default: printf ("Invalid day number. “A004 breaks ¥ + Please try again COT Swo bc RSC Un Tons wt) pCa aed rg Exercise 3: Write a C program to get an integer value from the user and display a pattern like the right angle triangle using an asterisk. (printf or puts can be used maximum 3 times in your program). #include "stdio.h” int main(void) £ int number, number1; printf("Please Enter the Number of Rows: scanf("%d", &number); ete ares mese uC) Cire mC Son Tony it) De oe ea ey printf ("\nPrinting Right Angled Triangle \ for (int i=l; i

You might also like