Mar

24

#include<stdio.h>
#include<stdlib.h>
void main(){
int row,col,i,j,sum;
int *ptr;
printf(“Enter How many Rows you want in 2D Array: “);
scanf(“%d”,&row);
printf(“Enter How many Cols you want in 2D Array: “);
scanf(“%d”,&col);
//ptr=(int*) malloc(row*col*sizeof(int));
ptr=(int*) calloc(row*col,sizeof(int));
for(i=0;i<row;i++){
printf(“Enter %d values for row %d:\n”,col,i+1);
for(j=0;j<col;j++){
scanf(“%d”,(ptr+i*col+j));
}
}
printf(“\nEntered Values are:\n”);
for(i=0;i<row;i++){
for(j=0;j<col;j++){
printf(“%d\t”,*(ptr+i*col+j));
}
printf(“\n\n”);
}

for(i=0;i<row;i++){
sum=0;
for(j=0;j<col;j++){
sum=sum+*(ptr+i*col+j);
}
printf(“Sum of Elements in row %d is %d”,i+1,sum);
printf(“\n\n”);
}
free(ptr);
}

Mar

24

#include<stdio.h>
#include<stdlib.h>
void main(){
int row,col,i,j,sum;
int *ptr;
printf(“Enter How many Rows you want in 2D Array: “);
scanf(“%d”,&row);
printf(“Enter How many Cols you want in 2D Array: “);
scanf(“%d”,&col);
ptr=(int*) malloc(row*col*sizeof(int));
for(i=0;i<row;i++){
printf(“Enter %d values for row %d:\n”,col,i+1);
for(j=0;j<col;j++){
scanf(“%d”,(ptr+i*col+j));
}
}
printf(“\nEntered Values are:\n”);
for(i=0;i<row;i++){
for(j=0;j<col;j++){
printf(“%d\t”,*(ptr+i*col+j));
}
printf(“\n\n”);
}

for(i=0;i<row;i++){
sum=0;
for(j=0;j<col;j++){
sum=sum+*(ptr+i*col+j);
}
printf(“Sum of Elements in row %d is %d”,i+1,sum);
printf(“\n\n”);
}
free(ptr);
}

Mar

24

#include<stdio.h>
#include<stdlib.h>
void main(){
int row,col,i,j;
int *ptr;
printf(“Enter How many Rows you want in 2D Array: “);
scanf(“%d”,&row);
printf(“Enter How many Cols you want in 2D Array: “);
scanf(“%d”,&col);
ptr=(int*) malloc(row*col*sizeof(int));
for(i=0;i<row;i++){
printf(“Enter %d values for row %d:\n”,col,i+1);
for(j=0;j<col;j++){
scanf(“%d”,(ptr+i*col+j));
}
}
printf(“\nEntered Values are:\n”);
for(i=0;i<row;i++){
for(j=0;j<col;j++){
printf(“%d\t”,*(ptr+i*col+j));
}
printf(“\n\n”);
}
free(ptr);
}

Mar

23

#include<stdio.h>
void main(){
int r,c;
int i,j;
int *ptr;
printf(“Enter Number of Rows: “);
scanf(“%d”,&r);
printf(“Enter Number of Columns: “);
scanf(“%d”,&c);
ptr=(int*)malloc(r*c*sizeof(int));
for(i=0;i<r;i++){
printf(“Enter %d values for %d row:”,c,(i+1));
for(j=0;j<c;j++){
scanf(“%d”,(ptr+i*3+j));
}
}
for(i=0;i<r;i++){
for(j=0;j<c;j++){
printf(“%d\t”,*(ptr+i*3+j));
}
printf(“\n”);
}
}

Mar

23

#include<stdio.h>
#include<stdlib.h>
void main(){
int *ptr1;
int n,i,j,flg;
printf(“How many numbers you want to enter: “);
scanf(“%d”,&n);
ptr1=(int*) malloc(n*sizeof(int));
printf(“Enter %d numbers:\n”,n);
for(i=0;i<n;i++){
scanf(“%d”,(ptr1+i));
}
// to find the prime numbers
for(i=0;i<n;i++){
//*(ptr1+i);
flg=0;
for(j=2;j<*(ptr1+i);j++){
if(*(ptr1+i)%j==0){
flg=1;
break;
}
}
if(flg==0)
printf(“%d is a Prime Number\n”,*(ptr1+i));
}
free(ptr1);
}

Comments Off on Prime numbers using dynamic memory allocation in 1-D Array prog-5

Jan

28

#include<stdio.h>

#include<conio.h>

void main(){

int num[50],n,i,key;

printf(“Values want to enter: “);

scanf(“%d”,&n);

for(i=0;i<n;i++){

scanf(“%d”,&num[i]);

}

printf(“\nEnter value want to search: “);

scanf(“%d”,&key);

for(i=0;i<n;i++){

if(num[i]==key){

printf(“\nValue %d is at position %d”,key,++i);

break;

}

}

}

