Jan

10

C Programming Tutorial by Akhilesh Mishra and Kiran Maurya (BCA-V, 2019-2022 batch)- SMS VARANASI

Download

Mar

04

 
 
 

 
 
 #include<stdio.h>
 void main(){
 //printf("Eneter a number:");
 int i=10;
 int *p=&i;
 printf("%d\n",i);
 printf("%d\n",&i);
 printf("%d\n",&p);
 printf("%d\n",p);
 printf("%d\n",*p);
 }
 #include<stdio.h>
 void main(){
 int i=10;
 int *p=&i;
 *p=20;
 printf("%d\n",i);
 printf("%d\n",*p);
 }
 #include<stdio.h>
 void main(){
 int i=10;
 int *p;
 p=&i;
 //int *p=&i;
 *p=20;
 i=*p+20;
 printf("%d\n",i);
 printf("%d\n",*p);
 }
 #include<stdio.h>
 void ch(int n){
       n=n+10;
       printf("Hello ch(%d)\n",n);
 }
 void main(){
       int a=60;
 ch(a);
 printf("a=%d\n",a);
 }
 #include<stdio.h>
 void ch(int *n){
       *n=*n+10;
       printf("Hello ch(%d)\n",*n);
 }
 void main(){
       int a=60;
 ch(&a);
 printf("a=%d\n",a);
 }
 #include<stdio.h>
 void ch(int *n){
       *n=*n+10;
       printf("Hello ch(%d)\n",*n);
 }
 void main(){
       int a=60;
 ch(&a);
 a=a+10;
 printf("a=%d\n",a);
 }
 #include<stdio.h>
 void main(){
       int num=20;
       //int *ptr=#
       int *ptr;
       ptr=#
       printf("num=%d\n",num);
       printf("*ptr=%d\n",*ptr);
       num=num*5;
       *ptr=*ptr+100;
       printf("num=%d\n",num);
       printf("*ptr=%d\n",*ptr);
       printf("Address of num=%d\n",&num);
       printf("Address of num=%d\n",ptr);
       printf("Address of ptr=%d\n",&ptr);
 }
 #include<stdio.h>
 void main(){
       int num1=20;
       int num2=50;
       int *ptr;
       printf("value of num1=%d\n",num1);
       printf("value of num2=%d\n",num2);
       ptr=&num1;
       num1=num2;
       num2=*ptr;
       printf("value of num1=%d\n",num1);
       printf("value of num2=%d\n",num2);
 }
 #include<stdio.h>
 void main(){
       int num1=20;
       int num2=50;
       int ptr;
       printf("value of num1=%d\n",num1);
       printf("value of num2=%d\n",num2);
       ptr=num1;
       num1=num2;
       num2=ptr;
       printf("value of num1=%d\n",num1);
       printf("value of num2=%d\n",num2);
 }
 #include<stdio.h>
 void main(){
       int num;
       int *ptr;
       ptr=#
       printf("Enter a Number:");
       scanf("%d",ptr);
       printf("Square of Number is %d\n",(*ptr * *ptr));
 }
  
 #include<stdio.h>
 #include<stdlib.h>
 void main(){
       int *ptr;
       ptr=(int*) malloc(sizeof(int));
       printf("Enter a Number:");
       scanf("%d",ptr);
       printf("Square of Number is %d\n",(*ptr * *ptr));
 }
  
 #include<stdio.h>
 #include<stdlib.h>
 int swap1(int n1,int n2){
       int tmp=n1;
       n1=n2;
       n2=tmp;
 }
 int swap2(int *n1,int *n2){
       int tmp=*n1;
       *n1=*n2;
       *n2=tmp;
 }
 void main(){
       int a,b;
       printf("Enter two numbers:\n");
       scanf("%d%d",&a,&b);
       printf("a=%d \t b=%d \n",a,b);
       swap1(a,b);
       printf("a=%d \t b=%d \n",a,b);
       swap2(&a,&b);
       printf("a=%d \t b=%d \n",a,b);
 }
  
 #include<stdio.h>
 void main(){
       int n;
       int *ptr;
       ptr=&n;
       printf("Enter a number: \n");
       scanf("%d",ptr);
       printf("Square is: %d",*ptr * *ptr);
 }
 #include<stdio.h>
 void main(){
       int *ptr;
       ptr=(int*) malloc(sizeof(int));
       printf("Enter a number: \n");
       scanf("%d",ptr);
       printf("Sum is: %d",*ptr + *ptr);
 }
 #include<stdio.h>
 #include<stdlib.h>
 void main(){
       int *ptr1,*ptr2;
       ptr1=(int*) malloc(sizeof(int));
       ptr2=(int*) malloc(sizeof(int));
       printf("Enter two number: \n");
       scanf("%d",ptr1);
       scanf("%d",ptr2);
       printf("Sum is: %d",*ptr1 + *ptr2);
 }
 #include<stdio.h>
 #include<stdlib.h>
 void main(){
       char *ptr1;
       ptr1=(char*) malloc(sizeof(char));
       printf("Enter A char: \n");
       scanf("%c",ptr1);
       printf("Char is: %c",*ptr1);
 }
 #include<stdio.h>
 #include<stdlib.h>
 void main(){
       char *ptr1;
       ptr1=(char*) malloc(sizeof(char));
       printf("Enter A char: \n");
       scanf("%c",ptr1);
       printf("Char is: %c",*ptr1);
 }
   

