Mar
25
#include<stdio.h>
void main(){
char name[100];
printf(“Enter Your Name: “);
//scanf(“%s”,name);
gets(name);
printf(“Entered Name is: %s”,name);
}
Mar
25
#include<stdio.h>
void main(){
char name[100];
printf(“Enter Your Name: “);
//scanf(“%s”,name);
gets(name);
printf(“Entered Name is: %s”,name);
}
Mar
25
//string initialization
#include<stdio.h>
#include<stdlib.h>
void main(){
//char nm[40]=”Hello”;
//printf(“%d\n”,sizeof(nm));
//char nm[]=”Hello”;
//printf(“%d\n”,sizeof(nm));
//char nm[]={‘H’,’e’,’l’,’l’,’o’,’\0′};
//printf(“%d\n”,sizeof(nm));
char nm[40]={‘H’,’e’,’l’,’l’,’o’};
printf(“%d\n”,sizeof(nm));
//nm[40]=”Hello”;
//nm[3]=’A’;
printf(“%s”,nm);
}
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);
}
Mar
22
An initiative of MHRD, AICTE, Persistent Systems, i4C, NIC, MyGov
Mar
22
#include<stdio.h>
#include<alloc.h>
void main(){
int *ptr;
int n,i,grt,smt;
printf(“How many numbers you want to enter: “);
scanf(“%d”,&n);
ptr=(int*) malloc(n*sizeof(int));
printf(“Enter %d numbers: \n”,n);
for(i=0;i<n;i++){
scanf(“%d”,(ptr+i));
}
grt=*ptr;
smt=*ptr;
for(i=0;i<n;i++){
if(*(ptr+i)>grt)
grt=*(ptr+i);
if(*(ptr+i)<smt)
smt=*(ptr+i);
}
printf(“Greatest Number among entered %d numbers is: %d\n”,n,grt);
printf(“Smallest Number among entered %d numbers is: %d\n”,n,smt);
printf(“Diff between Smallest and Greatest Number is: %d\n”,(grt-smt));
}
Mar
22
#include<stdio.h>
void main(){
int *ptr;
int n,i;
printf(“How many numbers you want to enter: “);
scanf(“%d”,&n);
ptr=(int*) malloc(n*sizeof(int));
printf(“Enter %d numbers: \n”,n);
for(i=0;i<n;i++){
scanf(“%d”,(ptr+i));
}
printf(“Entered %d numbers are: \n”,n);
for(i=0;i<n;i++){
printf(“%d\n”,*(ptr+i));
}
}
Mar
22
#include<stdio.h>
void main(){
int *ptr;
ptr=(int*) malloc(sizeof(int));
printf(“sizeof(int)= %d\n”,sizeof(int));
printf(“ptr= %u\n”,ptr);
//*ptr=30;
printf(“Enter a Number: “);
scanf(“%d”,ptr);
printf(“*ptr= %d\n”,*ptr);
}
Mar
22
#include<stdio.h>
#include<alloc.h>
int *fact(int *p){
int f=1;
int j;
for(j=1;j<=*p;j++){
f=f*j;
}
return(&f);
}
void main(){
int *ptr;
int n,i,*ff;
printf(“How many numbers you want to enter: “);
scanf(“%d”,&n);
ptr=(int*) malloc(n*sizeof(int));
printf(“Enter %d numbers: \n”,n);
for(i=0;i<n;i++){
scanf(“%d”,(ptr+i));
}
for(i=0;i<n;i++){
ff=fact(ptr+i);
printf(“Factorail of %d is: %d\n”,*(ptr+i),*ff);
}
}