SlideShare a Scribd company logo
1 of 3
C, C, C PROGRAMMING DO NOT ANSWER IF YOU CANT FIX MY CODE OR ANY OF
THE EXAMPLES BELOW WILL NOT WORK PROPERLY! Write a program to implement
the Caesar cipher. You program should read an integer N from standard in followed by a line of
plain text, and should print the encoded line. The provided N can be any integer between 0 and
26, otherwise your program should print an error message and terminate as shown in the
examples below. Any numbers or punctuation in the plaintext should be ignored. Note that the
letters should be shifted circularly, i.e. if N = 3 letter y would become b.
This is my code:
#include <stdio.h>
int main()
{
char array[100], cipher[100];
int c=0, x=0, y=0;
int z;
do {
printf("Enter key: ");
scanf("%d", &z);
getchar();
if(z < 1 || z > 26) {
z = 0;
printf("Invalid key! ");
return(0);
}
}while(!z);
printf("Enter line: ");
while((c=getchar()) != ' ')
{
array[x++]=(char)c;
cipher[y++]=(char)(c+z);
}
array[x]=0;
cipher[y]=0;
printf("%s ",cipher);
return 0;
}
IT SHOULD RUN ALL THE EXAMPLES BELOW CORRECTLY AND EXACTLY.
PLEASE ANSWER IF ONLY AND ONLY YOU CAN FIX MY CODE TO IMPLEMENT
EXACTLY EXACTLY THE SAME AS THE BELOW EXAMPLES!
Example 1
Example 2
Example 3
Solution
#include <stdio.h>
#include<ctype.h>
int main()
{
char array[100], cipher[100];
int c=0, x=0, y=0;
int z;
do {
printf("Enter key: ");
scanf("%d", &z);
getchar();
if(z < 1 || z > 26) {
z = 0;
printf("Invalid key! ");
return(0);
}
}while(!z);
printf("Enter line: ");
while((c=getchar()) != ' ')
{
array[x++]=(char)c;
if(isalpha(c)){
if(c+z > 'z'){
cipher[y++]=(char)((c+z-'a')%26 + 'a');}
else if (c+z > 'Z' && c+z < 'a')
cipher[y++]=(char)((c+z-'A')%26 + 'A');
else
cipher[y++]=(char)(c+z);
}
else
cipher[y++]=(char)c;
}
array[x]=0;
cipher[y]=0;
printf("%s ",cipher);
return 0;
}

More Related Content

Similar to C- C- C PROGRAMMING DO NOT ANSWER IF YOU CANT FIX MY CODE OR ANY OF TH.docx

Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
Vishal Singh
 

Similar to C- C- C PROGRAMMING DO NOT ANSWER IF YOU CANT FIX MY CODE OR ANY OF TH.docx (20)

Najmul
Najmul  Najmul
Najmul
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
C programming codes for the class assignment
C programming codes for the class assignmentC programming codes for the class assignment
C programming codes for the class assignment
 
C Language Programming Introduction Lecture
C Language Programming Introduction LectureC Language Programming Introduction Lecture
C Language Programming Introduction Lecture
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
Basic C Programming Lab Practice
Basic C Programming Lab PracticeBasic C Programming Lab Practice
Basic C Programming Lab Practice
 
Numerical analysis
Numerical analysisNumerical analysis
Numerical analysis
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Data types
Data typesData types
Data types
 
C Programming Lab.pdf
C Programming Lab.pdfC Programming Lab.pdf
C Programming Lab.pdf
 
C-programs
C-programsC-programs
C-programs
 
Data types
Data typesData types
Data types
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
Progr3
Progr3Progr3
Progr3
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
 

More from gilliandunce53776

c# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docxc# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docx
gilliandunce53776
 
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docxBusiness Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
gilliandunce53776
 
Brief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docxBrief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docx
gilliandunce53776
 
Briefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docxBriefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docx
gilliandunce53776
 
Brief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docxBrief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docx
gilliandunce53776
 
Both Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docxBoth Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docx
gilliandunce53776
 
Betty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docxBetty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docx
gilliandunce53776
 
Beyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docxBeyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docx
gilliandunce53776
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docx
gilliandunce53776
 
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docxcaiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
gilliandunce53776
 
C++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docxC++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docx
gilliandunce53776
 
C++ help! Write a function merge that merges two lists into one- alter.docx
C++ help! Write a function merge that merges two lists into one- alter.docxC++ help! Write a function merge that merges two lists into one- alter.docx
C++ help! Write a function merge that merges two lists into one- alter.docx
gilliandunce53776
 

