Write a c program to find the sum of the digits of a number?
#include<iostream>
int sum_digits(int num, int base=10)
{
int sum=0;
while( num )
{
sum+=num%base;
num/=base;
}
return(sum);
}
int main()
{
int sum=sum_digits(42);
// assert( sum==6);
}
//Written in C++. ALFRED OMONDI ORIMBO (orimbo@gmail.com)
# include
# include
using namespace std;
void main()
{
double s,a,b,c,area;
cout<<"type a value for first side of triangle: ";
cin>>a;
cout<<"\ntype a value for second side of triangle: ";
cin>>b;
cout<<"\ntype a value for third side of triangle: ";
cin>>c;
s=(a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
cout<<"\narea = "<
}
What electronic data prossing modes?
1)online processing
2)real-time processing
3)distributed processing
4)time-sharing
5)batch processing
6)multiprocessing
7)multitasking
8)interactive procrssing
well animation can mostly consist of Japanese cartoons but mostly means to turn into a cartoon of somesort so yeah look up funimation they animate many things.
# include < stdio.h >
# include < stdlib.h >
struct list
{
char info[20];
struct list *next;
struct list *prev;
};
struct list *new1,*node;
void create(struct list *s,struct list *e)
{
char ch;
node=s;
printf("\nWant to create a node(y/n):");
ch=getche();
while (ch != 'n')
{
node->next = (struct list *) malloc(sizeof(struct list));
node->next->prev= node;
node = node->next;
printf("\n Enter the string value:- ");
gets(node->info);
node->next = e;
e->prev=node;
printf("\n Enter choice--'n' for break: ");
ch = getche();
}
}
void displayL (struct list *s,struct list *e)
{
node = s->next;
while (node!=e)
{
printf(" 0x%x--%s", node,node->info);
node = node->next;
}
printf("\n");
}
void displayR (struct list *e,struct list *s)
{
node = e->prev;
while (node!=s)
{
printf(" 0x%x--%s", node,node->info);
node = node->prev;
}
printf("\n");
}
void insertA(struct list *s)
{
struct list *new1;
int c=1,count;
printf("\nEnter the location:");
scanf("%d",&count);
fflush(stdin);
new1 = (struct list *) malloc(sizeof(struct list));
printf("\nEnter the new value:");
gets(new1->info);
node=s->next;
while(node)
{
if(c==count)
break;
node=node->next;
c++;
}
node->prev->next=new1;
new1->prev=node->prev;
new1->next=node;
node->prev=new1;
}
void main()
{
struct list *start,*end;
clrscr();
start=(struct list *) malloc(sizeof(struct list));
end=(struct list *) malloc(sizeof(struct list));
create(start,end);
printf("\n Created list is as follows(L ->R)\n");
displayL(start,end);
printf("\n Created list displayed from R->L\n");
displayR(end,start);
printf("\nInserting a new location at user specified location\n");
insertA(start);
printf("\n now the listfrom L ->R\n");
displayL(start,end);
printf("\n list from R to L after insertion\n");
displayR(end,start);
getch();
}
Is the IB program better than the AICE program?
No. IB is pretty good, but the newest edition of the AICE Cambridge Curriculum is far the best.
if single line comment just place // before for single line comment else if multiple line denote as like this /*.............................
..............................*/
Strictly speaking, // is non.standard in C only in C++
Insert algorithm for circular queue in data structures?
In a standard queue data structure re-buffering problem occurs for each dequeue operation. To solve this problem by joining the front and rear ends of a queue to make the queue as a circular queue
Circular queue is a linear data structure. It follows FIFO principle.
Circular Queue can be created in three ways they are
· Using single linked list
· Using double linked list
· Using arrays
Using single linked list:
It is an extension for the basic single linked list. In circular linked list Instead of storing a Null value in the last node of a single linked list, store the address of the 1st node (root) forms a circular linked list. Using circular linked list it is possible to directly traverse to the first node after reaching the last node.
The following figure shows circular single linked list:
Using double linked list
In double linked list the right side pointer points to the next node address or the address of first node and left side pointer points to the previous node address or the address of last node of a list. Hence the above list is known as circular double linked list.
The following figure shows Circular Double linked list :-
Algorithm for creating circular linked list :-
Step 1) start
Step 2) create anode with the following fields to store information and the address of the next node.
Structure node
begin
int info
pointer to structure node called next
end
Step 3) create a class called clist with the member variables of pointer to structure nodes called root, prev, next and the member functions create ( ) to create the circular linked list and display ( ) to display the circular linked list.
Step 4) create an object called 'C' of clist type
Step 5) call C. create ( ) member function
Step 6) call C. display ( ) member function
Step 7) stop
Algorithm for create ( ) function:-
Step 1) allocate the memory for newnode
newnode = new (node )
Step 2) newnode->next=newnode. // circular
Step 3) Repeat the steps from 4 to 5 until choice = 'n'
Step 4) if (root=NULL)
root = prev=newnode // prev is a running pointer which points last node of a list
else
newnode->next = root
prev->next = newnode
prev = newnode
Step 5) Read the choice
Step 6) return
Algorithm for display ( ) function :-
Step 1) start
Step 2) declare a variable of pointer to structure node called temp, assign root to temp
temp = root
Step 3) display temp->info
Step 4) temp = temp->next
Step 5) repeat the steps 6 until temp = root
Step 6) display temp info
Step 7) temp=temp->next
Step 8) return
Using array
In arrays the range of a subscript is 0 to n-1 where n is the maximum size. To make the array as a circular array by making the subscript 0 as the next address of the subscript n-1 by using the formula subscript = (subscript +1) % maximum size. In circular queue the front and rear pointer are updated by using the above formula.
The following figure shows circular array:
Algorithm for Enqueue operation using array
Step 1. start
Step 2. if (front == (rear+1)%max)
Print error "circular queue overflow "
Step 3. else
{ rear = (rear+1)%max
Q[rear] = element;
If (front == -1 ) f = 0;
}
Step 4. stop
Algorithm for Dequeue operation using array
Step 1. start
Step 2. if ((front == rear) && (rear == -1))
Print error "circular queue underflow "
Step 3. else
{ element = Q[front]
If (front == rear) front=rear = -1
Else
Front = (front + 1) % max
}
Step 4. stop
List of not object-oriented programming languages?
Languages like C, Pascal, Basic do not use classes, polymorphism, etc, they promote functional style of programming.
Languages like PHP, Perl, Python, Ruby provide you with the opportunity to choose whether you like to program using classes, in other words in the object-oriented way, or adhere to functional programming - depending on what is optimal for the project you are working on.
Are constructors allowed to have a return statement in them?
NO...The reason being, when you return something, someone is supposed to receive what you are returning...So when the object is not yet created, there wont be any body to receive it.
memcpy function is used to copy memory area. Syntax ------ void *memcpy(void *dest, const void *src, size_t n); *dest is a destination string. *src is a source string. n is a number of characters to be copied from source string. Example: #include #include main() { char src[]="Hello World"; char des[10]; memcpy(des,src,5); printf("des:%s\n",des); //It will contain the string "Hello". }
What are Semantic errors in a programming language?
Semantic or Syntax errors are errors in the way a programmer has written his code. The code does not conform to language standards and is incorrect.
Ex:
for(int i = 0, i++, i<10) {
}
The above is a syntactically incorrect declaration of a for loop in Java. The compiler would not let you compile this code successfully.
Most commonly it's used to remove the newline character from the end of a string or an array of strings. If the newline character isn't there, then nothing is done to the string.
There are other details involved in what chomp does, but mostly that is what it is used for.
For instance you can change which character is considered the be the newline character. If you want to know more, I would suggest reading the documentation.
They don't. All compilers produce machine code by default, with the exception of the Java compiler which emits Java byte code suitable for interpretation by the Java virtual machine at runtime.
What you call assembly is actually the disassembled machine code. That is, the machine code produced by the compiler is translated into the equivalent disassembly. This is the code you see when you hit a breakpoint and examine the disassembled machine code. You will also see disassembly when debugging code for which no source code exists (as is the case with most 3rd party libraries).
If you wish to view the actual assembly, along with your comments and source code, then you have to configure your compiler to emit assembly rather than the default machine code. You would do this if you wished to tweak the assembled code prior to final assembly, for instance, to take advantage of manual optimisations. However, modern compilers are capable of optimising code more efficiently and more easily than any human can so there's rarely a need to manually optimise.
Electricity bill preparation source codes in java?
import java.io.*;
import java.lang.*;
class electricity extends Exception
{
int b1;
electricity(int b)
{
b1=b;
System.out.println("\n\t\t Exception will caught below ");
}
}
class electric
{
static void compute(int a,int b,String name,String bno)throws IOException,electricity
{
name=name;
bno=bno;
if(b<a)
throw new electricity(b);
else
{
int tmr,amt=0,z=0;
tmr=b-a;
do
{
DataInputStream in=new DataInputStream(System.in);
System.out.println("\n\t Click any purpose ");
System.out.println("\n\t\t 1-Domestic ");
System.out.println("\n\t\t 2-Agriculture ");
System.out.println("\n\t\t 3-Industry ");
System.out.println("\n\t\t 4.Exit");
System.out.println("\n\n\t\t Enter ur Choice :");
int ch=Integer.parseInt(in.readLine());
switch(ch)
{
case 1:
if(tmr<=100)
amt =tmr *2;
else if(tmr >100 && tmr <=200)
amt=(tmr-100) *4 +100*2;
System.out.println("\n\n\t\t **********************************************");
System.out.println("\t\t\t Electricity Bill Preparation ");
System.out.println("\t\t **********************************************\n\n");
System.out.println("\n\t\t Name : " +name + " Bill no : " + bno );
System.out.println("\n\t\t Previous Meter Reading : " +a );
System.out.println("\n\t\t Closed Meter Reading :" +b );
System.out.println("\n\t\t Current Meter Reading :" +tmr );
System.out.println("\n\t\t Purpose : Domestic " );
System.out.println("\n\t\t Total Amount Rs. :" +amt );
break;
case 2:
if(tmr<=100)
amt =tmr *0;
else if(tmr >100 && tmr<=200)
amt=(tmr-100) *1 +100*0;
System.out.println("\n\n\t\t **********************************************");
System.out.println("\t\t\t Electricity Bill Preparation ");
System.out.println("\t\t **********************************************\n\n");
System.out.println("\n\t\t Name : " +name + " Bill no : " + bno );
System.out.println("\n\t\t Previous Meter Reading : " +a );
System.out.println("\n\t\t Closed Meter Reading :" +b );
System.out.println("\n\t\t Current Meter Reading :" +tmr );
System.out.println("\n\t\t Purpose : Agriculture " );
System.out.println("\n\t\t Total Amount Rs. :" +amt );
break;
case 3:
if(tmr<=100)
amt =tmr *4;
else if(tmr >100 && tmr<=200)
amt=(tmr-100) *8 +100*4;
System.out.println("\n\n\t\t **********************************************");
System.out.println("\t\t\t Electricity Bill Preparation ");
System.out.println("\t\t **********************************************\n\n");
System.out.println("\n\t\t Name : " +name + " Bill no : " + bno );
System.out.println("\n\t\t Previous Meter Reading : " +a );
System.out.println("\n\t\t Closed Meter Reading :" +b );
System.out.println("\n\t\t Current Meter Reading :" +tmr );
System.out.println("\n\t\t Purpose : Industry " );
System.out.println("\n\t\t Total Amount Rs. :" +amt );
break;
case 4:
System.exit(0);
}
System.out.println("\n\t Continue :");
z=Integer.parseInt(in.readLine());
} while(z==1);
}
}
public static void main(String ar[])throws IOException
{
electric ee=new electric();
String name,bno;
int pmr,cmr;
DataInputStream in=new DataInputStream(System.in);
System.out.println("\n\t ELECTRICITY BILL USING USERDEFINED EXCEPTION ");
System.out.print("\n\t\t Enter the name : ");
name=in.readLine();
System.out.print("\n\t\t Enter the Bill Number :");
bno=in.readLine();
System.out.print("\n\t\t Previous Meter Reading : ");
pmr=Integer.parseInt(in.readLine());
System.out.print("\n\t\t Current Meter Reading : ");
cmr=Integer.parseInt(in.readLine());
try
{
compute(pmr,cmr,name,bno);
}
catch(Exception e)
{
System.out.println("\n\t\tUserDefined Exception is found");
}
}
}
Palindrome program by using array C?
#include<stdio.h>
#include<math.h>
int main()
{
int num,a,b,c,d,y,k=0;
printf("Enter no.\n");
scanf("%d",&num);
y=num;
for(a=0;a<=num;a++)
{ c=pow(10,a);
d=num/c;
if (d>=1)
k=k+1;
else
break;}
printf(" an aaray of dimension %d" ,k);
int v1[k],v2[k];
int l=0,i,e,f;
for(i=k-1;i>=0;i--)
{
e=pow(10,i);
f=num/e;
v1[l]=f;
l++;
num=num%e;
}
int q,r,t=0,s=0;
q=y;
for(i=k-1;i>=0;i--)
{while(q!=0)
{
r=q%10;
v2[t]=r;
t++;
q=q/10;
}}
for (i=0;i<=k-1;i++)
{if(v1[i]==v2[i])
s++;}
if(s==k)
printf("the no.is palindrome\n");
else
printf("not a palindrome");
return 0;
}
In a queue if rear equals front then what will be the queue?
if the queue contains one element then front end is equal to the rear end.
Program for marksheet in c language?
The std::cout and std::cin streams are peculiar to the C++ standard library. They are not available in the C standard library, but are analogous to stdin and stdout which is in the C standard library.
Is artificial intelligence a good idea?
Some love artificial intelligence because they think it will make their life easier for the-- which is true but there are disadvantages as well. Suppose the fact that these things will only be machines and they will not always listen to command especially if they are programed as a complete human. Some hate the very idea of A.I. because they have problems with the fact that the robots might 'take over the word' or the fact that the robots will take our jobs and we will be left money-less.