Friday, 10 April 2020

Program: print table of input number

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,tab;
clrscr();
printf("enter an number to print table");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
tab=n*i;
printf("%d * %d = %d" n,i,tab);
}
getch();
}

Thursday, 9 April 2020

conditional statement part 3 (SWITH)

Program: check number is positive or negative in python

n=eval(input("enter any number"))
if n>=0:
    print(n," is positive")
else:
    print(n, "is negative")

Program: print first 10 natural numbers & their sum

#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum=0;
clrscr();
for(i=1;i<=10;i++)
{
printf(“%d no is= %d\n”,i,I);
sum=sum+i;
}
printf(“sum =%d”,sum);
getch();
}

Write a Program to swap private data members of classes named as class_1, class_2 using friend function.

#include<iostream.h>
#include<conio.h>
class class_2;
class class_1
{ 
int value1;
public: 
void indata(int a) 
{ 
value1=a; 
} 
void display(void) 
{ 
cout<<value1<<"\n"; 
} 
friend void exchange(class_1 &, class_2 &);
};
class class_2
{ 
int value2;
public: 
void indata(int a) 
{ 
value2=a; 
} 
void display(void) 
{ 
cout<<value2<<"\n"; 
} 
friend void exchange(class_1 &, class_2 &);
};
void exchange(class_1 &x, class_2 &y)
{ 
int temp = x.value1; 
x.value1 = y.value2; 
y.value2 = temp;
}
int main()
{ 
class_1 C1; 
class_2 C2;
C1.indata(100); 
C2.indata(200); 
cout<<"Values before exchange"<<"\n";
C1.display(); 
C2.display(); 
exchange(C1, C2); 
cout<<"Values after exchange"<<"\n"; 
C1.display(); 
C2.display(); 
return 0;
} 

Write a program to input a set of 20 letters. Convert each letter into upper case. Find and display the number of vowels and number of consonants present in the set of given letters.

import java.util.Scanner;
public class ATS
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter any 20 letters");
int vc = 0, cc = 0;
for (int i = 0; i < 20; i++)
{
char ch = in.next().charAt(0);           
ch = Character.toUpperCase(ch);
if (ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
                        vc++;
else if (ch >= 'A' && ch <= 'Z')
                cc++;       
}
System.out.println("Number of Vowels = " + vc);
System.out.println("Number of Consonants = " + cc);   
}
}

Wednesday, 8 April 2020

Program: Swap two number using Python

a,b=eval(input("enter two number"))
a,b=b,a
print("number after swapping = ",a,b)