//——————————————————————————————————–

#include<stdio.h>

#include<conio.h>

void main(){

int num[50],n,i,key;

printf(“Values want to enter: “);

scanf(“%d”,&n);

for(i=0;i<n;i++){

scanf(“%d”,&num[i]);

}

printf(“\nEnter value want to search: “);

scanf(“%d”,&key);

for(i=0;i<n;i++){

if(num[i]==key){

printf(“\nValue %d is at position %d”,key,i+1);

}

 

}

}

//——————————————————————————————————–

#include<stdio.h>

#include<conio.h>

void main(){

int num[50],n,i,key,flg=0;

printf(“Values want to enter: “);

scanf(“%d”,&n);

for(i=0;i<n;i++){

scanf(“%d”,&num[i]);

}

printf(“\nEnter value want to search: “);

scanf(“%d”,&key);

for(i=0;i<n;i++){

 

if(num[i]==key){

printf(“\nValue %d is at position %d”,key,i+1);

flg=1;

}

}

if(flg==0)

printf(“\nThis number doesnot exist”);

}

//——————————————————————————————————-

#include<stdio.h>

#include<conio.h>

void main(){

int num[50],n,i,key,flg=0;

printf(“Values want to enter: “);

scanf(“%d”,&n);

for(i=0;i<n;i++){

scanf(“%d”,&num[i]);

}

printf(“\nEnter value want to search: “);

scanf(“%d”,&key);

for(i=0;i<n;i++){

 

if(num[i]==key){

printf(“\nValue %d is at position %d”,key,i+1);

flg=1;

}

}

if(flg==0)

printf(“\nThis number doesnot exist”);

}

//—————————————————————————————————-

#include<stdio.h>

#include<conio.h>

void main(){

int num[3][3],i,j;

printf(“Enter Values in 3 x 3 array: “);

for(i=0;i<3;i++){

for(j=0;j<3;j++){

scanf(“%d”,&num[i][j]);

}

}

printf(“\nValues in 3×3 array are:\n”);

for(i=0;i<3;i++){

for(j=0;j<3;j++){

printf(“%6d”,num[i][j]);

}

printf(“\n”);

}

//————–TRANSPOSE

printf(“\nMatrix transpose —\n”);

for(i=0;i<3;i++){

for(j=0;j<3;j++){

printf(“%6d”,num[j][i]);

}

printf(“\n”);

}

}

Aug

10

Campus Commune is a professional network rolled out by TCS for the academic community. It has been acknowledged and appreciated by the student community across India as an effective tool for collaboration. sharing, learning and exploration.

TCS Campus Commune has launched Code Vita (the biggest Coding Contest in India) on 22nd July,13. This contest shall be open to all the students( FY 14,15 and 16 and 17 batches) of your esteemed Institutions. Request you to kindly ask the students from FY 14,15,16 and 17 batch to subscribe to the portal. The process of launching Campus Commune has been attached below. Please share it with all the students at your Institute. The students registering on this portal from a TCS non accredited Institute are called Direct Candidates.

The contest will provide the candidates a competition platform on a national level to test their talents and they will witness a really enriching learning experience.

�The Registration and Team Formation process for Code Vita is open till 12th August,13.

The subscription to TCS Campus Commune is a prerequisite to register and participate in Code Vita. The subscription to Campus Commune is free of cost. Please see the attachment below which needs to be supplemented with the process of launching Campus Commune and sent across to the students.�

FOR MORE DETAILS CLICK THE FOLLOWING URLS:-

Codevita_Participation_Guidelines_For_Direct_Trainees

CodeVita_2013_Registration_and_Team_Formation

Mar

21

 #include <stdio.h>
 #include <string.h>
 
 void main() {
 char *name=(char*)malloc(sizeof(50));
scanf(“%s”,name);
 printf(“\nMy name is %s\r\n”,name) ;

 }

Jan

24

#include<stdio.h>

#include<conio.h>

void main(){

int i,k,n;

char name[50][30],temp[30];

clrscr();

printf(“Enter number of persons: “);

scanf(“%d”,&n);

printf(“\n”);

fflush(stdin);

for(i=0;i<n;i++){

printf(“Enter name of person %d: “,i+1);

gets(name[i]);

}

for(k=0;k<n-1;k++){

for(i=0;i<n-k-1;i++){

if(strcmp(name[i],name[i+1])>0){

strcpy(temp,name[i]);

strcpy(name[i],name[i+1]);

strcpy(name[i+1],temp);

}

}

}

printf(“\nSorted list…\n\n”);

for(i=0;i<n;i++)

puts(name[i]);

getch();

}

Jan

24

#include<stdio.h>

#include<conio.h>

#define MAX 3

