Beruflich Dokumente
Kultur Dokumente
11
#include<stdio.h> main() { int n, a, b, c; float area, r, s=3.14; printf("\nchoices:\n 1.sum of nimbers.\n 2.area of circle\n 3. maximum of two numbers\n 4.maximum of three numbers\n Enter oyur choices:"); scanf("%d", &n); switch (n) { case 1: printf("enter the two no"); scanf("%d%d", &a, &b); c=a+b; printf("%d is the sum",c); break; case 2: printf("enter the radius"); scanf("%f", &r); area = s * r * r; printf("%f is the area",area); break; case 3: printf("enter the two numbers"); scanf("%d%d", &a, &b); if(a>b) printf("%d is maximum",a); else printf("%d is maximum",b); break; case 4: printf("enter thtree numbers"); scanf("%d%d%d", &a, &b, &c); if(a>b) { if(a>c) printf("%d is maximum",a); else printf("%d is maximum",c); } else printf("%d is maximum",b); break; }; }
Output:
choices: 1. sum of nimbers. 2. area of circle 3. maximum of two numbers 4.maximum of three numbers Enter your choices : 1 enter the two no 3 6 9 is the sum Enter your choices : 2 enter the radius=6 Area=113.040001 Enter your choices : 3 enter the two numbers 6 9 9 is maximum
EX:NO:2 DATE:1.8.11
#include<stdio.h> main() { int n, a, b, c; short int m; do { printf("\n\t\t\tImplementation of operaters"); printf("\n1.Arithmatic\n2.Relatonal\n3.Logical\n4.conditional\n 5.size of"); printf("\nEnter your choice:"); scanf("%d",&n); switch(n) { case 1: printf("\n\t\t\tAirthmatic operater"); printf("\nEnter the value for a and b:\n"); scanf("%d%d",&a,&b); printf("\nsum=%d",a+b); printf("\ndifference=%d",a-b); printf("\nproduct==%d",a*b); printf("\nreminder=%d",a%b); printf("\nquantient=%d\n",a/b); break; case 2: printf("\n\t\t\tRelational operater"); printf("\nEnter a number:"); scanf("%ld",&a); if(a>0) printf("\n%d is positive",a); else if(a==0) printf("\n%d is poasitive nor negative",a); else printf("\n%d is negative",a); break; case 3: printf("\n\t\t\tLogical operater"); printf("\nEnter two numbers:"); if((0<=a<=1)&&(0<=b<=1)) { scanf("\n%d\n%d", &a,&b); printf("\nAND=%d",a&&b); printf("\nOR=%d",a||b); printf("\nNOT=%d",!a); }
else printf("\npls Enter the numbers 1's and 0,s."); break; case 4: printf("\n\t\t\tConditional operaters\n"); printf("\nenter two numbers:\n"); scanf("%d%d",&a,&b); printf("\n%d is maximum",(a>b)?a:b); break; case 5: printf("size of m=%d",sizeof(m)); break; }; } while(n>=1&&n<=5); }
OUTPUT
Implementation of operators 1. Arithmatic 2. Relatonal 3. Logical 4. Conditional 5. Size of Enter your choice: 1 Airthmatic operater Enter the value for a and b: 6 3 sum=9 difference=3 product==18 reminder=0 quantient=2 Enter your choice: 2 Relational operater Enter a number : 3 3 is positive Enter your choice: 3 Logical operater AND = 1 OR = 1 NO = 0 Enter your choice : 4 Conditional operators enter two numbers:6 3 6 is maximum
SUM OF DIGITS
EX NO:3
DATE:1.8.11 #include<stdio.h> main() { long int n; int sum=0; printf("\n Enter the number:"); scanf("%d",&n); while(n>0) { sum=sum+(n%10); n=n/10; } printf(" \n%d is the sum of digits\n\n\n",sum); }
Output:
Enter the number: 321654
21 is the sum of digits
Output:
Enter the number The reverse is 654. . : 456
FIBONOCCI SERIES
EX NO:5 DATE:8.8.11
#include<stdio.h> main() { int n,i,x1=-1,x2=1,x3; printf("enter the number of terms:"); scanf("%d",&n); printf("\n the series is...."); for(i=0;i<n;i++) { x3=x1+x2; x1=x2; x2=x3; printf("\n%d\n",x3); } }
Output:
enter the number of terms:5 the series is.... 0 1 1 2 3
Output:
Enter the number:5 The factorial value is...120
ARMSTRONG NUMBER
EX NO:7 DATE:17.8.11
#include<stdio.h> main() { int n,n1,p,s=0; printf("enter n value:"); scanf("%d%",&n); n1=n; while(n!=0) { p=n%10; s=s+(p*p*p); n=n/10; } if (s==n1) printf("\n the no is ARMSTRONG\n"); else printf("\n the no is not ARMSTRONG\n"); }
Output:
Enter n value:153 the no is ARMSTRONG
Output:
Enter the number: 12 the series is.... 2 3 5 7 11
Output:
Enter the number:2 tables for 2 2*1=2 2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18 2*10=20
Output:
1. Normal triangle. 2. Reversed triangle Enter your choice: 1 Enter the number: 5 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1. Normal triangle. 2. Reversed triangle Enter your choice: 2 Enter the number: 5 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1 5 4 3 2 1 4 3 2 1 3 2 1 2 1 1
Output:
Enter the customer id : 1001
Enter the customer name : aswin Enter the units consumed : 126 **************** Charge **************** customer id customer name date of payment units consumed charges
Out put:
1.sum of number 2.power Enter ur choice : Enter the number:
1 5
the numbers are 1 2 3 4 5 the squres are 1 4 9 16 25 the sum of numbers is 15 tne sum of squres is 55 Enter your choice : 2 Enter the number : 6 Enter the power : 3
PERFECT NUMBER
EX NO:13 DATE:12.9.11
#include<stdio.h> main() { int n,i=1,s,sum=0; printf("Enter the number:"); scanf("%d",&n); while(i<n) { s=n%i; if(s==0) { sum=sum+i; } i++; } if(sum==n) printf("%d is perfect",n); else printf("%d is not perfect",n); }
Output:
Enter the number: 6 6 is perfect number.