Upload
vicksgeorge
View
223
Download
1
Embed Size (px)
DESCRIPTION
C language important codes
Citation preview
//My First C Program#include int main(){ printf("Talk To a Teacher\n"); return 0;}
//My First C++ program#include using namespace std;int main(){ cout
} }
#include int a=5;int b=2;void add(){int sum;sum = a + b;printf("Sum of a and b is %d\n",sum);}int main(){add();return 0;}
#include using namespace std;int a=5;int b=2;void add(){int sum;sum = a + b;cout b; sum = a + b; cout
#include int main() {int x, y;printf("Enter a number between 0 to 39: ");scanf("%d",&y);
if(y/10==0){printf("you have entered the number in the range of 0 to 9\n");}else if(y/10==1){printf("you have entered the number in the range of 10 to 19\n");}else if (y/10==2){printf("you have entered number in the range of 20-29\n");}else if (y/10==3){printf("you have entered number in the range of 30-39\n");}else {printf("The number not in range \n");}return 0;}
#include using namespace std;int main() {int x, y;couty;
if(y/10==0){cout
case 2:printf("you have entered number in the range of 20-29\n");break;case 3:printf("you have entered number in the range of 30-39\n");break;default:printf("number not in range \n");} return 0;}
break;case 2:cout
%.2f\n",a,b,c); c = (float)a / b; printf("Real Division of %d and %d is %.2f\n",a,b,c); return 0;}
c = a / b; cout
} return 0;}
#includeint main(){int x=0;int y=0;do{y=y+x;printf("%d\n",y);x++;}while(x
j = strcmp(str2,"Cream"); printf("%d, %d\n",i,j);
return 0;}
printf("target string = %s\n",target);return 0;}
//String Length
#include#includeint main(){ char arr[] = "Ashwini"; int len1 = strlen(arr); printf("string = %s length = %d\n",arr, len1);return 0;}
#include struct student { int eng; int maths; int science;};int main() { int total; struct student stud; stud.eng = 75; stud.maths = 70; stud.science = 65; total = stud.eng + stud.maths + stud.science; printf("Total is %d\n",total); return 0;}
#include using namespace std;struct student { int eng; int maths; int science;};int main() { int total; struct student stud; stud.eng = 75; stud.maths = 70; stud.science = 65; total = stud.eng + stud.maths + stud.science; cout
printf("pointer's value: %p\n", ptr);
printf("value pointed to: %ld\n", *ptr); }
sizeof(ptr)
{ FILE *fp; fp = fopen("/home/ttt/Desktop/sample.txt","w"); fprintf(fp,"Welcome to the spoken-tutorial
\n"); fprintf(fp,"This is an test example\n"); fclose(fp); return 0;}
{ FILE *fp; char c; fp = fopen("/home/ttt/Desktop/sample.txt","r"); if (fp == NULL) printf("File doesn't exist\n"); else { while (c != EOF) { c = getc(fp); putchar(c); } fclose(fp); }return 0;}