Future Program Assignment
Name – SRISHTY ARYA
Registration no : 2501020340
Year – 1st
Semester – 2nd
Branch – CSE([Link])
1.
int num;
printf("Enter a number :");
scanf("%d",&num);
if(num%2==0){
printf("%d is an even number.\n",num);
}else if(num%2==1){
printf("%d is an odd number.\n",num);
}else
printf("%d is neither odd nor even.\n");
2.
int age;
printf("Enter your age :");
scamf("%d",&age);
if(age<18){
printf("You are a minor.\n");
}else
printf("You are not a minor.\n");
3.
int n;
printf("Enter a number :");
scanf("%d",&n);
if(n>0){
printf("%d is positive number.\n");
}else if(n<0){
printf("%d is a negative number.\n");
}else
printf("%d is neither positive nor negative
number.\n");
4.
int n;
scanf("%d",n);
int r1,r2;
r1=n%10;
n=n/10;
r2=n%10;
if(r1==r2){
printf("%d is a pallidrme.",n);
} printf("%d is not a paliidrome.",n);
5.
int a,b;
printf("Enter two numbers.\n");
scanf("%d,%d",&a,&b);
if(a>b){
printf("%d is the largest.",a);
}
printf("%d is largest.",b);
6.
int CP,SP;
scanf("%d,%d",&CP,&SP);
float profit,loss;
if(SP>CP){
profit=(Sp-CP)*100/CP;
printf("Profit is %.2f",profit);
}else
loss=(CP-SP)*100/CP;
printf("Loss is %.2f",loss);
7.
long int bill;
float dis;
scanf("%ld",&bill);
if(bill<=5000){
if(bill>5000){
printf("You get 30% discount.");
dis=(30*bill)/100;
printf("The discount is %.2f",dis);
}else
printf("You get 20% discount.");
dis=(20*bill)/100;
printf("The discount is %.2f",dis);
}else
printf("No discount.");
8.
long int bill;
int first,float dis;
printf("Are you a first time customer?([Link] or
[Link])");
scanf("%d",&first);
scanf("%ld",&bill);
if(bii>=500&&first==1){
printf("You get 5% discount.");
dis=(5*bill)/100;
printf("The discount is %.2f",dis);
}
9.
float weight;
scanf("%f",&weight);
if(weight>=55&&weight>=90){
printf("You can donate blood.");
}
printf("You can't donate blood.");
10.
char ch;
scanf("%c",&ch);
if(ch==a||ch==A){
printf("%c is a Vowel.",ch);
}
else if(ch==e||ch==E){
printf("%c is a Vowel.",ch);
}
else if(ch==o||ch==O){
printf("%c is a Vowel.",ch);
}
else if(ch==i||ch==I){
printf("%c is a Vowel.",ch);
}
else if(ch==u||ch==U){
printf("%c is a Vowel.",ch);
}else
printf("%c is not a vowel.",ch);
11.
char ch;
scanf("%c",&ch);
if(ch>=A&&ch<=Z){
printf("%c is an uppercase alphabet",ch);
}
else if(ch>=a&&ch<=z){
printf("%c is a lowercase alphabet",ch);
}
else if(ch>='0'&&ch<='9'){
printf("%c is a number",ch);
}
else
printf("%c is a special character",ch);
12.
int n=5;
int digit=0;
while(n!=0){
digit+=1;
n=n/10;
}
if(digit==1){
printf("It is a single digit number.");
}else if(digit==2){
printf("It is a two digit number");
}else if(digit==3){
printf("It is a three digit number");
}else
printf("Other digit");
13.
int unit;
scanf("%d",&unit);
if(unit>0){
if(unit>100){
if(unit>200){
if(unit>300){
Bill=4.4*unit;
printf("The Power Bill is %.2f",Bill);
}
Bill=3.3*unit;
printf("The Power Bill is %.2f",Bill);
}
Bill=2.2*unit;
printf("The Power Bill is %.2f",Bill);
}
Bill=1.1*unit;
printf("The Power Bill is %.2f",Bill);
}
printf("No Power Bill.");
14.
int a,b,c;
scanf("%d,%d,%d",&a,&b,&c);
if(a>b){
if(a>c){
printf("%d is largest integer.",a);
}
printf("%d is largest integer.",c);
}else{
if(b>c){
printf("%d is largest integer.",b);
}
printf("%d is largest integer.",c);
}
15.
float bonus;
long int sales;
scanf("%d",&sales);
if(sales>=50000&&sales<=100000){
if(sales>100000&&sales<=200000){
if(sales>200000&&sales<=500000){
if(sales>500000){
bonus=20*sales/100;
printf("The bonus is %.2f",bonus);
}
bonus=15*sales/100;
printf("The bonus is %.2f",bonus);
}
bonus=12*sales/100;
printf("The bonus is %.2f",bonus);
}
bonus=7*sales/100;
printf("The bonus is %.2f",bonus);
}
bonus=1*sales/100;
printf("The bonus is %.2f",bonus);
16.
int num;
scanf("%d",&num);
if(num==1){
printf("Sunday");
}
if(num==2){
printf("Monday");
}
if(num==3){
printf("Tuesday");
}
if(num==4){
printf("Wednesday");
}
if(num==5){
printf("Thrusday");
}
if(num==6){
printf("Friday");
}
if(num==7){
printf("Saturday");
}
17.
char ch;
scanf("%d",&ch);
if(ch=='A'||ch=='a'||ch=='E'||ch=='e'||ch=='I'||ch=='i'||ch=
='O'||ch=='o'||ch=='U'||ch=='u'){
printf("%c is a vowel.",ch);
}
printf("%c is a consonant",ch);
18.
int a,b;
scanf("%d,%d",&a,&b);
char Operator;
scanf("%c",&Operator);
switch(Operator){
case '+':
printf("The sum is %d",a+b);
break;
case '-':
printf("The difference is %d",a-b);
break;
case '*':
printf("The product is %d",a*b);
break;
case '/':
printf("The division is %f",a/b);
break;
case '%':
printf("The remainder is %d",a%b);
break;
default :
printf("Invalid operator");
}
19.
int celcius;
scanf("%d",&celcius);
float farhenite =(9*celcius)/5+32;
printf("The Farhenite scale reading after conversion
is %f",farhenite);
20.
char ch;
scanf("%c",&ch);
switch(ch){
case 'a':
printf("Good Morning");
break;
case 'e':
printf("Good Afternoon");
break;
case 'm':
printf("Good Evening");
break;
default :
printf("Good Night");
}
Series Program :
1.
int n;
int sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
sum +=i;
2.
int n;
int sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
if(i%2==1){
sum+=i;
}sum-=i;
}
3.
int n;
float x, sum = 0.0;
scanf("%d,%f", &n,&x);
if (x == 0) {
printf("Division not possible.");
return 1;
}
for (int i = 1; i <= n; i++) {
sum += (float)i / x;
}
printf("The sum is %.2f",sum);
4.
int n;
float sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
sum+=(1/i);
}
printf("The sum is %.2f",sum);
5.
int n;
long int fact;
double sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
fact =1;
for(int j=1;j<=i;j++){
fact*=j;
}
sum+=(i*i)/fact;
}
printf("The sum is %.2lf",sum);
6.
int n;
double sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++){
sum+=(1/(i*i));
}
7.
double sum=1;
long int fact =1;
int sign =-1;
int x;
scanf("%d",&x);
for(int i=2;i<=18;i+=2){
for(int j=1;j<=i;j++){
fact*=j;
}
sum+= sign*((x*i)/fact);
sign=-sign;
}
8.
long int sum =0;
long int term =0;
for(int i=0;i<=10;i++){
term term*10 +1;
sum+=term;
}
printf("Sum of 10 terms is %ld",sum);
Loop Logic Program :
1.
int n;
scanf("%d",&n);
int fact=1;
for(int i=1;i<=n;i++){
fact*=i;
}
2.
int n=100;
int sum_odd=0;
int sum_even=0;
for(int i=1;i<=100;i++){
if(i%2==1){
sum_odd+=i;
}sum_even+=i;
}
3.
int n;
scanf("%d",&n);
for(int i=1;i<=10;i++){
printf("%d\n",n*i);
}
4.
int n;
scanf("%d",&n);
if(n%2==1){
printf("%d is odd",n);
}printf("%d is not odd",n);
5.
int n,rem;
scanf("%d",&n);
int new_n=0;
while(n!=0){
rem=n%10;
new_n=new_n*10 +rem;
n=n/10;
}
if(n==new_n){
printf("%d is a pallidrome.",n);
}
printf("%d is not a pallidrome.",n);
6.
int n,rem;
scanf("%d",&n);
int rev_n=0;
while(n!=0){
rem=n%10;
rev_n=rev_n*10 +rem;
n=n/10;
}
printf("%d is the reverse of %d",rev_n,n);
7.
int n,rem;
scanf("%d",&n);
int count=0;
int p=n;
while(p!=0){
count+=1;
p=p/10;
}
p=n;
while(p!=0){
rem=p%10;
sum=pow(rem,count);
p=p/10
}
if(sum==n){
printf("%d is an armstronf number",n)
}
printf("%d is not an armstrong number.",n);
8.
int n,rem;
scanf("%d",&n);
int count=0;
int p=n;
while(p!=0){
count+=1;
p=p/10;
}
p=n;
while(p!=0){
rem=p%10;
sum=pow(rem,count);
p=p/10
}
if(sum==n){
printf("%d is an armstronf number",n)
}
printf("%d is not an armstrong number.",n);
9.
int base,Power;
scanf("%d,%d",&base,&Power);
int result = pow(base,Power);
10.
int n;
scanf("%d",&n);
int sum=0;
for(int i=1;i<=n/2;i++){
if(n%i==0){
sum+=i;
}
}
if(sum==n){
printf("%d is aperfect number.",n);
}
printf("%d is not a perfect number.");
11.
int N,sum;
int n1=0, n2=1;
printf("Enter the number:");
scanf("%d",&N);
for(int i=0;i<N;i++){
printf("\n%d",n1);
sum=n1+n2;
n1=n2;
n2=sum;
}
12.
long long binary;
int decimal =0;
int rem,i=0;
scanf("%lld",&binary);
while(binary!=0){
rem=n%10;
decimal+=rem*pow(2,i);
binary=binary/10;
i++;
}printf("%d is decimal number of
%lld",decimal,binary);
13.
int n1,n2,lcm;
scanf("%d,%d",&n1,&n2);
int p;
if(n1>n2){
p=n1;
}else{
p=n2;
}
while(1){
if(p%n1==0&&p%n2==0){
lcm=max;
break;
}
p++;
} printf("LCM of %d and %d is %d",n1,n2,lcm);
Pattern Programs :
1.
for(int i=1;i<=5;i++){
for(int j=1;j<=i;j++){
printf("%d\t",j);
}printf("\n");
}
2.
for(int i=5;i<=1;i--){
for(int j=1;j>=i;j++){
printf("%d\t",j);
}printf("\n");
}
3.
for(int i=1;i<=5;i++){
for(int j=1;j<=i;j++){
printf("%d\t",i);
}printf("\n");
}
4.
for(int i=5;i<=1;i--){
for(int j=1;j>=i;j++){
printf("%d\t",i);
}printf("\n");
}
5.
int sum=1;
for(int i=1;i<=4;i++){
for(int j=1;j<=i;j++){
printf("%d\t",sum);
sum+=1;
}printf("\n");
}
6.
for(int i=1;i<=5;i++){
for(int j=0;j<i;j++){
printf("%c\t",'A'+j);
}printf("\n");
7.
for(int i=5;i>=1;i--){
for(int j=i;j>=1;j--){
printf("%d\t",j);
}printf("\n");
}
8.
for(int i=1;i<=4;i++){
for(int j=1;j<=2*i-1;j++){
printf("*");
}printf("\n");
}
9.
for(int i=1;i<=4;i++){
for(int j=1;j<=i;j++){
printf("* ");
}printf("\n");
}
10.
for(int i=1;i<=4;i++){
for(int j=1;j<=i;j++){
printf("%d",j);
}
for(int j=i-1;j>=1;j--){
printf("%d",j);
}printf("\n");
}