/*wap to find whether the given int is odd or even*/ #include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf("enter any int:"); scanf("%d",&n); if(n%2==0) printf("the number is even"); else printf("the number is odd"); getch(); }
Showing posts with label Odd Even. Show all posts
Showing posts with label Odd Even. Show all posts
wap to find whether the given int is odd or even
wap to find number of odd, even & zero numbers from given 10 int numbers
/*wap to find number of odd, even & zero numbers from given 10 int numbers*/ #include<stdio.h> #include<conio.h> void main() { int n[10],i,count1=0,count2=0,count3=0; clrscr(); printf("enter any 10 int numbers:\n"); for(i=0;i<10;i++) { scanf("%d",&n[i]); } for(i=0;i<10;i++) { if(n[i]==0) count1++; else if(n[i]%2==0) count2++; else if(n[i]%2!=0) count3++; } printf("odd numbers:%d",count3); printf("\neven numbers:%d",count2); printf("\nzero numbers:%d",count1); getch(); }
Wap to find sum of first ODD or EVEn numbers using SWITCH CASE
/*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(); }
Wap to find sum of first 10 even numbers
/*write a c program to add first 10 even numbers*/ #include<stdio.h> #include<conio.h> void main() { int n,sum=0; clrscr(); printf("sum of first 10 even numbers"); for(n=2;n<=20;n=n+2) { sum=sum+n; } printf("sum:%d",sum); getch(); }
Wap to find sum of first 10 odd numbers
/*write a c program to add first 10 odd numbers*/ #include<stdio.h> #include<conio.h> void main() { int n,sum=0; clrscr(); printf("sum of first 10 odd numbers");
for(n=1;n<=20;n=n+2) { sum=sum+n; } printf("sum:%d",sum); getch(); }
Subscribe to:
Posts (Atom)