May

04

File Handling in C Programs-1

Apr

21

Structure program in C – 1

Mar

30

//concat strings
#include<stdio.h>
void main(){
char st1[50],st2[50],st3[100];
int i,j;
printf(“Enter First string: “);
gets(st1);
printf(“Enter First string: “);
gets(st2);
for(i=0;st1[i]!=’\0′;i++){
st3[i]=st1[i];
}
j=i;
for(i=0;st2[i]!=’\0′;i++){
st3[j]=st2[i];
j++;
}
//puts(st3);
}

Mar

30

//reverse strings
#include<stdio.h>
void main(){
char st1[100];
int i,j;
printf(“Enter First string: “);
gets(st1);

for(i=0;st1[i]!=’\0′;i++);
for(j=i-1;j>=0;j–){
printf(“%c”,st1[j]);
}
}

Mar

30

//compare strings
#include<stdio.h>
void main(){
char st1[100],st2[100];
char ch;
int i,j,k,flg=0;
printf(“Enter First string: “);
gets(st1);
printf(“Enter Second string: “);
gets(st2);
for(i=0;st1[i]!=’\0′;i++);// to get the length of st1
for(j=0;st2[j]!=’\0′;j++);// to get the length of st2
if(i==j){
for(k=0;k<i;k++){
if(st1[k]!=st2[k]){
flg=1;
break;
}
}
if(flg==0)
printf(“Both Strings are same”);
else
printf(“Both Strings are not same”);
}
else{
printf(“Both Strings are not same”);
}
}

Mar

30

/*
HELLO
HELL
HEL
HE
H
*/

#include<stdio.h>
void main(){
char st[100];
char ch;
int i,j,k;
printf(“Enter a string: “);
gets(st);
for(i=0;st[i]!=’\0′;i++);
for(j=i-1;j>=0;j–){
for(k=0;k<=j;k++){
printf(“%c”,st[k]);
}
printf(“\n”);
}
}

Mar

30

/*
HHHHH
EEEE
LLL
LL
O
*/

#include<stdio.h>
void main(){
char st[100];
char ch;
int i,j,k;
printf(“Enter a string: “);
gets(st);
for(i=0;st[i]!=’\0′;i++);
for(j=0;st[j]!=’\0′;j++){
for(k=i-1;k>=j;k–){
printf(“%c”,st[j]);
}
printf(“\n”);
}
}

Mar

29

#include<stdio.h>
void main(){
char st[100];
int i,j;
int len=0;
printf(“Enter a string: “);
gets(st);
for(i=0;st[i]!=’\0′;i++){
len++;
}
for(i=len-1;i>=0;i–){
for(j=0;j<=i;j++){
printf(“%c\t”,st[j]);
}
printf(“\n”);
}
}

Mar

29

#include<stdio.h>
void main(){
char st[100];
int i,j;
printf(“Enter a string: “);
gets(st);

for(i=0;st[i]!=’\0′;i++){
for(j=0;j<=i;j++){
printf(“%c\t”,st[i]);
}
printf(“\n”);
}
}

Mar

29

#include<stdio.h>
void main(){
char st[100];
int i,j;
printf(“Enter a string: “);
gets(st);

for(i=0;st[i]!=’\0′;i++){
for(j=0;j<=i;j++){
printf(“%c\t”,st[j]);
}
printf(“\n”);
}
}

Mar

25

//get length of string in C

#include<stdio.h>
void main(){
char name[100];
int i;
printf(“Enter Your name: “);
//scanf(“%s”,name);
gets(name);
printf(“%d\n”,sizeof(name));
printf(“Your name is: %s\n”,name);
for(i=0;name[i]!=’\0′;i++);
printf(“Length of string: %d”,i);
}