//wap to find sum of series 1^2,3^2,5^2,7^2.......nth term. #include #include int main(){ int i,n,sum=0,x,y; printf("enter a number upto which u want sum : \n"); scanf("%d",&n); //5 for(i=1;i<=n;i=i+2){ x=pow(i,2); sum=sum+x; } printf("sum is %d",sum);//35 } //wap to enter marks of 5 diff subjects and find result. find result as passed if he/she gets 40 out of 100 in each subject. Also calculate the percentage and division as: // If percent is >= 80, => Distinction // If percent is >= 70, first division //If percent is >=55, second division //If percent is >=40, passed , otherwise failed. #include #include int main (){ int mark,percent,a,b,c,d,e; printf("enter marks of 5 different subjects"); scanf("%d%d%d%d%d",&a,&b,&c,&d,&e); mark=a+b+c+d+e; if(a>=40&&b>=40&&c>=40&&d>=40&&e>=40){ printf("You've passed the exam"); } else{ printf("You've failed, keep working hard"); } percent=mark/5; printf("\nYour percentage is %d",percent); if(percent>=80){ printf("\nDistinction"); } else if(percent>=70){ printf("\nFirst Division"); } else if(percent>=55){ printf("\nSecond Division"); } else if(percent>=40){ printf("\nJust Passed"); } else{ printf("\n So, you've got no rank"); } } //6. NTC charges the following rate for local calls from a customer. //CALLS //CHARGES //<=175 Rs 200 // >175 Rs 1 per extra call //TSC =10% of Total Charge //VAT=13%(Total charge+TSC) //WAP to display all the info including the amount paid by the customer, if the total number of calls is given. #include #include int main(){ int calls,charges,vat,tsc,total; printf("enter total number of calls"); scanf("%d",&calls); if(calls<=175){ charges=200; } else if(calls>=175){ charges=200+(calls-175); } tsc=0.1*charges; vat=0.13*(charges+tsc); printf("Total charge is %d, tsc is %d and vat is %d",charges,tsc,vat); return 0; } //WAP to input all side of triangle and check whether triangle is valid or not. #include #include int main(){ int a,b,c; printf("enter all 3 sides of a triangle"); scanf("%d%d%d",&a,&b,&c); if(a>0&&b>0&&c>0&&a+b>c&&b+c>a&&a+c>b){ printf("triangle is valid"); } else{ printf("Invalid triangle"); } return 0; } //WAP to find greatest number among three given by the user using ternary operator. #include #include int main(){ int a,b,c; printf("enter 3 numbers"); scanf("%d%d%d",&a,&b,&c); (a>b&&a>c)?printf("%d is greater",a):(b>c)?printf("%d is greater",b):printf("%d is greater",c); return 0; } //WAP to input angle of a triangle and check whether triangle is valid or not. #include #include int main(){ int a,b,c; printf("enter 3 angles of a triangle"); scanf("%d%d%d",&a,&b,&c); if(a>0&&b>0&&c>0&&a+b+c==180){ printf("Triangle is valid"); } else{ printf("Invalid Triangle"); } return 0; } //WAP to display all those armstrong numbers from 100 to 500 and count the displayed numbers. #include #include int main(){ int i,a,b,sum; for(i=100;i<500;i++){ int num=i; sum=0; while(num>0){ a=num%10; b=pow(a,3); sum=sum+b; num=num/10; } if(sum==i){ printf("%d \n",i); } } } //WAP to swap first and last digit of a number. #include #include int main(){ int n,a,swap=0; printf("enter any number");//345 scanf("%d",&n); while(n>0){ a=n%10; //345%10=5 n=n/10;//345/10=34 swap=a; printf("%d",swap); } } //Write a menu driven program to have the following menu: //a) factorial // b) Area and perimeter of rectangle. // c) Exit // The program must repeat until user wants. #include #include int main(){ int press; do{ printf("Press 1 to find factorail.\n Press 2 tp find area and perimeter of rectange.\n Press 3 to exit the program."); scanf("%d",&press); switch(press){ case 1:{ int f,fact=1; printf("enter num to find factorial"); scanf("%d",&f); for(int i=f;i>=1;i--){ fact=i*fact; } printf("%d is factorial \n",fact); break; } case 2:{ int l,b; printf("enter length and breadth of rectangle"); scanf("%d%d",&l,&b); int area=l*b; int peri=2*(l+b); printf("area is %d and perimeter is %d \n",area,peri); break; } case 3:{ break; } default :{ printf("Invalid number, try again. \n"); } } } while(press!=3); return 0; }