పోస్ట్‌లు

జనవరి, 2024లోని పోస్ట్‌లను చూపుతోంది

100% working code JNTUK papers 29-1-24

S4-4a:  while & do..while (discussed in class already; posted 8-12-2023): https://padhaayee.blogspot.com/2023/12/output-in-5-different-ways-regular-for.html S4-4b:  sum of digits of a no. (discussed in class already; posted 1-11-2023): https://padhaayee.blogspot.com/2023/11/100-c-sum-of-digits-of-number-printing.html S4-5a: Prog with conditional operator & if-else  https://padhaayee.blogspot.com/2024/01/100-set-4-5a-if-else-conditional.html S4-5b: goto ఉపయోగిస్తూ ప్రోగ్రాం  (discussed in class already; posted 25-10-2023): https://padhaayee.blogspot.com/2023/10/100-demonstrating-goto.html S4-5b  S1-5a:  break ఉపయోగిస్తూ ప్రోగ్రాం  (discussed in class already; posted 25-10-2023): https://padhaayee.blogspot.com/2023/10/100-switch-program-with-without-break.html S4-5b:  return ఉపయోగిస్తూ ప్రోగ్రాం  (discussed in class already; posted 19-12-2023): https://padhaayee.blogspot.com/2023/12/100-finding-sum-of-elements-of-array.html S4-5b   S1-5a:  Prog with continue statement https://

100% SET4- 11a: Prog to find prime or not using functions

#include <stdio.h> void primeornot(int num)  {   int i = 2;   while(i <= num / 2)   {     if(num % i == 0) {  printf ("\n given number %d is not prime", num);       break; } i++;   }   if(i == (num / 2) + 1)   printf ("\n given number %d is prime", num); } void main() {   int numb;   printf ("\nenter a int >1 and <32768 that has to be checked for prime or not:");   scanf ("%d", &numb);   if(numb>1 && numb <32768)    primeornot (numb);   else     printf("\n entered number is out of prescribed limits:"); } //end of main  తెరమీద  enter a int >1 and <32768 that has to be checked for prime or not:24  given number 24 is not prime తెరమీద  మరోసారి  enter a int >1 and <32768 that has to be checked for prime or not:2  given number 2 is prime ఇంకోసారి  enter a int >1 and <32768 that has to be checked for prime or not:43221  entered number is out of prescribed limits:

100% JNTUK SET 4:9b arrays vs structure getting same output

#include <stdio.h> void main() {     int i, roll_no[2];     float mean[2];     /*roll_no & mean are 2 arrays in which data of 2 students is stored.     As we declare 2 arrays ..one for roll nos and other for mean values,     the relation among them is not apparent in arrays. the problem is     overcome by using structures*/         struct student     {       int rno;       float avg;     }s[2];  // s[0].rno and s[1].rno contains rollnumbers of 2 students whose averages are s[1].avg and s[1].avg         //   data entry into arrays begin     printf("\n Enter the two roll nos:");     scanf("%d%d",&roll_no[0],&roll_no[1]);     printf("\n Enter the mean values of the two candidates in exam:");     scanf("%f%f",&mean[0],&mean[1]);         //   data entry into struct variable begins     for(i=0;i<2;i++)     {         printf("\n Enter the rno & avg:");         scanf("%d%f",&s[i].rno,&s[i].avg);

100% Prog JNTUK (29-1-24) SET 1-9a: Using pointers, print elements if array in reverse order

#include <stdio.h> void main () {   int i,arr[5],*ptr;   ptr=&arr[0];   for(i=0;i<5;i++)   {       printf ("\nenter element a[%d]:",i);       scanf("%d",ptr+i);   }   printf("\n printing the numbers in reverse order begins:");   while(i)   {       printf(" %2d",*(ptr+--i)); //ఈ లాజిక్ అవగతం చేసుకొనుట  కీలకం    }  } తెరమీద enter element a[0]:1 enter element a[1]:3 enter element a[2]:5 enter element a[3]:7 enter element a[4]:9  printing the numbers in reverse order begins:  9  7  5  3  1 ------------------------------------- #include <stdio.h> void main () {   int i,arr[5],*ptr;   ptr=&arr[0];   for(i=0;i<5;i++)   {       printf ("\nenter element a[%d]:",i);       scanf("%d",ptr+i);   }     printf("\n printing the numbers in reverse order begins:");   while(i)   {       printf(" %2d",*(ptr+--i));   }     printf("\n printing the numbers in actual order begins:");   do   {  

100% SET-4 5b: continue statement illustration.

#include<stdio.h> void main() {      int i=9;     while(i)     {              i--;            if(i==7)      {          continue;      }      printf("%2d",i);     } } తెరమీద  8 6 5 4 3 2 1 0 గమనిక  7 అనే  అంకె ప్రింట్ కాలేదు..bcoz of continue statement.  