More from gilliandunce53776 (15)

Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docxBullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
Bullen Inc- acquired 100- of the voting common stock of Vicker Inc- on.docx
 
c# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docxc# Write an application that displays the following patterns separatel.docx
c# Write an application that displays the following patterns separatel.docx
 
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docxBusiness Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
Business Law 1- Firm X and Firm Y are in dispute over a contract- They.docx
 
Brief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docxBrief explain how a DBMS handles concurrent execution of transactionsS.docx
Brief explain how a DBMS handles concurrent execution of transactionsS.docx
 
Briefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docxBriefly explain the three types of IPv6 addresses-SolutionThree types.docx
Briefly explain the three types of IPv6 addresses-SolutionThree types.docx
 
Brief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docxBrief timeline of the development of the theory and or technology and.docx
Brief timeline of the development of the theory and or technology and.docx
 
Both Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docxBoth Ford and Phillips Electric have faced major changes globally in t.docx
Both Ford and Phillips Electric have faced major changes globally in t.docx
 
Brand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docxBrand Foods Wholesale Corporation operates more than 590 membership wa.docx
Brand Foods Wholesale Corporation operates more than 590 membership wa.docx
 
Betty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docxBetty retires from the BS Partnership when the basis of her one-third.docx
Betty retires from the BS Partnership when the basis of her one-third.docx
 
Beyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docxBeyond aesthetics- what functional differences are there for running G.docx
Beyond aesthetics- what functional differences are there for running G.docx
 
Below is accounting information for Cascade Company for 2013- What we.docx
Below is accounting information for Cascade Company for 2013-  What we.docxBelow is accounting information for Cascade Company for 2013-  What we.docx
Below is accounting information for Cascade Company for 2013- What we.docx
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docx
 
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docxcaiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
caiorie Potenhally useful information- 4-1843I K -C + 273-15 760 mmHg-.docx
 
C++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docxC++ inheritance True or false- If A is the superclass and B is the sub.docx
C++ inheritance True or false- If A is the superclass and B is the sub.docx
 
C++ help! Write a function merge that merges two lists into one- alter.docx
C++ help! Write a function merge that merges two lists into one- alter.docxC++ help! Write a function merge that merges two lists into one- alter.docx
C++ help! Write a function merge that merges two lists into one- alter.docx
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 

C- C- C PROGRAMMING DO NOT ANSWER IF YOU CANT FIX MY CODE OR ANY OF TH.docx

  • 1. C, C, C PROGRAMMING DO NOT ANSWER IF YOU CANT FIX MY CODE OR ANY OF THE EXAMPLES BELOW WILL NOT WORK PROPERLY! Write a program to implement the Caesar cipher. You program should read an integer N from standard in followed by a line of plain text, and should print the encoded line. The provided N can be any integer between 0 and 26, otherwise your program should print an error message and terminate as shown in the examples below. Any numbers or punctuation in the plaintext should be ignored. Note that the letters should be shifted circularly, i.e. if N = 3 letter y would become b. This is my code: #include <stdio.h> int main() { char array[100], cipher[100]; int c=0, x=0, y=0; int z; do { printf("Enter key: "); scanf("%d", &z); getchar(); if(z < 1 || z > 26) { z = 0; printf("Invalid key! "); return(0); } }while(!z); printf("Enter line: "); while((c=getchar()) != ' ') { array[x++]=(char)c; cipher[y++]=(char)(c+z); } array[x]=0; cipher[y]=0; printf("%s ",cipher);
  • 2. return 0; } IT SHOULD RUN ALL THE EXAMPLES BELOW CORRECTLY AND EXACTLY. PLEASE ANSWER IF ONLY AND ONLY YOU CAN FIX MY CODE TO IMPLEMENT EXACTLY EXACTLY THE SAME AS THE BELOW EXAMPLES! Example 1 Example 2 Example 3 Solution #include <stdio.h> #include<ctype.h> int main() { char array[100], cipher[100]; int c=0, x=0, y=0; int z; do { printf("Enter key: "); scanf("%d", &z); getchar(); if(z < 1 || z > 26) { z = 0; printf("Invalid key! "); return(0); } }while(!z);
  • 3. printf("Enter line: "); while((c=getchar()) != ' ') { array[x++]=(char)c; if(isalpha(c)){ if(c+z > 'z'){ cipher[y++]=(char)((c+z-'a')%26 + 'a');} else if (c+z > 'Z' && c+z < 'a') cipher[y++]=(char)((c+z-'A')%26 + 'A'); else cipher[y++]=(char)(c+z); } else cipher[y++]=(char)c; } array[x]=0; cipher[y]=0; printf("%s ",cipher); return 0; }