Skip to main content

Featured

C Program to display spellings of number 1-10 on entry

C Program to display spellings of number 1-10 on entry.   #include<stdio.h>   void main() { int num; printf("Enter a number between 1-10:"); scanf("%d",&num); printf("\n"); switch (num) { case 1: printf("ONE"); break; case 2: printf("TWO"); break; case 3: printf("THREE"); break; case 4: printf("FOUR"); break; case 5: printf("FIVE"); break; case 6: printf("SIX"); break; case 7: printf("SEVEN"); break; case 8: printf("EIGHT"); break; case 9: printf("NINE"); break; case 10: printf("TEN"); break; default:         printf("THE ENTERED NUMBER IS NOT BETWEEN 1-10"); } } OUTPUTS

C Program to find sum of first n natural,even,odd numbers

C Program to find sum of first n natural,even,odd numbers


#include<stdio.h> void main() { int n,i,a=0,e=0,o=0; printf("Enter the nth number:"); scanf("%d",&n);                                   //sum of first n natural numbers. for(i=1;i<=n;i++) { a=a+i; } printf("\nSum of first %d natural numbers:%d",n,a);                                   //sum of first n even and odd numbers. for(i=1;i<=2*n;i++) { if(i%2==0) { e=e+i;               //for even } else { o=o+i;                //for odd } } printf("\nSum of first %d even numbers:%d",n,e); printf("\nSum of first %d odd numbers:%d",n,o); }


OUTPUTS












Comments