100% SET 4: 5(a) if-else & conditional operator

#include <stdio.h> int main() {     int a=4,b=5;     printf("\n a=%d, b=%d",a,b);     if (a<b)      printf("\n a is less than b");     else      printf("\n a is not less than b");     printf("\n\n till now we used if-else condition; Now lets use conditional operator below\n\n");           a<b? printf("a is smaller than b"): printf("a is not smaller than b"); } తెరమీద a=4, b=5  a is less than b  till now we used if-else condition; Now lets use conditional operator below a is smaller than b

100% SET 4: 6(a) Prog to add and subtract two 2D arrays.

#include <stdio.h> void main() {     int arr1[2][3]={{1,-1,2},{0,1,2}};     int arr2[][3]={0,1,-3,4, 7,1};     int i,j,sum_arr[2][3],diff_arr[2][3];     for(i=0;i<2;i++)     {         for(j=0;j<3;j++)         {             sum_arr[i][j]=arr1[i][j]+arr2[i][j]; //addition of arrays             diff_arr[i][j]=arr1[i][j]-arr2[i][j]; //substraction of arrays         }     }     /* Printing the two given matrices begins*/     printf("\n arr1= \n\n");     for(i=0;i<2;i++)     {         for(j=0;j<3;j++)         {             printf(" %2d",arr1[i][j]);         }         printf("\n");     }     printf("\n arr2= \n\n");     for(i=0;i<2;i++)     {         for(j=0;j<3;j++)         {             printf(" %2d",arr2[i][j]);         }         printf("\n");     }     /*sum of the arrays follows:*/     printf("\n the sum is:\n\n");     for(i=0;i<2;i++)     {         for(j=0;j<3;j++)         {             p

100% SET 1 & 4: 6(b) string handling functions

#include <stdio.h> #include<string.h> void main() {     char str1[ ]="satyamu", str2[ ]="cheppu";     int length;    printf("\n Before copying str1=%s, str2=%s",str1,str2);    strcpy(str1,str2);     printf("\n After copying str1=%s, str2=%s",str1,str2);         printf("\n concatenating the two string satyamu_ and paluku is %s", strcat(str1,str2));         printf("\n if strings are same then strcmp gives %d",strcmp("Chennai","Chennai"));         printf("\n if strings are not same then strcmp gave %d",strcmp("Chennai","ChinToo"));     printf("\n if strings are not same then strcmp gave %d",strcmp("ChinToo","Chennai"));         length=strlen(str1);     printf("\n length of string cheppucheppu= %d",length);     } తెరమీద Before copying str1=satyamu, str2=cheppu  After copying str1=cheppu, str2=cheppu  concatenating the two string s

100% prog /* SET 1: m to the power of n */

/* SET 1: m to the power of n */ #include <stdio.h> #include<math.h> #include<conio.h> void main() {     int m,n, n_copy;     long int m_pow_n=1;       //clrscr();     printf("Enter the base m:");     scanf("%d",&m);     printf("Enter the exponent n (a positive integer):");     scanf("%d",&n);     n_copy=n;     while(n>0)     {         m_pow_n=m_pow_n*m;         n--;     }     printf("\n %d to the power of %d is %ld ",m,n_copy,m_pow_n); } తెరమీద Enter the base m:2 Enter the exponent n (a positive integer):5  2 to the power of 5 is 32 

100% prog /* SET 1: area of equilateral triangle */

#include <stdio.h> #include<math.h> #include<conio.h> void main( ) {     float side, area; // side can be replaced by a     clrscr( );     printf("Enter side of the equilateral triangle:");     scanf("%f",&side);     area=(sqrt(3)/4)*side*side;     printf("\n area of the equilateral triangle with side= %f units is %f sq. units",side,area);     getch( ); } తెరమీద Enter side of the equilateral traingle:1 area of the equilateral triangle with side= 1.000000 units is 0.433013 sq. units  

Survey form

Survey form https://forms.gle/Dq7RisPNA1X2GjrK8

JNTUK paper Q&A 1b: 27-1-24

//program to evaluate 5+10/5*6%3 #include<stdio.h> void main() {  printf("%d",5+10/5*6%3); } తెరమీద  5 కారణం = 5+10/5*6%3 --> 5+2*6%3   -->  5+12%3   -->  5+0   -->  5 

JNTUK paper Q&A 3a : 27-1-24

