Question-7 To print number of bit set in an number
// bit set #include<stdio.h> int main() { int n,a,r,s; s=0; printf("enter the number:\n"); scanf("%d",&n); while(n>=1) { r=n%2; n=n/2; printf("%d ",r); if(r==1) s=s+1; } printf("number of bit set is---->%d",s); return 0; }
Q-10- #include<stdio.h> int main() { int i,n; int sum1=0,even=0,evenc=0,oddc=0; int sum2=0,odd=0; float avg1=0,avg2=0; printf("Even count:%d ...Odd count%d..\n",evenc,oddc); printf("Enter the value of n..\n"); scanf("%d",&n); int arr[n]; for(i=0;i<n;i++) { scanf("%d",&arr[i]); if(arr[i]==0) break; } for(i=0;i<n;i++) { if((arr[i]%2)==0) { // if(arr[n]!=0)
sum1+=arr[i]; evenc++; }
else { sum2+=arr[i]; oddc++; } } printf("Even sum=%d ...Odd sum=%d..\n",sum1,sum2); printf("Even count:%d ...Odd count%d..\n",evenc,oddc); return 0; Que-6#include<stdio.h> int main() { int a,b,c,n,i; a=0; b=1; printf("Enter series nos\n"); scanf("%d",&n); printf("Fibo series is ..%d %d\n",a,b); for(i=0;i<=n;i++) { c=a+b; a=b; b=c; printf("%d\n",c); } return 0; }
Que-4 To be cleared ans should be "f is equal to 1" Ans-e<stdio.h> int main() { float f=1.2; int i; printf("size:%d\n",sizeof(f)); // for(i=0;i<10;i++) // f=f+0.1f; printf("f is equal :%f\n",f); printf("size:%d\n",sizeof(f)); if(f==1.2f) printf("f is equal 1.0\n"); else printf("f is not equal 1.0\n");