/*write a c program to add first 10 odd or even numbers*/ #include<stdio.h> #include<conio.h> void main() { int n,c,sum=0; clrscr(); printf("1.sum of first 10 odd numbers"); printf("\n2.sum of first 10 even numbers"); printf("\nenter your choice:"); scanf("%d",&c); switch(c) { case 1: for(n=1;n<=20;n=n+2) { sum=sum+n; } printf("sum:%d",sum); break; case 2: for(n=2;n<=20;n=n+2) { sum=sum+n; } printf("sum:%d",sum); break; } getch(); }
No comments:
Post a Comment