void main(){

int m,n,i,j;

//int const num=10;

int arr1[MAX][MAX],arr2[MAX][MAX],arr3[MAX][MAX];

printf(“Enter size of matrics as m,n: “);

scanf(“%d%d”,&m,&n);

if (m>MAX || n>MAX){

printf(“\nMatrix sizes are more than”);

printf(“declared sizes\n”);

exit(1);

}

printf(“Enter%d elements of matrix A row-wise as \n”,m*n);

for(i=0;i<m;i++){

for(j=0;j<n;j++){

scanf(“%d”,&arr1[i][j]);

}

}

for(i=0;i<m;i++){

for(j=0;j<n;j++){

scanf(“%d”,&arr2[i][j]);

}

}

for(i=0;i<m;i++){

for(j=0;j<n;j++){

arr3[i][j]=arr1[i][j]+arr2[i][j];

}

}

for(i=0;i<m;i++){

for(j=0;j<n;j++){

printf(“%d “,arr3[i][j]);

//arr2[j][i]=arr1[i][j];

}

printf(“\n”);

}

getch();

}

Jan

24

#include<stdio.h>

#include<conio.h>

#define MAX 3

void main(){

int i,j,k;

int arr1[MAX][MAX],arr2[MAX][MAX],arr3[MAX][MAX];

printf(“Enter%d elements of matrix A row-wise\n”,MAX*MAX);

for(i=0;i<2;i++){

for(j=0;j<2;j++){

scanf(“%d”,&arr1[i][j]);

}

}

for(i=0;i<2;i++){

for(j=0;j<2;j++){

scanf(“%d”,&arr2[i][j]);

}

}

for(i=0;i<2;i++){

for(j=0;j<2;j++){

arr3[i][j]=0;

for(k=0;k<2;k++){

arr3[i][j]+=arr1[i][k] * arr2[k][j];

}

}

}

for(i=0;i<2;i++){

for(j=0;j<2;j++){

printf(“%d “,arr3[i][j]);

//arr2[j][i]=arr1[i][j];

}

printf(“\n”);

}

getch();

}

Jan

24

#include<stdio.h>

#include<conio.h>

#define MAX 3

void main(){

int i,j;

int arr1[MAX][MAX],arr2[MAX][MAX];

printf(“Enter%d elements of matrix A row-wise\n”,MAX*MAX);

for(i=0;i<3;i++){

for(j=0;j<3;j++){

scanf(“%d”,&arr1[i][j]);

}

}

for(i=0;i<3;i++){

for(j=0;j<3;j++){

arr2[j][i]=arr1[i][j];

}

}

for(i=0;i<3;i++){

for(j=0;j<3;j++){

printf(“%d “,arr2[i][j]);

//arr2[j][i]=arr1[i][j];

}

printf(“\n”);

}

getch();

}

Jan

23

#include<stdio.h>

struct node{

int num;

struct node *left;

struct node *right;

};

typedef struct node NODE;

NODE *root=NULL;

NODE *insert(NODE *tree, int num);

void preorder(NODE *tree);

void inorder(NODE *tree);

void postorder(NODE *tree);

int count=1;

void main(){

int choice;

int digit;

clrscr();

do{

printf(“\nEnter 1 : Insert a node in the BT”);

printf(“\nEnter 2 : Display (preorder) the BT”);

printf(“\nEnter 3 : Display (inorder) the BT”);

printf(“\nEnter 4 : Display (postorder) the BT”);

printf(“\nEnter 5 : END\n”);

scanf(“\n %d”,&choice);

switch(choice){

case 1: printf(“Enter ineger: To quit enter 0:: “);

scanf(“%d”,&digit);

while(digit !=0){

root=insert(root,digit);

scanf(“%d”,&digit);

}

break;

case 2: printf(“\n Preorder traversing TREE”);

preorder(root);

break;

case 3: printf(“\n Inorder traversing TREE”);

inorder(root);

break;

case 4: printf(“\n Postorder traversing TREE”);

postorder(root);

break;

case 5: printf(“\n END”);exit(0);

}

}while(choice>=1 && choice<=5);

}

NODE *insert(NODE *p,int digit){

if(p==NULL){

p=(NODE*) malloc(sizeof(NODE));

p->left=p->right=NULL;

p->num=digit;

}

else{

if(digit<=p->num)

p->left=insert(p->left,digit);

else

p->right=insert(p->right,digit);

}

return(p);

}

void preorder(NODE *p){

if(p!=NULL){

printf(“\n%d”,p->num);

preorder(p->left);

preorder(p->right);

}

}

void inorder(NODE *p){

if(p!=NULL){

inorder(p->left);

printf(“\n%d”,p->num);

inorder(p->right);

}

}

void postorder(NODE *p){

if(p!=NULL){

postorder(p->left);

postorder(p->right);

printf(“\n%d”,p->num);

}

}