/* program to use if else conditionals and grade the students     marks           grade     >90               A     70-90             B     50-69             C     40-49             D     <40               F     */  #include<stdio.h>  #include<conio.h>  void main()  {   int marks;   char grade;   clrscr();   printf("\n enter marks:");   scanf("%d",&marks);   if(marks>90)   {     grade='A';   }   else if(marks>=70 && marks<=90)   {    grade='B';   }   else if(marks>=50 && marks<70)   {    grade='C';   }   else if(marks>=40 && marks<50)   {    grade='D';   }   else   {    grade='F';   }   printf("\n marks=%d, grade=%c",marks,grade);   getch();  } //end of main తెరమీద  enter marks: 82 marks=82, grade=B  తెరమీద మరోసారి  enter marks: 54 marks=54, grade=C

LAB week 9 (i): sum of elements of array (dynamic allocation of memory using malloc( ))

/*code is slightly modified by bhayyA after taking it from S.chand text book  'Introduction to Programming' authored by KV SAmbasivarao & DAvuluri sunita*/ #include<stdio.h> #include<stdlib.h> int main() { int i,n,*arrptr,total=0; printf("\n enter no of elements in the array:"); scanf("%d",&n); //dynamically allotinng memory for the array begins arrptr=(int *)malloc(n*sizeof(int)); printf("\n memory alloted =%d",sizeof(arrptr)); if(arrptr==NULL) {   printf("\n memory allocation failed");   exit(0); //the no. is an indication of the type of error      }      else      {       printf("\n enter the elements of the array:\n");       for(i=0;i<n;i++)       {       printf("\n enter the element arrptr[%d]:",i);       scanf("%d",&arrptr[i]);       total=total+arrptr[i];       }          }      free(arrptr); //frees the dynamically allocated memory      printf("\n sum of

LAB week 7 (iv): 2's complement

/*code is typed by bhayyA by taking it from S.chand text book  'Introduction to Programming' authored by KV SAmbasivarao & DAvuluri sunita. Output is observed to be satisfactory for 3 given inputs*/   #include<stdio.h> void main() {  int b2comp[9],n,i,j;  printf("\n enter no of bits:"); scanf("%d",&n); printf("\n enter the binary no. without leading zeros:"); for(i=0;i<n;++i) { scanf("%1d",&b2comp[i]); } //find 2's complement for(i=n-1;i>=0;--i) { if(b2comp[i]==1) break; } if(i==-1) { printf("\n 2's complement:"); for(i=0;i<n;++i) { printf("%d",b2comp[i]); } } else {   for(j=i-1;j>=0;--j)   {   b2comp[j]=1-b2comp[j];   }   printf("\n 2's complement:");   for(i=0;i<n;++i) { printf("%d",b2comp[i]); } } } తెరమీద  enter no of bits: 5 enter the binary no. without leading zeros: 10011 2's complement: 01101 మరోసారి enter no of bits: 5 ente

100% C prog to write only పెద్ద అక్షరాలు (uppercase letters) into file and subsequently print the content

/*dedicated to student who asked genuine doubt and made me think*/ /*this program will create a file where only uppercase  (A-Z) letters get written into the file. the content is later read and   displayed on to the screen */ #include<stdio.h> #include<conio.h> void main() { char ch; FILE *fptr; fptr=fopen("nayA1601.txt","w"); printf("\n start entering the data: \n "); ch=getchar(); while(ch!='z') { if((ch>=65 &&ch<=92)) //only uppercase letters get written into file   fputc(ch,fptr);// only this line is inside the if condition ch=getchar(); } fclose(fptr); printf("\n writing is over. lets read now:\n"); fptr=fopen("nayA1601.txt","r"); printf("\n\n start reading the data from the file: \n "); while(!feof(fptr)) { ch=fgetc(fptr); putchar(ch); } fclose(fptr); getch(); }

100% C prog to create a file and (i) Print back full content and (ii) then to print only Capital letters from file

/*ధన్యవాదములు to student who asked genuine doubt and made the teacher think*/ #include<stdio.h> #include<conio.h> void main() { char ch; FILE *fptr; fptr=fopen("nayA_1601.txt","w"); printf("\n start entering the data: \n "); ch=getchar(); while(ch!='z') { fputc(ch,fptr); ch=getchar(); } fclose(fptr); printf("\n writing is over. lets read now:\n"); fptr=fopen("nayA_1601.txt","r"); printf("\n\n start reading the data from the file: \n "); while(!feof(fptr)) { ch=fgetc(fptr); putchar(ch); } fclose(fptr); printf("\n\n  lets now read only those which are in capital letters:\n"); fptr=fopen("nayA_1601.txt","r"); printf("\n start reading the data from the file: \n "); while(!feof(fptr)) { ch=fgetc(fptr); if((ch>=65 &&ch<=92)) putchar(ch); } fclose(fptr); getch(); }

100% C prog to write content into a file and then read it back onto the console

