Sie sind auf Seite 1von 12

program.

1
Find the area of triangle

#include<stdio.h> #include<math.h> main() { int b,h; float area=0; printf("Enter the base and height \n"); scanf("%d%d",&b,&h); area=(0.5*b*h); printf("The area of triangle is %.3f",area); printf("\n"); }

program.2 #include<stdio.h> main() { int p,t,r; float si=0; clrscr(); printf("Enter the principle,rate,interest \n"); scanf("%d%d%d",&p,&t,&r); si=(p*t*r)/100; printf("The simple interst is %.3f",si); printf("\n"); }

program.3 #include<stdio.h> main() { int n; clrscr(); printf("Enter the number \n"); scanf("%d",&n); if(n%2==0) printf("\nThe number is even"); else printf("\nThe number is odd"); printf("\n"); }

program.4 #include<stdio.h> main() { int n; clrscr(); printf("Enter the number \n"); scanf("%d",&n); if(n>0) printf("The given number is positive \n"); else printf("The given number is negative "); printf("\n"); }

program.5 #include<stdio.h> main() { int a,b,c,big; clrscr(); printf("Enter three numbers \n"); scanf("%d%d%d",&a,&b,&c); big=a; if(b>big) big=b; if(c>big) big=c; printf("The largest of three number is %d",big); printf("\n"); }

program.6
* program to design a simple calculator */ #include<stdio.h> main() { int a,b; char c; clrscr(); printf("Enter two numbers \n"); scanf("%d %d",&a,&b); printf("+:add -:sub *:mul and / divide \n"); scanf(" %c",&c); switch(c) { case '+':printf("The sum of numbers =%d",a+b); break; case '-':printf("The sub of numbers =%d",a-b); break; case '*':printf("The product of numbers =%d",a*b); break; case '/':if(b==0) { printf("\nDivision is not possible"); exit(0); } else printf("The division of numbers =%d",a/b); break; default:printf("Invalid chioce"); } printf("\n"); }

Program7 #include<stdio.h> #include<math.h> main() { int i,f=1,n; clrscr(); printf("Enter the number \n"); scanf("%d",&n); for(i=2;i<=n/2;i++) { if(n%i==0) { f=0; break; } } if(f==1) printf("\nThe given number is prime"); else printf("\nThe given number not a prime"); printf("\n"); }

program.8 /* program to find sum of positive and negative elements of array */ #include<stdio.h> #include<math.h> main() { int i,n,a[100]; float sp=0,np=0,sum=0,avg=0; clrscr(); printf("Enter the length of array \n"); scanf("%d",&n); printf("Enter the elements of array \n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) { if(a[i]>0) sp+=a[i]; else np+=a[i]; } sum=np+sp; avg=sum/n; printf("\nThe sum of positive is %.2f",sp); printf("\nThe sum of negative is %.2f",np); printf("\nThe avg of array elements is %.2f",avg); printf("\n");

program.9 #include<stdio.h> #include<math.h> main() { int i, n,key,flag=0,a[100]; clrscr(); printf("Enter the number of elements \n"); scanf("%d",&n); printf("Enter the array elements \n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); printf("Enter the element to be search \n"); scanf("%d",&key); for(i=1;i<=n;i++) if(a[i]==key) { flag=1; break; } if(flag==1) printf("\nSuccesful search"); else printf("\nUnsuccesful search"); printf("\n"); }

program.10 /* program to arrage the names in alphabetical order */ #include<stdio.h> #include<math.h> main() { int i,j,n; char s[20][20],t[20]; clrscr(); printf("Enter the number of names \n"); scanf("%d",&n); printf("Enter the names\n"); for(i=0;i<=n;i++) gets(s[i]); for(i=0;i<n-1;i++) for(j=0;j<n-i;j++) if(strcmp(s[j],s[j+1])>0) { strcpy(t,s[j]); strcpy(s[j],s[j+1]); strcpy(s[j+1],t); } printf("\n\nThe alphabetical order \n"); for(i=0;i<=n;i++) printf("%s\n",s[i]); printf("\n");
}

program.12
#include<stdio.h> main() { int n,i,sum=0; clrscr(); printf("Enter the number \n"); scanf("%d",&n); for(i=1;i<=n;i++) sum=sum+i; printf("The sum is %d",sum); printf("\n"); }

Das könnte Ihnen auch gefallen