#include<stdio.h> #include<conio.h> void main() { char ch; FILE *fptr; // clrscr(); fptr=fopen("kotta1601.txt","w"); printf("\n start entering the data: \n "); ch=getchar(); while(ch!='z') { fputc(ch,fptr); ch=getchar(); } fclose(fptr); //writing file is completed now lets start reading from the just created file fptr=fopen("kotta1601.txt","r"); printf("\n start reading the data from the file: \n "); while(!feof(fptr)) { ch=fgetc(fptr); putchar(ch); } fclose(fptr); getch(); }

100% C prog to append content to existing file and then read the whole content

#include<stdio.h> #include<conio.h> void main() { char ch; FILE *fptr; fptr=fopen("kotta1601.txt","a"); printf("\n start entering the data: \n "); ch=getchar(); while(ch!='z') { fputc(ch,fptr); ch=getchar(); } fclose(fptr); printf("\n appending completed"); printf("\n start reading the data from the file: \n "); fptr=fopen("kotta1601.txt","r"); while(!feof(fptr)) { ch=fgetc(fptr); putchar(ch); } fclose(fptr); getch(); }

100% C prog to read data from .txt file

/*in the just previous program, reading got stopped when 'u' is encountered but here the file will be read till the end of the file */ #include<stdio.h> #include<conio.h> void main() { char ch; FILE *fptr; // clrscr(); fptr=fopen("creating.txt","r"); printf("\n start reading the data from the file: \n "); while(!feof(fptr)) { ch=fgetc(fptr); putchar(ch); } fclose(fptr); getch(); }

100% C prog to read data from .txt file

#include<stdio.h> #include<conio.h> void main() { char ch; FILE *fptr; // clrscr(); fptr=fopen("creating.txt","r"); printf("\n start reading the data from the file: \n "); ch=fgetc(fptr); putchar(ch); while(ch!='u') { ch=fgetc(fptr); putchar(ch); } fclose(fptr); getch(); }

100% C prog to create a .txt file

#include<stdio.h> #include<conio.h> void main() { char ch; FILE *fptr; //clrscr(); fptr=fopen("creating.txt","w"); printf("\n start entering the data: \n "); ch=getchar(); while(ch!='z') { fputc(ch,fptr); ch=getchar(); } fclose(fptr); getch(); }

useful C ppt links

100%  https://www.cse.iitd.ac.in/~aseth/col100-2021/col100.html   COL100 lecture notes: 20-21 Sem 2 (iitd.ac.in)    cse.iitkgp.ac.in/~goutam/pds/pdsLect/index.html    https://www.cs.clemson.edu/course/cpsc111/slides3/

సుల్తాన్ గారి C material typed pdf link(73+2 pages)

https://drive.google.com/file/d/1klYfeIXFJR_kOdNzG2Ky2Ud8PKQiOQqO/view?usp=sharing

100% pointer & structure

#include<stdio.h> void callstruct(int *ptrstruct) {   printf("\n just entered the function callstruct");    printf("\n\n roll =%d",*ptrstruct++);    printf("\n name=%c",*ptrstruct); } void main() {  struct  student  {    int r_no;    char name; // assuming name is single letter like a or b or Z  }s;  printf("\n enter the roll no,  name:");  scanf("%d %c",&s.r_no,& s.name );  printf("\n roll no= %d,    name=%c",s.r_no, s.name );  printf("\n\n %u  %u   %u",&s, &s.r_no,& s.name );  printf("\n we r about to enter the function callstruct\n");  callstruct(&s);  } ఆన్లైన్ లో చేస్తే తెరమీద  enter the roll no,  name:2 a roll no= 2,    name=a  2006898232  2006898232   2006898236  we r about to enter the function callstruct  just entered the function callstruct  roll =2  name=a

Multiple programs... ఇందులో ఉన్నాయి

save the  following as KOSHISH.C #include<stdio.h> #include<conio.h> void main() {  printf("\n satyamu paluku");  printf("\n 12  nijam cheppu");  getch(); } ---------------------------------------------------------------------------------------- Save the following as FNAYA4.C  /*program written by vikram bhayya after he understood the content given in LET US C book*/ #include<stdio.h> #include<stdlib.h> #include<conio.h> void main() {  FILE *fptrs,*fptrd;  char ch;  fptrs=fopen("KOSHISH.C","r");  if(fptrs==NULL)  {   puts("\n cannot open source file");   exit(1);  }  fptrd=fopen("KOSHISH2.C","w");  if(fptrd==NULL)  {   puts("\n cannot open destination file");   fclose(fptrs);   exit(2);  }  while(1)  {   ch=fgetc(fptrs);   if(ch==EOF)    break;   else    fputc(ch,fptrd);  }  fclose(fptrs);  fclose(fptrd);  getch(); } -------------------------------------------------------------